| 1 |
<?php |
| 2 |
/** |
| 3 |
* Initialization Action. |
| 4 |
* |
| 5 |
* @package ULTP\Notice |
| 6 |
* @since v.1.1.0 |
| 7 |
*/ |
| 8 |
namespace ULTP; |
| 9 |
|
| 10 |
defined('ABSPATH') || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Initialization class. |
| 14 |
*/ |
| 15 |
class ULTP_Initialization{ |
| 16 |
|
| 17 |
private $all_blocks; |
| 18 |
|
| 19 |
/** |
| 20 |
* Setup class. |
| 21 |
* |
| 22 |
* @since v.1.1.0 |
| 23 |
*/ |
| 24 |
public function __construct(){ |
| 25 |
$this->compatibility_check(); |
| 26 |
$this->requires(); // Include Necessary Files |
| 27 |
$this->blocks(); // Include Blocks |
| 28 |
$this->include_addons(); // Include Addons |
| 29 |
|
| 30 |
add_action('wp', array($this, 'popular_posts_tracker_callback')); |
| 31 |
add_filter('block_categories_all', array($this, 'register_category_callback'), 10, 2); // Block Category Register |
| 32 |
add_action('after_setup_theme', array($this, 'add_image_size')); |
| 33 |
|
| 34 |
add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor |
| 35 |
add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel |
| 36 |
add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend |
| 37 |
register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook')); |
| 38 |
add_action( 'activated_plugin', array($this, 'activation_redirect')); |
| 39 |
|
| 40 |
add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call |
| 41 |
add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User |
| 42 |
add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call |
| 43 |
add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User |
| 44 |
add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call |
| 45 |
add_action('wp_ajax_nopriv_ultp_pagination',array($this, 'ultp_pagination_callback')); // Page Number AJAX Call Logout User |
| 46 |
add_action('wp_ajax_ultp_addon', array($this, 'ultp_addon_callback')); // Next Previous AJAX Call |
| 47 |
|
| 48 |
add_action('admin_init', array($this, 'check_theme_compatibility')); |
| 49 |
add_action( 'after_switch_theme', array($this, 'wpxpo_swithch_thememe')); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
* Theme Switch Callback |
| 55 |
* |
| 56 |
* @since v.1.1.0 |
| 57 |
* @return NULL |
| 58 |
*/ |
| 59 |
public function wpxpo_swithch_thememe () { |
| 60 |
$this->check_theme_compatibility(); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* Theme Compatibility Action |
| 66 |
* |
| 67 |
* @since v.1.1.0 |
| 68 |
* @return NULL |
| 69 |
*/ |
| 70 |
public function check_theme_compatibility() { |
| 71 |
$licence = apply_filters( 'ultp_theme_integration' , FALSE); |
| 72 |
$theme = get_transient( 'ulpt_theme_enable' ); |
| 73 |
|
| 74 |
if( $licence ) { |
| 75 |
if( $theme != 'integration' ) { |
| 76 |
$themes = wp_get_theme(); |
| 77 |
$api_params = array( |
| 78 |
'wpxpo_theme_action' => 'theme_license', |
| 79 |
'slug' => $themes->get('TextDomain'), |
| 80 |
'author' => $themes->get('Author'), |
| 81 |
'item_id' => 181, |
| 82 |
'url' => home_url() |
| 83 |
); |
| 84 |
|
| 85 |
$response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
| 86 |
|
| 87 |
if ( !is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) { |
| 88 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 89 |
if(isset($license_data->license)) { |
| 90 |
if ( $license_data->license == 'valid' ) { |
| 91 |
set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} else { |
| 97 |
if ( $theme == 'integration' ) { |
| 98 |
delete_transient('ulpt_theme_enable'); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
/** |
| 105 |
* Check Compatibility |
| 106 |
* |
| 107 |
* @since v.1.0.0 |
| 108 |
* @return NULL |
| 109 |
*/ |
| 110 |
public function compatibility_check(){ |
| 111 |
require_once ULTP_PATH.'classes/Compatibility.php'; |
| 112 |
new \ULTP\Compatibility(); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
/** |
| 117 |
* Option Panel CSS and JS Scripts |
| 118 |
* |
| 119 |
* @since v.1.0.0 |
| 120 |
* @return NULL |
| 121 |
*/ |
| 122 |
public function register_scripts_option_panel_callback(){ |
| 123 |
wp_enqueue_style('wp-color-picker'); |
| 124 |
wp_enqueue_script('wp-color-picker'); |
| 125 |
wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true); |
| 126 |
wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER); |
| 127 |
wp_localize_script('ultp-option-script', 'ultp_option_panel', array( |
| 128 |
'width' => ultimate_post()->get_setting('editor_container'), |
| 129 |
'security' => wp_create_nonce('ultp-nonce'), |
| 130 |
'ajax' => admin_url('admin-ajax.php') |
| 131 |
)); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/** |
| 136 |
* Common Frontend and Backend CSS and JS Scripts |
| 137 |
* |
| 138 |
* @since v.1.0.0 |
| 139 |
* @return NULL |
| 140 |
*/ |
| 141 |
public function register_scripts_common(){ |
| 142 |
wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER ); |
| 143 |
wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true); |
| 144 |
wp_localize_script('ultp-script', 'ultp_data_frontend', array( |
| 145 |
'url' => ULTP_URL, |
| 146 |
'ajax' => admin_url('admin-ajax.php'), |
| 147 |
'security' => wp_create_nonce('ultp-nonce') |
| 148 |
)); |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
/** |
| 154 |
* Only Frontend CSS and JS Scripts |
| 155 |
* |
| 156 |
* @since v.1.0.0 |
| 157 |
* @return NULL |
| 158 |
*/ |
| 159 |
public function register_scripts_front_callback() { |
| 160 |
$call_common = false; |
| 161 |
if ('yes' == get_post_meta(ultimate_post()->get_ID(), '_ultp_active', true)) { |
| 162 |
$call_common = true; |
| 163 |
$this->register_scripts_common(); |
| 164 |
} else { |
| 165 |
if (ultimate_post()->is_builder()) { |
| 166 |
$call_common = true; |
| 167 |
$this->register_scripts_common(); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
// For WidgetWidget |
| 172 |
$has_block = false; |
| 173 |
$widget_blocks = array(); |
| 174 |
global $wp_registered_sidebars, $sidebars_widgets; |
| 175 |
foreach ($wp_registered_sidebars as $key => $value) { |
| 176 |
if (is_active_sidebar($key)) { |
| 177 |
foreach ($sidebars_widgets[$key] as $val) { |
| 178 |
if (strpos($val, 'block-') !== false) { |
| 179 |
if (empty($widget_blocks)) { |
| 180 |
$widget_blocks = get_option( 'widget_block' ); |
| 181 |
} |
| 182 |
foreach ( (array) $widget_blocks as $block ) { |
| 183 |
if ( isset( $block['content'] ) && strpos($block['content'], 'wp:ultimate-post') !== false ) { |
| 184 |
$has_block = true; |
| 185 |
break; |
| 186 |
} |
| 187 |
} |
| 188 |
if ($has_block) { |
| 189 |
break; |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
if ($has_block) { |
| 196 |
if (!$call_common) { |
| 197 |
$this->register_scripts_common(); |
| 198 |
} |
| 199 |
$css = get_option('ultp-widget', true); |
| 200 |
if ($css) { |
| 201 |
wp_register_style('ultp-post-widget', false ); |
| 202 |
wp_enqueue_style('ultp-post-widget' ); |
| 203 |
wp_add_inline_style('ultp-post-widget', $css); |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
/** |
| 210 |
* Only Backend CSS and JS Scripts |
| 211 |
* |
| 212 |
* @since v.1.0.0 |
| 213 |
* @return NULL |
| 214 |
*/ |
| 215 |
public function register_scripts_back_callback() { |
| 216 |
$this->register_scripts_common(); |
| 217 |
global $pagenow; |
| 218 |
$depends = 'wp-editor'; |
| 219 |
if ( $pagenow === 'widgets.php' ) { |
| 220 |
$depends = 'wp-edit-widgets'; |
| 221 |
} |
| 222 |
wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.min.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', $depends ), ULTP_VER, true); |
| 223 |
wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER); |
| 224 |
if(is_rtl()){ |
| 225 |
wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); |
| 226 |
} |
| 227 |
$is_active = ultimate_post()->is_lc_active(); |
| 228 |
wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array( |
| 229 |
'url' => ULTP_URL, |
| 230 |
'ajax' => admin_url('admin-ajax.php'), |
| 231 |
'security' => wp_create_nonce('ultp-nonce'), |
| 232 |
'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'), |
| 233 |
'upload' => wp_upload_dir()['basedir'] . '/ultp', |
| 234 |
'premium_link' => ultimate_post()->get_premium_link(), |
| 235 |
'license' => $is_active ? get_option('edd_ultp_license_key') : '', |
| 236 |
'active' => $is_active, |
| 237 |
'archive' => $is_active ? ultimate_post()->is_archive_builder() : '', |
| 238 |
'settings' => ultimate_post()->get_setting() |
| 239 |
)); |
| 240 |
|
| 241 |
wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' ); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
/** |
| 246 |
* Fire When Plugin First Install |
| 247 |
* |
| 248 |
* @since v.1.0.0 |
| 249 |
* @return NULL |
| 250 |
*/ |
| 251 |
public function install_hook() { |
| 252 |
if (!get_option('ultp_options')) { |
| 253 |
ultimate_post()->init_set_data(); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
/** |
| 259 |
* Redirect After Active Plugin |
| 260 |
* |
| 261 |
* @since v.1.0.0 |
| 262 |
* @param STRING | Plugin Path |
| 263 |
* @return NULL |
| 264 |
*/ |
| 265 |
public function activation_redirect($plugin) { |
| 266 |
if( $plugin == 'ultimate-post/ultimate-post.php' ) { |
| 267 |
exit(wp_redirect(admin_url('admin.php?page=ultp-settings'))); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
/** |
| 273 |
* Require Blocks |
| 274 |
* |
| 275 |
* @since v.1.0.0 |
| 276 |
* @return NULL |
| 277 |
*/ |
| 278 |
public function blocks() { |
| 279 |
$setting = ultimate_post()->get_setting(); |
| 280 |
if (!isset($setting['post_list_1']) || $setting['post_list_1'] == 'yes') { |
| 281 |
require_once ULTP_PATH.'blocks/Post_List_1.php'; |
| 282 |
$this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1(); |
| 283 |
} |
| 284 |
if (!isset($setting['post_list_2']) || $setting['post_list_2'] == 'yes') { |
| 285 |
require_once ULTP_PATH.'blocks/Post_List_2.php'; |
| 286 |
$this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2(); |
| 287 |
} |
| 288 |
if (!isset($setting['post_list_3']) || $setting['post_list_3'] == 'yes') { |
| 289 |
require_once ULTP_PATH.'blocks/Post_List_3.php'; |
| 290 |
$this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3(); |
| 291 |
} |
| 292 |
if (!isset($setting['post_list_4']) || $setting['post_list_4'] == 'yes') { |
| 293 |
require_once ULTP_PATH.'blocks/Post_List_4.php'; |
| 294 |
$this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4(); |
| 295 |
} |
| 296 |
if (!isset($setting['post_grid_1']) || $setting['post_grid_1'] == 'yes') { |
| 297 |
require_once ULTP_PATH.'blocks/Post_Grid_1.php'; |
| 298 |
$this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1(); |
| 299 |
} |
| 300 |
if (!isset($setting['post_grid_2']) || $setting['post_grid_2'] == 'yes') { |
| 301 |
require_once ULTP_PATH.'blocks/Post_Grid_2.php'; |
| 302 |
$this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2(); |
| 303 |
} |
| 304 |
if (!isset($setting['post_grid_3']) || $setting['post_grid_3'] == 'yes') { |
| 305 |
require_once ULTP_PATH.'blocks/Post_Grid_3.php'; |
| 306 |
$this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3(); |
| 307 |
} |
| 308 |
if (!isset($setting['post_grid_4']) || $setting['post_grid_4'] == 'yes') { |
| 309 |
require_once ULTP_PATH.'blocks/Post_Grid_4.php'; |
| 310 |
$this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4(); |
| 311 |
} |
| 312 |
if (!isset($setting['post_grid_5']) || $setting['post_grid_5'] == 'yes') { |
| 313 |
require_once ULTP_PATH.'blocks/Post_Grid_5.php'; |
| 314 |
$this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5(); |
| 315 |
} |
| 316 |
if (!isset($setting['post_grid_6']) || $setting['post_grid_6'] == 'yes') { |
| 317 |
require_once ULTP_PATH.'blocks/Post_Grid_6.php'; |
| 318 |
$this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6(); |
| 319 |
} |
| 320 |
if (!isset($setting['post_grid_7']) || $setting['post_grid_7'] == 'yes') { |
| 321 |
require_once ULTP_PATH.'blocks/Post_Grid_7.php'; |
| 322 |
$this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7(); |
| 323 |
} |
| 324 |
if (!isset($setting['post_slider_1']) || $setting['post_slider_1'] == 'yes') { |
| 325 |
require_once ULTP_PATH.'blocks/Post_Slider_1.php'; |
| 326 |
$this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1(); |
| 327 |
} |
| 328 |
if (!isset($setting['post_module_1']) || $setting['post_module_1'] == 'yes') { |
| 329 |
require_once ULTP_PATH.'blocks/Post_Module_1.php'; |
| 330 |
$this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1(); |
| 331 |
} |
| 332 |
if (!isset($setting['post_module_2']) || $setting['post_module_2'] == 'yes') { |
| 333 |
require_once ULTP_PATH.'blocks/Post_Module_2.php'; |
| 334 |
$this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2(); |
| 335 |
} |
| 336 |
if (!isset($setting['heading']) || $setting['heading'] == 'yes') { |
| 337 |
require_once ULTP_PATH.'blocks/Heading.php'; |
| 338 |
$this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading(); |
| 339 |
} |
| 340 |
if (!isset($setting['image']) || $setting['image'] == 'yes') { |
| 341 |
require_once ULTP_PATH.'blocks/Image.php'; |
| 342 |
$this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image(); |
| 343 |
} |
| 344 |
if (!isset($setting['taxonomy']) || $setting['taxonomy'] == 'yes') { |
| 345 |
require_once ULTP_PATH.'blocks/Taxonomy.php'; |
| 346 |
$this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy(); |
| 347 |
} |
| 348 |
|
| 349 |
require_once ULTP_PATH.'blocks/Archive_Title.php'; |
| 350 |
$this->all_blocks['ultimate-post_archive-title'] = new \ULTP\blocks\Archive_Title(); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
/** |
| 355 |
* Necessary Requires Class |
| 356 |
* |
| 357 |
* @since v.1.0.0 |
| 358 |
* @return NULL |
| 359 |
*/ |
| 360 |
public function requires() { |
| 361 |
require_once ULTP_PATH.'classes/Notice.php'; |
| 362 |
require_once ULTP_PATH.'classes/Styles.php'; |
| 363 |
require_once ULTP_PATH.'classes/Options.php'; |
| 364 |
require_once ULTP_PATH.'classes/REST_API.php'; |
| 365 |
require_once ULTP_PATH.'classes/Caches.php'; |
| 366 |
new \ULTP\REST_API(); |
| 367 |
new \ULTP\Caches(); |
| 368 |
new \ULTP\Options(); |
| 369 |
new \ULTP\Styles(); |
| 370 |
new \ULTP\Notice(); |
| 371 |
|
| 372 |
require_once ULTP_PATH.'classes/Deactive.php'; |
| 373 |
new \ULTP\Deactive(); |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
/** |
| 378 |
* Block Categories Initialization |
| 379 |
* |
| 380 |
* @since v.1.0.0 |
| 381 |
* @param $categories(ARRAY) | $post (ARRAY) |
| 382 |
* @return NULL |
| 383 |
*/ |
| 384 |
public function register_category_callback( $categories, $post ) { |
| 385 |
return array_merge( |
| 386 |
array( |
| 387 |
array( |
| 388 |
'slug' => 'ultimate-post', |
| 389 |
'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' ) |
| 390 |
) |
| 391 |
), $categories |
| 392 |
); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
/** |
| 397 |
* Post View Counter for Every Post |
| 398 |
* |
| 399 |
* @since v.1.0.0 |
| 400 |
* @param NUMBER | Post ID |
| 401 |
* @return NULL |
| 402 |
*/ |
| 403 |
public function popular_posts_tracker_callback($post_id) { |
| 404 |
if (!is_single()){ return; } |
| 405 |
global $post; |
| 406 |
$post_id = $post->ID; |
| 407 |
$isEnable = apply_filters('ultp_view_cookies', true); |
| 408 |
if ($post_id && $isEnable) { |
| 409 |
$has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false; |
| 410 |
if (!$has_cookie) { |
| 411 |
$count = (int)get_post_meta( $post_id, '__post_views_count', true ); |
| 412 |
update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 ); |
| 413 |
setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies |
| 414 |
} |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
/** |
| 420 |
* Set Image Size |
| 421 |
* |
| 422 |
* @since v.1.0.0 |
| 423 |
* @return NULL |
| 424 |
*/ |
| 425 |
public function add_image_size() { |
| 426 |
$size_disable = ultimate_post()->get_setting('disable_image_size'); |
| 427 |
if ($size_disable != 'yes') { |
| 428 |
add_image_size('ultp_layout_landscape_large', 1200, 800, true); |
| 429 |
add_image_size('ultp_layout_landscape', 870, 570, true); |
| 430 |
add_image_size('ultp_layout_portrait', 600, 900, true); |
| 431 |
add_image_size('ultp_layout_square', 600, 600, true); |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
/** |
| 437 |
* Include Addons Directory |
| 438 |
* |
| 439 |
* @since v.1.0.0 |
| 440 |
* @return NULL |
| 441 |
*/ |
| 442 |
public function include_addons() { |
| 443 |
$addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir'); |
| 444 |
if (count($addons_dir) > 0) { |
| 445 |
foreach( $addons_dir as $key => $value ) { |
| 446 |
$addon_dir_name = str_replace(dirname($value).'/', '', $value); |
| 447 |
$file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php'; |
| 448 |
if ( file_exists($file_name) ) { |
| 449 |
include_once $file_name; |
| 450 |
} |
| 451 |
} |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
/** |
| 457 |
* Addon Callback |
| 458 |
* |
| 459 |
* @since v.1.0.0 |
| 460 |
* @return STRING |
| 461 |
*/ |
| 462 |
public function ultp_addon_callback() { |
| 463 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 464 |
return ; |
| 465 |
} |
| 466 |
$addon_name = sanitize_text_field($_POST['addon']); |
| 467 |
$addon_value = sanitize_text_field($_POST['value']); |
| 468 |
if ($addon_name && current_user_can('administrator')) { |
| 469 |
$addon_data = ultimate_post()->get_setting(); |
| 470 |
$addon_data[$addon_name] = $addon_value; |
| 471 |
$GLOBALS['ultp_settings'][$addon_name] = $addon_value; |
| 472 |
update_option('ultp_options', $addon_data); |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
/** |
| 478 |
* Next Preview Callback of the Blocks |
| 479 |
* |
| 480 |
* @since v.1.0.0 |
| 481 |
* @return STRING |
| 482 |
*/ |
| 483 |
public function ultp_next_prev_callback() { |
| 484 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 485 |
return ; |
| 486 |
} |
| 487 |
|
| 488 |
$paged = sanitize_text_field($_POST['paged']); |
| 489 |
$blockId = sanitize_text_field($_POST['blockId']); |
| 490 |
$postId = sanitize_text_field($_POST['postId']); |
| 491 |
$blockRaw = sanitize_text_field($_POST['blockName']); |
| 492 |
$builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : ''; |
| 493 |
|
| 494 |
$blockName = str_replace('_','/', $blockRaw); |
| 495 |
|
| 496 |
if( $paged && $blockId && $postId && $blockName ) { |
| 497 |
$post = get_post($postId); |
| 498 |
if (has_blocks($post->post_content)) { |
| 499 |
$blocks = parse_blocks($post->post_content); |
| 500 |
$this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder); |
| 501 |
} |
| 502 |
} |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
/** |
| 507 |
* Filter Callback of the Blocks |
| 508 |
* |
| 509 |
* @since v.1.0.0 |
| 510 |
* @return STRING |
| 511 |
*/ |
| 512 |
public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) { |
| 513 |
foreach ($blocks as $key => $value) { |
| 514 |
if($blockName == $value['blockName']) { |
| 515 |
if($value['attrs']['blockId'] == $blockId) { |
| 516 |
$attr = $this->all_blocks[$blockRaw]->get_attributes(true); |
| 517 |
if($taxonomy) { |
| 518 |
$value['attrs']['queryTaxValue'] = json_encode(array($taxonomy)); |
| 519 |
$value['attrs']['queryTax'] = $taxtype; |
| 520 |
} |
| 521 |
if(isset($value['attrs']['queryNumber'])){ |
| 522 |
$value['attrs']['queryNumber'] = $value['attrs']['queryNumber']; |
| 523 |
} |
| 524 |
$attr = array_merge($attr, $value['attrs']); |
| 525 |
echo $this->all_blocks[$blockRaw]->content($attr, true); |
| 526 |
die(); |
| 527 |
} |
| 528 |
} |
| 529 |
if(!empty($value['innerBlocks'])){ |
| 530 |
$this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
/** |
| 537 |
* Filter Callback of the Blocks |
| 538 |
* |
| 539 |
* @since v.1.0.0 |
| 540 |
* @return STRING |
| 541 |
*/ |
| 542 |
public function ultp_filter_callback() { |
| 543 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 544 |
return ; |
| 545 |
} |
| 546 |
|
| 547 |
$taxtype = sanitize_text_field($_POST['taxtype']); |
| 548 |
if( $taxtype ) { |
| 549 |
$blockId = sanitize_text_field($_POST['blockId']); |
| 550 |
$postId = sanitize_text_field($_POST['postId']); |
| 551 |
$taxonomy = sanitize_text_field($_POST['taxonomy']); |
| 552 |
$blockRaw = sanitize_text_field($_POST['blockName']); |
| 553 |
$blockName = str_replace('_','/', $blockRaw); |
| 554 |
$post = get_post($postId); |
| 555 |
if (has_blocks($post->post_content)) { |
| 556 |
$blocks = parse_blocks($post->post_content); |
| 557 |
$this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
/** |
| 564 |
* Pagination of the Blocks |
| 565 |
* |
| 566 |
* @since v.1.0.0 |
| 567 |
* @return STRING |
| 568 |
*/ |
| 569 |
public function ultp_pagination_callback() { |
| 570 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) { |
| 571 |
return ; |
| 572 |
} |
| 573 |
|
| 574 |
$paged = sanitize_text_field($_POST['paged']); |
| 575 |
if($paged) { |
| 576 |
$blockId = sanitize_text_field($_POST['blockId']); |
| 577 |
$postId = sanitize_text_field($_POST['postId']); |
| 578 |
$blockRaw = sanitize_text_field($_POST['blockName']); |
| 579 |
$builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : ''; |
| 580 |
$blockName = str_replace('_','/', $blockRaw); |
| 581 |
$post = get_post($postId); |
| 582 |
if (has_blocks($post->post_content)) { |
| 583 |
$blocks = parse_blocks($post->post_content); |
| 584 |
$this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder); |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
/** |
| 591 |
* Blocks Content Start |
| 592 |
* |
| 593 |
* @since v.1.0.0 |
| 594 |
* @return STRING |
| 595 |
*/ |
| 596 |
public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder) { |
| 597 |
foreach ($blocks as $key => $value) { |
| 598 |
if($blockName == $value['blockName']) { |
| 599 |
if($value['attrs']['blockId'] == $blockId) { |
| 600 |
$attr = $this->all_blocks[$blockRaw]->get_attributes(true); |
| 601 |
$value['attrs']['paged'] = $paged; |
| 602 |
if ($builder) { |
| 603 |
$value['attrs']['builder'] = $builder; |
| 604 |
} |
| 605 |
$attr = array_merge($attr, $value['attrs']); |
| 606 |
echo $this->all_blocks[$blockRaw]->content($attr, true); |
| 607 |
die(); |
| 608 |
} |
| 609 |
} |
| 610 |
if(!empty($value['innerBlocks'])){ |
| 611 |
$this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder); |
| 612 |
} |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
} |