| 1 |
<?php |
| 2 |
|
| 3 |
if( defined('VP_VERSION') ) |
| 4 |
return; |
| 5 |
|
| 6 |
////////////////////////// |
| 7 |
// Include Constants // |
| 8 |
////////////////////////// |
| 9 |
require_once 'constant.php'; |
| 10 |
|
| 11 |
////////////////////////// |
| 12 |
// Include Autoloader // |
| 13 |
////////////////////////// |
| 14 |
require_once 'autoload.php'; |
| 15 |
|
| 16 |
////////////////////////// |
| 17 |
// Load Languages // |
| 18 |
////////////////////////// |
| 19 |
load_theme_textdomain('wp-ultimate-recipe', VP_DIR . '/lang'); |
| 20 |
|
| 21 |
////////////////////////// |
| 22 |
// Setup FileSystem // |
| 23 |
////////////////////////// |
| 24 |
$vpfs = VP_FileSystem::instance(); |
| 25 |
$vpfs->add_directories('views' , VP_VIEWS_DIR); |
| 26 |
$vpfs->add_directories('config' , VP_CONFIG_DIR); |
| 27 |
$vpfs->add_directories('data' , VP_DATA_DIR); |
| 28 |
$vpfs->add_directories('includes', VP_INCLUDE_DIR); |
| 29 |
|
| 30 |
////////////////////////// |
| 31 |
// Include Data Source // |
| 32 |
////////////////////////// |
| 33 |
foreach (glob(VP_DATA_DIR . "/*.php") as $datasource) |
| 34 |
{ |
| 35 |
require_once($datasource); |
| 36 |
} |
| 37 |
|
| 38 |
////////////////////////// |
| 39 |
// TGMPA Unsetting // |
| 40 |
////////////////////////// |
| 41 |
add_action('after_setup_theme', 'vp_tgm_ac_check'); |
| 42 |
|
| 43 |
if( !function_exists('vp_tgm_ac_check') ) |
| 44 |
{ |
| 45 |
function vp_tgm_ac_check() |
| 46 |
{ |
| 47 |
add_action('tgmpa_register', 'vp_tgm_ac_vafpress_check'); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
if( !function_exists('vp_tgm_ac_vafpress_check') ) |
| 52 |
{ |
| 53 |
function vp_tgm_ac_vafpress_check() |
| 54 |
{ |
| 55 |
if( defined('VP_VERSION') and class_exists('TGM_Plugin_Activation') ) |
| 56 |
{ |
| 57 |
foreach (TGM_Plugin_Activation::$instance->plugins as $key => &$plugin) |
| 58 |
{ |
| 59 |
if( $plugin['name'] === 'Vafpress Framework Plugin' ) |
| 60 |
{ |
| 61 |
unset(TGM_Plugin_Activation::$instance->plugins[$key]); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
////////////////////////// |
| 69 |
// Ajax Definition // |
| 70 |
////////////////////////// |
| 71 |
add_action('wp_ajax_vp_ajax_wrapper', 'vp_ajax_wrapper'); |
| 72 |
|
| 73 |
if( !function_exists('vp_ajax_wrapper') ) |
| 74 |
{ |
| 75 |
function vp_ajax_wrapper() |
| 76 |
{ |
| 77 |
$function = $_POST['func']; |
| 78 |
$params = $_POST['params']; |
| 79 |
|
| 80 |
if( VP_Security::instance()->is_function_whitelisted($function) ) |
| 81 |
{ |
| 82 |
if(!is_array($params)) |
| 83 |
$params = array($params); |
| 84 |
|
| 85 |
try { |
| 86 |
$result['data'] = call_user_func_array($function, $params); |
| 87 |
$result['status'] = true; |
| 88 |
$result['message'] = __("Successful", 'wp-ultimate-recipe'); |
| 89 |
} catch (Exception $e) { |
| 90 |
$result['data'] = ''; |
| 91 |
$result['status'] = false; |
| 92 |
$result['message'] = $e->getMessage(); |
| 93 |
} |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
$result['data'] = ''; |
| 98 |
$result['status'] = false; |
| 99 |
$result['message'] = __("Unauthorized function", 'wp-ultimate-recipe'); |
| 100 |
} |
| 101 |
|
| 102 |
if (ob_get_length()) ob_clean(); |
| 103 |
header('Content-type: application/json'); |
| 104 |
echo json_encode($result); |
| 105 |
die(); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
///////////////////////////////// |
| 110 |
// Pool and Dependencies Init // |
| 111 |
///////////////////////////////// |
| 112 |
add_action( 'init' , 'vp_metabox_enqueue' ); |
| 113 |
add_action( 'current_screen' , 'vp_sg_enqueue' ); |
| 114 |
add_action( 'admin_enqueue_scripts', 'vp_enqueue_scripts' ); |
| 115 |
add_action( 'current_screen' , 'vp_sg_init_buttons' ); |
| 116 |
add_filter( 'clean_url' , 'vp_ace_script_attributes', 10, 1 ); |
| 117 |
|
| 118 |
if( !function_exists('vp_ace_script_attributes') ) |
| 119 |
{ |
| 120 |
function vp_ace_script_attributes( $url ) |
| 121 |
{ |
| 122 |
if ( FALSE === strpos( $url, 'ace.js' ) ) |
| 123 |
return $url; |
| 124 |
|
| 125 |
return "$url' charset='utf8"; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
if( !function_exists('vp_metabox_enqueue') ) |
| 130 |
{ |
| 131 |
function vp_metabox_enqueue() |
| 132 |
{ |
| 133 |
if( VP_WP_Admin::is_post_or_page() and VP_Metabox::pool_can_output() ) |
| 134 |
{ |
| 135 |
$loader = VP_WP_Loader::instance(); |
| 136 |
$loader->add_main_js( 'vp-metabox' ); |
| 137 |
$loader->add_main_css( 'vp-metabox' ); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if( !function_exists('vp_sg_enqueue') ) |
| 143 |
{ |
| 144 |
function vp_sg_enqueue() |
| 145 |
{ |
| 146 |
if( VP_ShortcodeGenerator::pool_can_output() ) |
| 147 |
{ |
| 148 |
// enqueue dummy js |
| 149 |
$localize = VP_ShortcodeGenerator::build_localize(); |
| 150 |
wp_register_script( 'vp-sg-dummy', VP_PUBLIC_URL . '/js/dummy.js', array(), '', false ); |
| 151 |
wp_localize_script( 'vp-sg-dummy', 'vp_sg', $localize ); |
| 152 |
wp_enqueue_script( 'vp-sg-dummy' ); |
| 153 |
|
| 154 |
$loader = VP_WP_Loader::instance(); |
| 155 |
$loader->add_main_js( 'vp-shortcode' ); |
| 156 |
$loader->add_main_css( 'vp-shortcode' ); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
add_action('admin_footer', 'vp_post_dummy_editor'); |
| 162 |
|
| 163 |
if( !function_exists('vp_post_dummy_editor') ) |
| 164 |
{ |
| 165 |
function vp_post_dummy_editor() |
| 166 |
{ |
| 167 |
/** |
| 168 |
* If we're in post edit page, and the post type doesn't support `editor` |
| 169 |
* we need to echo out a dummy editor to load all necessary js and css |
| 170 |
* to be used in our own called wp editor. |
| 171 |
*/ |
| 172 |
$loader = VP_WP_Loader::instance(); |
| 173 |
$types = $loader->get_types(); |
| 174 |
$dummy = false; |
| 175 |
|
| 176 |
if( VP_WP_Admin::is_post_or_page() ) |
| 177 |
{ |
| 178 |
$types = array_unique( array_merge( $types['metabox'], $types['shortcodegenerator'] ) ); |
| 179 |
if( in_array('wpeditor', $types ) ) |
| 180 |
{ |
| 181 |
if( !VP_ShortcodeGenerator::pool_supports_editor() and !VP_Metabox::pool_supports_editor() ) |
| 182 |
$dummy = true; |
| 183 |
} |
| 184 |
} |
| 185 |
else |
| 186 |
{ |
| 187 |
$types = $types['option']; |
| 188 |
if( in_array('wpeditor', $types ) ) |
| 189 |
$dummy = true; |
| 190 |
} |
| 191 |
|
| 192 |
if( $dummy ) |
| 193 |
{ |
| 194 |
echo '<div style="display: none">'; |
| 195 |
add_filter( 'wp_default_editor', 'vp_post_dummy_editor_tinymce' ); |
| 196 |
wp_editor ( '', 'vp_dummy_editor' ); |
| 197 |
echo '</div>'; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
function vp_post_dummy_editor_tinymce() { |
| 202 |
return "tinymce"; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
if( !function_exists('vp_sg_init_buttons') ) |
| 207 |
{ |
| 208 |
function vp_sg_init_buttons() |
| 209 |
{ |
| 210 |
if( VP_ShortcodeGenerator::pool_can_output() ) |
| 211 |
{ |
| 212 |
VP_ShortcodeGenerator::init_buttons(); |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
if( !function_exists('vp_enqueue_scripts') ) |
| 218 |
{ |
| 219 |
function vp_enqueue_scripts() |
| 220 |
{ |
| 221 |
$loader = VP_WP_Loader::instance(); |
| 222 |
$loader->build(); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* Easy way to get metabox values using dot notation |
| 228 |
* example: |
| 229 |
* |
| 230 |
* vp_metabox('meta_name.field_name') |
| 231 |
* vp_metabox('meta_name.group_name') |
| 232 |
* vp_metabox('meta_name.group_name.0.field_name') |
| 233 |
* |
| 234 |
*/ |
| 235 |
|
| 236 |
if( !function_exists('vp_metabox') ) |
| 237 |
{ |
| 238 |
function vp_metabox($key, $default = null, $post_id = null) |
| 239 |
{ |
| 240 |
global $post; |
| 241 |
|
| 242 |
$vp_metaboxes = VP_Metabox::get_pool(); |
| 243 |
|
| 244 |
if(!is_null($post_id)) |
| 245 |
{ |
| 246 |
$the_post = get_post($post_id); |
| 247 |
if ( empty($the_post) ) $post_id = null; |
| 248 |
} |
| 249 |
|
| 250 |
if(is_null($post) and is_null($post_id)) |
| 251 |
return $default; |
| 252 |
|
| 253 |
$keys = explode('.', $key); |
| 254 |
$temp = NULL; |
| 255 |
|
| 256 |
foreach ($keys as $idx => $key) |
| 257 |
{ |
| 258 |
if($idx == 0) |
| 259 |
{ |
| 260 |
if(array_key_exists($key, $vp_metaboxes)) |
| 261 |
{ |
| 262 |
$temp = $vp_metaboxes[$key]; |
| 263 |
if(!is_null($post_id)) |
| 264 |
$temp->the_meta($post_id); |
| 265 |
else |
| 266 |
$temp->the_meta(); |
| 267 |
} |
| 268 |
else |
| 269 |
{ |
| 270 |
return $default; |
| 271 |
} |
| 272 |
} |
| 273 |
else |
| 274 |
{ |
| 275 |
if(is_object($temp) and get_class($temp) === 'VP_Metabox') |
| 276 |
{ |
| 277 |
$temp = $temp->get_the_value($key); |
| 278 |
} |
| 279 |
else |
| 280 |
{ |
| 281 |
if(is_array($temp) and array_key_exists($key, $temp)) |
| 282 |
{ |
| 283 |
$temp = $temp[$key]; |
| 284 |
} |
| 285 |
else |
| 286 |
{ |
| 287 |
return $default; |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
return $temp; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* Easy way to get option values using dot notation |
| 298 |
* example: |
| 299 |
* |
| 300 |
* vp_option('option_key.field_name') |
| 301 |
* |
| 302 |
*/ |
| 303 |
|
| 304 |
if( !function_exists('vp_option') ) |
| 305 |
{ |
| 306 |
function vp_option($key, $default = null) |
| 307 |
{ |
| 308 |
$vp_options = VP_Option::get_pool(); |
| 309 |
|
| 310 |
if(empty($vp_options)) |
| 311 |
return $default; |
| 312 |
|
| 313 |
$keys = explode('.', $key); |
| 314 |
$temp = NULL; |
| 315 |
|
| 316 |
foreach ($keys as $idx => $key) |
| 317 |
{ |
| 318 |
if($idx == 0) |
| 319 |
{ |
| 320 |
if(array_key_exists($key, $vp_options)) |
| 321 |
{ |
| 322 |
$temp = $vp_options[$key]; |
| 323 |
$temp = $temp->get_options(); |
| 324 |
} |
| 325 |
else |
| 326 |
{ |
| 327 |
return $default; |
| 328 |
} |
| 329 |
} |
| 330 |
else |
| 331 |
{ |
| 332 |
if(is_array($temp) and array_key_exists($key, $temp)) |
| 333 |
{ |
| 334 |
$temp = $temp[$key]; |
| 335 |
} |
| 336 |
else |
| 337 |
{ |
| 338 |
return $default; |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
return $temp; |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* EOF |
| 348 |
*/ |