| 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_head', array($this, 'popular_posts_tracker_callback')); |
| 31 |
add_filter('block_categories', 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 |
if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) { |
| 161 |
$this->register_scripts_common(); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
/** |
| 167 |
* Only Backend CSS and JS Scripts |
| 168 |
* |
| 169 |
* @since v.1.0.0 |
| 170 |
* @return NULL |
| 171 |
*/ |
| 172 |
public function register_scripts_back_callback() { |
| 173 |
$this->register_scripts_common(); |
| 174 |
wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.min.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor' ), ULTP_VER, true); |
| 175 |
wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER); |
| 176 |
if(is_rtl()){ |
| 177 |
wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); |
| 178 |
} |
| 179 |
|
| 180 |
$import = ultimate_post()->get_setting('hide_import_btn'); |
| 181 |
|
| 182 |
$is_active = get_option('edd_ultp_license_status') == 'valid' ? true : ( get_transient( 'ulpt_theme_enable' ) == 'integration' ? true : false ); |
| 183 |
|
| 184 |
wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array( |
| 185 |
'url' => ULTP_URL, |
| 186 |
'ajax' => admin_url('admin-ajax.php'), |
| 187 |
'security' => wp_create_nonce('ultp-nonce'), |
| 188 |
'hide_import_btn' => $import, |
| 189 |
'upload' => wp_upload_dir()['basedir'] . '/ultp', |
| 190 |
'premium_link' => ultimate_post()->get_premium_link(), |
| 191 |
'license' => get_option('edd_ultp_license_key'), |
| 192 |
'active' => $is_active, |
| 193 |
)); |
| 194 |
|
| 195 |
wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' ); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
/** |
| 200 |
* Fire When Plugin First Install |
| 201 |
* |
| 202 |
* @since v.1.0.0 |
| 203 |
* @return NULL |
| 204 |
*/ |
| 205 |
public function install_hook() { |
| 206 |
if (!get_option('ultp_options')) { |
| 207 |
ultimate_post()->init_set_data(); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
/** |
| 213 |
* Redirect After Active Plugin |
| 214 |
* |
| 215 |
* @since v.1.0.0 |
| 216 |
* @param STRING | Plugin Path |
| 217 |
* @return NULL |
| 218 |
*/ |
| 219 |
public function activation_redirect($plugin) { |
| 220 |
if( $plugin == 'ultimate-post/ultimate-post.php' ) { |
| 221 |
exit(wp_redirect(admin_url('admin.php?page=ultp-settings'))); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
/** |
| 227 |
* Require Blocks |
| 228 |
* |
| 229 |
* @since v.1.0.0 |
| 230 |
* @return NULL |
| 231 |
*/ |
| 232 |
public function blocks() { |
| 233 |
require_once ULTP_PATH.'blocks/Post_List_1.php'; |
| 234 |
require_once ULTP_PATH.'blocks/Post_List_2.php'; |
| 235 |
require_once ULTP_PATH.'blocks/Post_List_3.php'; |
| 236 |
require_once ULTP_PATH.'blocks/Post_List_4.php'; |
| 237 |
require_once ULTP_PATH.'blocks/Post_Slider_1.php'; |
| 238 |
require_once ULTP_PATH.'blocks/Post_Grid_1.php'; |
| 239 |
require_once ULTP_PATH.'blocks/Post_Grid_2.php'; |
| 240 |
require_once ULTP_PATH.'blocks/Post_Grid_3.php'; |
| 241 |
require_once ULTP_PATH.'blocks/Post_Grid_4.php'; |
| 242 |
require_once ULTP_PATH.'blocks/Post_Grid_5.php'; |
| 243 |
require_once ULTP_PATH.'blocks/Post_Grid_6.php'; |
| 244 |
require_once ULTP_PATH.'blocks/Post_Grid_7.php'; |
| 245 |
require_once ULTP_PATH.'blocks/Heading.php'; |
| 246 |
require_once ULTP_PATH.'blocks/Image.php'; |
| 247 |
require_once ULTP_PATH.'blocks/Post_Module_1.php'; |
| 248 |
require_once ULTP_PATH.'blocks/Post_Module_2.php'; |
| 249 |
require_once ULTP_PATH.'blocks/Taxonomy.php'; |
| 250 |
$this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1(); |
| 251 |
$this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2(); |
| 252 |
$this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3(); |
| 253 |
$this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4(); |
| 254 |
$this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1(); |
| 255 |
$this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1(); |
| 256 |
$this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2(); |
| 257 |
$this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3(); |
| 258 |
$this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4(); |
| 259 |
$this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5(); |
| 260 |
$this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6(); |
| 261 |
$this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7(); |
| 262 |
$this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading(); |
| 263 |
$this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image(); |
| 264 |
$this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1(); |
| 265 |
$this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2(); |
| 266 |
$this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy(); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
/** |
| 271 |
* Necessary Requires Class |
| 272 |
* |
| 273 |
* @since v.1.0.0 |
| 274 |
* @return NULL |
| 275 |
*/ |
| 276 |
public function requires() { |
| 277 |
require_once ULTP_PATH.'classes/Notice.php'; |
| 278 |
require_once ULTP_PATH.'classes/Styles.php'; |
| 279 |
require_once ULTP_PATH.'classes/Options.php'; |
| 280 |
require_once ULTP_PATH.'classes/REST_API.php'; |
| 281 |
require_once ULTP_PATH.'classes/Caches.php'; |
| 282 |
new \ULTP\REST_API(); |
| 283 |
new \ULTP\Caches(); |
| 284 |
new \ULTP\Options(); |
| 285 |
new \ULTP\Styles(); |
| 286 |
new \ULTP\Notice(); |
| 287 |
|
| 288 |
require_once ULTP_PATH.'classes/Deactive.php'; |
| 289 |
new \ULTP\Deactive(); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
/** |
| 294 |
* Block Categories Initialization |
| 295 |
* |
| 296 |
* @since v.1.0.0 |
| 297 |
* @param $categories(ARRAY) | $post (ARRAY) |
| 298 |
* @return NULL |
| 299 |
*/ |
| 300 |
public function register_category_callback( $categories, $post ) { |
| 301 |
return array_merge( |
| 302 |
array( |
| 303 |
array( |
| 304 |
'slug' => 'ultimate-post', |
| 305 |
'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' ) |
| 306 |
) |
| 307 |
), $categories |
| 308 |
); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
/** |
| 313 |
* Post View Counter for Every Post |
| 314 |
* |
| 315 |
* @since v.1.0.0 |
| 316 |
* @param NUMBER | Post ID |
| 317 |
* @return NULL |
| 318 |
*/ |
| 319 |
public function popular_posts_tracker_callback($post_id) { |
| 320 |
if (!is_single()){ return; } |
| 321 |
global $post; |
| 322 |
if (empty($post_id)) { $post_id = $post->ID; } |
| 323 |
$count = (int)get_post_meta( $post_id, '__post_views_count', true ); |
| 324 |
update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 ); |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
/** |
| 329 |
* Set Image Size |
| 330 |
* |
| 331 |
* @since v.1.0.0 |
| 332 |
* @return NULL |
| 333 |
*/ |
| 334 |
public function add_image_size() { |
| 335 |
$size_disable = ultimate_post()->get_setting('disable_image_size'); |
| 336 |
if ($size_disable != 'yes') { |
| 337 |
add_image_size('ultp_layout_landscape_large', 1200, 800, true); |
| 338 |
add_image_size('ultp_layout_landscape', 870, 570, true); |
| 339 |
add_image_size('ultp_layout_portrait', 600, 900, true); |
| 340 |
add_image_size('ultp_layout_square', 600, 600, true); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
/** |
| 346 |
* Include Addons Directory |
| 347 |
* |
| 348 |
* @since v.1.0.0 |
| 349 |
* @return NULL |
| 350 |
*/ |
| 351 |
public function include_addons() { |
| 352 |
$addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir'); |
| 353 |
if (count($addons_dir) > 0) { |
| 354 |
foreach( $addons_dir as $key => $value ) { |
| 355 |
$addon_dir_name = str_replace(dirname($value).'/', '', $value); |
| 356 |
$file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php'; |
| 357 |
if ( file_exists($file_name) ) { |
| 358 |
include_once $file_name; |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
/** |
| 366 |
* Addon Callback |
| 367 |
* |
| 368 |
* @since v.1.0.0 |
| 369 |
* @return STRING |
| 370 |
*/ |
| 371 |
public function ultp_addon_callback() { |
| 372 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 373 |
return ; |
| 374 |
} |
| 375 |
$addon_name = sanitize_text_field($_POST['addon']); |
| 376 |
$addon_value = sanitize_text_field($_POST['value']); |
| 377 |
if ($addon_name) { |
| 378 |
$addon_data = ultimate_post()->get_setting(); |
| 379 |
$addon_data[$addon_name] = $addon_value; |
| 380 |
$GLOBALS['ultp_settings'][$addon_name] = $addon_value; |
| 381 |
update_option('ultp_options', $addon_data); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
/** |
| 387 |
* Next Preview Callback of the Blocks |
| 388 |
* |
| 389 |
* @since v.1.0.0 |
| 390 |
* @return STRING |
| 391 |
*/ |
| 392 |
public function ultp_next_prev_callback() { |
| 393 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 394 |
return ; |
| 395 |
} |
| 396 |
|
| 397 |
$paged = sanitize_text_field($_POST['paged']); |
| 398 |
$blockId = sanitize_text_field($_POST['blockId']); |
| 399 |
$postId = sanitize_text_field($_POST['postId']); |
| 400 |
$blockRaw = sanitize_text_field($_POST['blockName']); |
| 401 |
$blockName = str_replace('_','/', $blockRaw); |
| 402 |
|
| 403 |
if( $paged && $blockId && $postId && $blockName ) { |
| 404 |
$post = get_post($postId); |
| 405 |
if (has_blocks($post->post_content)) { |
| 406 |
$blocks = parse_blocks($post->post_content); |
| 407 |
$this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName); |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
/** |
| 414 |
* Filter Callback of the Blocks |
| 415 |
* |
| 416 |
* @since v.1.0.0 |
| 417 |
* @return STRING |
| 418 |
*/ |
| 419 |
public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) { |
| 420 |
foreach ($blocks as $key => $value) { |
| 421 |
if($blockName == $value['blockName']) { |
| 422 |
if($value['attrs']['blockId'] == $blockId) { |
| 423 |
$attr = $this->all_blocks[$blockRaw]->get_attributes(true); |
| 424 |
if($taxonomy) { |
| 425 |
$value['attrs']['queryTaxValue'] = json_encode(array($taxonomy)); |
| 426 |
$value['attrs']['queryTax'] = $taxtype; |
| 427 |
} |
| 428 |
if(isset($value['attrs']['queryNumber'])){ |
| 429 |
$value['attrs']['queryNumber'] = $value['attrs']['queryNumber']; |
| 430 |
} |
| 431 |
$attr = array_merge($attr, $value['attrs']); |
| 432 |
echo $this->all_blocks[$blockRaw]->content($attr, true); |
| 433 |
die(); |
| 434 |
} |
| 435 |
} |
| 436 |
if(!empty($value['innerBlocks'])){ |
| 437 |
$this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); |
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
/** |
| 444 |
* Filter Callback of the Blocks |
| 445 |
* |
| 446 |
* @since v.1.0.0 |
| 447 |
* @return STRING |
| 448 |
*/ |
| 449 |
public function ultp_filter_callback() { |
| 450 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){ |
| 451 |
return ; |
| 452 |
} |
| 453 |
|
| 454 |
$taxtype = sanitize_text_field($_POST['taxtype']); |
| 455 |
$blockId = sanitize_text_field($_POST['blockId']); |
| 456 |
$postId = sanitize_text_field($_POST['postId']); |
| 457 |
$taxonomy = sanitize_text_field($_POST['taxonomy']); |
| 458 |
$blockRaw = sanitize_text_field($_POST['blockName']); |
| 459 |
$blockName = str_replace('_','/', $blockRaw); |
| 460 |
|
| 461 |
if( $taxtype ) { |
| 462 |
$post = get_post($postId); |
| 463 |
if (has_blocks($post->post_content)) { |
| 464 |
$blocks = parse_blocks($post->post_content); |
| 465 |
$this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy); |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
/** |
| 472 |
* Pagination of the Blocks |
| 473 |
* |
| 474 |
* @since v.1.0.0 |
| 475 |
* @return STRING |
| 476 |
*/ |
| 477 |
public function ultp_pagination_callback() { |
| 478 |
if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) { |
| 479 |
return ; |
| 480 |
} |
| 481 |
|
| 482 |
$paged = sanitize_text_field($_POST['paged']); |
| 483 |
$blockId = sanitize_text_field($_POST['blockId']); |
| 484 |
$postId = sanitize_text_field($_POST['postId']); |
| 485 |
$blockRaw = sanitize_text_field($_POST['blockName']); |
| 486 |
$blockName = str_replace('_','/', $blockRaw); |
| 487 |
|
| 488 |
if($paged) { |
| 489 |
$post = get_post($postId); |
| 490 |
if (has_blocks($post->post_content)) { |
| 491 |
$blocks = parse_blocks($post->post_content); |
| 492 |
$this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName); |
| 493 |
} |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
/** |
| 499 |
* Blocks Content Start |
| 500 |
* |
| 501 |
* @since v.1.0.0 |
| 502 |
* @return STRING |
| 503 |
*/ |
| 504 |
public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) { |
| 505 |
foreach ($blocks as $key => $value) { |
| 506 |
if($blockName == $value['blockName']) { |
| 507 |
if($value['attrs']['blockId'] == $blockId) { |
| 508 |
$attr = $this->all_blocks[$blockRaw]->get_attributes(true); |
| 509 |
$attr['paged'] = $paged; |
| 510 |
$attr = array_merge($attr, $value['attrs']); |
| 511 |
echo $this->all_blocks[$blockRaw]->content($attr, true); |
| 512 |
die(); |
| 513 |
} |
| 514 |
} |
| 515 |
if(!empty($value['innerBlocks'])){ |
| 516 |
$this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName); |
| 517 |
} |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
} |