-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
221 lines (171 loc) · 6.56 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/*
[ ] - Make "basementor-vue" action to global register components
[ ] - Make wp_editor component for vue
[ ] - Create "clone" action in posts actions list
[ ] - Make "Post excel mode" work in all post types
[ ] - Make Woocommerce filters customizable
[ ] - Put title inside thumbnail for loop elements height bugfix
*/
/* Se for tema filho, para por aqui para não redeclarar funções */
if (defined('BASEMENTOR_PARENT')) return;
define('BASEMENTOR_ELEMENTOR', did_action('elementor/loaded'));
define('BASEMENTOR_WOOCOMMERCE', class_exists('WooCommerce'));
define('BASEMENTOR_PARENT', get_template_directory());
define('BASEMENTOR_CHILD', get_stylesheet_directory());
/* Print data: dd($data1, $data2, $data3); */
if (! function_exists('dd')) { function dd() { foreach(func_get_args() as $data) { echo '<pre>'. print_r($data, true) .'</pre>'; }}}
if (! function_exists('de')) { function de() { foreach(func_get_args() as $data) { echo '<pre>'. var_export($data, true) .'</pre>'; }}}
if (isset($_GET['test'])) {
dd(BASEMENTOR_PARENT, BASEMENTOR_CHILD); die;
}
spl_autoload_register(function($class) {
if ($include = realpath(str_replace('\\', '/', __DIR__ . "/{$class}.php"))) {
include $include;
}
});
foreach([BASEMENTOR_PARENT, BASEMENTOR_CHILD] as $folder) {
foreach(glob($folder .'/autoload/*.php') as $include) {
include $include;
}
}
include __DIR__ . '/woocommerce-checkout-fields/woocommerce-checkout-fields.php';
if (isset($_GET['basementor-theme-child']) AND is_user_logged_in()) {
add_action('init', function() {
$folder = wp_get_current_user();
$folder = $folder->data->user_login;
$theme_folder = get_theme_root() ."/{$folder}";
$current_folder = pathinfo(__DIR__, PATHINFO_FILENAME);
@mkdir($theme_folder, 0755, true);
@mkdir($theme_folder.'/autoload', 0755, true);
file_put_contents("{$theme_folder}/style.css", implode("\n", [
'/*',
"Theme Name: {$folder} theme",
"Description: {$folder} Theme",
'Author: Jeferson Siqueira',
'Author URI: https://jsiqueira.com',
"Template: {$current_folder}",
'Version: 1.0',
'*/',
]));
file_put_contents("{$theme_folder}/functions.php", implode("\n", [
'<?php',
'',
]));
wp_redirect($_SERVER['HTTP_REFERER']); die;
});
}
/* Remove WP Emoji */
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
/* Disable Woocommerce Stylesheet */
// add_filter('woocommerce_enqueue_styles', '__return_false' );
// add_filter('woocommerce_enqueue_styles', function( $enqueue_styles ) {
// unset( $enqueue_styles['woocommerce-general'] );
// unset( $enqueue_styles['woocommerce-layout'] );
// unset( $enqueue_styles['woocommerce-smallscreen'] );
// return $enqueue_styles;
// });
add_action('after_setup_theme', function() {
add_theme_support('post-thumbnails');
add_theme_support('woocommerce');
add_theme_support('custom-logo', [
'width' => 300,
'height' => 100,
'flex-height' => true,
'flex-width' => true,
'header-text' => ['site-title', 'site-description'],
]);
register_nav_menus([
'primary' => 'Principal',
'socials' => 'Redes Sociais',
]);
});
/* Enqueue scripts and styles in admin and website */
foreach(['wp_enqueue_scripts', 'admin_enqueue_scripts'] as $action) {
add_action($action, function() {
wp_enqueue_script('vue', '//cdn.jsdelivr.net/npm/vue');
wp_enqueue_script('popper', '//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js');
wp_enqueue_script('bootstrap', '//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js');
wp_enqueue_style('bootstrap', '//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css');
wp_enqueue_style('font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css');
wp_enqueue_style('animate-css', '//cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css');
wp_enqueue_script('head-load', '//cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.load.min.js');
});
}
/* foreach(['wp_head', 'admin_head'] as $action):
add_action($action, function() {
$settings = \Basementor\Basementor::settings();
?><style>
.wp-admin .card {padding:0px; max-width:none;}
[v-cloak] {display:none;}
.wp-filter > * {line-height:3px; margin:0px !important;}
.search-plugins {padding:5px 0px 0px 0px;}
.search-plugins > * {vertical-align:top;}
</style>
<?php echo \Basementor\Basementor::styles(); ?>
<?php });
endforeach; */
// add_action('wp_enqueue_scripts', function() {
// wp_enqueue_style('aaa', get_template_directory_uri().'/style.css');
// wp_enqueue_style('bbb', get_stylesheet_directory_uri().'/style.css');
// });
/* Redirect if current post edit is Elementor */
add_action('admin_head-post.php', function() {
global $post;
if (\Elementor\Plugin::$instance->db->is_built_with_elementor($post->ID)) {
wp_redirect(admin_url("/post.php?post={$post->ID}&action=elementor"));
}
});
/* Save any Woocommerce user post field */
add_action('woocommerce_customer_save_address', function($user_id, $load_address) {
$ignore = ['save_address', 'woocommerce-edit-address-nonce', '_wp_http_referer', 'action'];
foreach($_POST as $key=>$value) {
if (in_array($key, $ignore)) continue;
update_user_meta(get_current_user_id(), $key, $value);
}
}, 10, 2);
add_action('admin_bar_menu', function($admin_bar) {
$items = [
[
'id' => 'basementor-elementor',
'title' => 'Elementor',
'href' => 'javascript:;',
'children' => [
[
'id' => 'basementor-elementor-page',
'title' => 'Editar página atual',
'href' => admin_url('admin.php?page=basementor-settings&tab=update'),
],
[
'id' => 'basementor-elementor-header',
'title' => 'Editar Cabeçalho',
'href' => admin_url('admin.php?page=basementor-settings&tab=update'),
],
[
'id' => 'basementor-elementor-footer',
'title' => 'Rodapé',
'href' => admin_url('admin.php?page=basementor-settings&tab=update'),
],
],
]
];
if (BASEMENTOR_PARENT==BASEMENTOR_CHILD) {
$items[0]['children'][] = [
'id' => 'basementor-elementor-child',
'title' => 'Criar e ativar tema filho',
'href' => admin_url('admin.php?basementor-theme-child'),
];
}
foreach($items as $item) {
$admin_bar->add_menu($item);
if (isset($item['children']) AND is_array($item['children'])) {
foreach($item['children'] as $iitem) {
$iitem['parent'] = $item['id'];
$admin_bar->add_menu($iitem);
}
}
}
}, 100);