forked from vafour/vafpress-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
344 lines (305 loc) · 7.19 KB
/
bootstrap.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
if( defined('VP_VERSION') )
return;
//////////////////////////
// Include Constants //
//////////////////////////
require_once 'constant.php';
//////////////////////////
// Include Autoloader //
//////////////////////////
require_once 'autoload.php';
//////////////////////////
// Load Languages //
//////////////////////////
load_theme_textdomain('vp_textdomain', VP_DIR . '/lang');
//////////////////////////
// Setup FileSystem //
//////////////////////////
$vpfs = VP_FileSystem::instance();
$vpfs->add_directories('views' , VP_VIEWS_DIR);
$vpfs->add_directories('config' , VP_CONFIG_DIR);
$vpfs->add_directories('data' , VP_DATA_DIR);
$vpfs->add_directories('includes', VP_INCLUDE_DIR);
//////////////////////////
// Include Data Source //
//////////////////////////
foreach (glob(VP_DATA_DIR . "/*.php") as $datasource)
{
require_once($datasource);
}
//////////////////////////
// TGMPA Unsetting //
//////////////////////////
add_action('after_setup_theme', 'vp_tgm_ac_check');
if( !function_exists('vp_tgm_ac_check') )
{
function vp_tgm_ac_check()
{
add_action('tgmpa_register', 'vp_tgm_ac_vafpress_check');
}
}
if( !function_exists('vp_tgm_ac_vafpress_check') )
{
function vp_tgm_ac_vafpress_check()
{
if( defined('VP_VERSION') and class_exists('TGM_Plugin_Activation') )
{
foreach (TGM_Plugin_Activation::$instance->plugins as $key => &$plugin)
{
if( $plugin['name'] === 'Vafpress Framework Plugin' )
{
unset(TGM_Plugin_Activation::$instance->plugins[$key]);
}
}
}
}
}
//////////////////////////
// Ajax Definition //
//////////////////////////
add_action('wp_ajax_vp_ajax_wrapper', 'vp_ajax_wrapper');
if( !function_exists('vp_ajax_wrapper') )
{
function vp_ajax_wrapper()
{
$function = $_POST['func'];
$params = $_POST['params'];
if( VP_Security::instance()->is_function_whitelisted($function) )
{
if(!is_array($params))
$params = array($params);
try {
$result['data'] = call_user_func_array($function, $params);
$result['status'] = true;
$result['message'] = __("Successful", 'vp_textdomain');
} catch (Exception $e) {
$result['data'] = '';
$result['status'] = false;
$result['message'] = $e->getMessage();
}
}
else
{
$result['data'] = '';
$result['status'] = false;
$result['message'] = __("Unauthorized function", 'vp_textdomain');
}
if (ob_get_length()) ob_clean();
header('Content-type: application/json');
echo json_encode($result);
die();
}
}
/////////////////////////////////
// Pool and Dependencies Init //
/////////////////////////////////
add_action( 'init' , 'vp_metabox_enqueue' );
add_action( 'current_screen' , 'vp_sg_enqueue' );
add_action( 'admin_enqueue_scripts', 'vp_enqueue_scripts' );
add_action( 'current_screen' , 'vp_sg_init_buttons' );
add_filter( 'clean_url' , 'vp_ace_script_attributes', 10, 1 );
if( !function_exists('vp_ace_script_attributes') )
{
function vp_ace_script_attributes( $url )
{
if ( FALSE === strpos( $url, 'ace.js' ) )
return $url;
return "$url' charset='utf8";
}
}
if( !function_exists('vp_metabox_enqueue') )
{
function vp_metabox_enqueue()
{
if( VP_WP_Admin::is_post_or_page() and VP_Metabox::pool_can_output() )
{
$loader = VP_WP_Loader::instance();
$loader->add_main_js( 'vp-metabox' );
$loader->add_main_css( 'vp-metabox' );
}
}
}
if( !function_exists('vp_sg_enqueue') )
{
function vp_sg_enqueue()
{
if( VP_ShortcodeGenerator::pool_can_output() )
{
// enqueue dummy js
$localize = VP_ShortcodeGenerator::build_localize();
wp_register_script( 'vp-sg-dummy', VP_PUBLIC_URL . '/js/dummy.js', array(), '', false );
wp_localize_script( 'vp-sg-dummy', 'vp_sg', $localize );
wp_enqueue_script( 'vp-sg-dummy' );
$loader = VP_WP_Loader::instance();
$loader->add_main_js( 'vp-shortcode' );
$loader->add_main_css( 'vp-shortcode' );
}
}
}
add_action('admin_footer', 'vp_post_dummy_editor');
if( !function_exists('vp_post_dummy_editor') )
{
function vp_post_dummy_editor()
{
/**
* If we're in post edit page, and the post type doesn't support `editor`
* we need to echo out a dummy editor to load all necessary js and css
* to be used in our own called wp editor.
*/
$loader = VP_WP_Loader::instance();
$types = $loader->get_types();
$dummy = false;
if( VP_WP_Admin::is_post_or_page() )
{
$types = array_unique( array_merge( $types['metabox'], $types['shortcodegenerator'] ) );
if( in_array('wpeditor', $types ) )
{
if( !VP_ShortcodeGenerator::pool_supports_editor() and !VP_Metabox::pool_supports_editor() )
$dummy = true;
}
}
else
{
$types = $types['option'];
if( in_array('wpeditor', $types ) )
$dummy = true;
}
if( $dummy )
{
echo '<div style="display: none">';
add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
wp_editor ( '', 'vp_dummy_editor' );
echo '</div>';
}
}
}
if( !function_exists('vp_sg_init_buttons') )
{
function vp_sg_init_buttons()
{
if( VP_ShortcodeGenerator::pool_can_output() )
{
VP_ShortcodeGenerator::init_buttons();
}
}
}
if( !function_exists('vp_enqueue_scripts') )
{
function vp_enqueue_scripts()
{
$loader = VP_WP_Loader::instance();
$loader->build();
}
}
/**
* Easy way to get metabox values using dot notation
* example:
*
* vp_metabox('meta_name.field_name')
* vp_metabox('meta_name.group_name')
* vp_metabox('meta_name.group_name.0.field_name')
*
*/
if( !function_exists('vp_metabox') )
{
function vp_metabox($key, $default = null, $post_id = null)
{
global $post;
$vp_metaboxes = VP_Metabox::get_pool();
if(!is_null($post_id))
{
$the_post = get_post($post_id);
if ( empty($the_post) ) $post_id = null;
}
if(is_null($post) and is_null($post_id))
return $default;
$keys = explode('.', $key);
$temp = NULL;
foreach ($keys as $idx => $key)
{
if($idx == 0)
{
if(array_key_exists($key, $vp_metaboxes))
{
$temp = $vp_metaboxes[$key];
if(!is_null($post_id))
$temp->the_meta($post_id);
else
$temp->the_meta();
}
else
{
return $default;
}
}
else
{
if(is_object($temp) and get_class($temp) === 'VP_Metabox')
{
$temp = $temp->get_the_value($key);
}
else
{
if(is_array($temp) and array_key_exists($key, $temp))
{
$temp = $temp[$key];
}
else
{
return $default;
}
}
}
}
return $temp;
}
}
/**
* Easy way to get option values using dot notation
* example:
*
* vp_option('option_key.field_name')
*
*/
if( !function_exists('vp_option') )
{
function vp_option($key, $default = null)
{
$vp_options = VP_Option::get_pool();
if(empty($vp_options))
return $default;
$keys = explode('.', $key);
$temp = NULL;
foreach ($keys as $idx => $key)
{
if($idx == 0)
{
if(array_key_exists($key, $vp_options))
{
$temp = $vp_options[$key];
$temp = $temp->get_options();
}
else
{
return $default;
}
}
else
{
if(is_array($temp) and array_key_exists($key, $temp))
{
$temp = $temp[$key];
}
else
{
return $default;
}
}
}
return $temp;
}
}
/**
* EOF
*/