PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.6.1
Post Grid Gutenberg Blocks – PostX v2.6.1
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Initialization.php

Initialization.php in Post Grid Gutenberg Blocks – PostX 2.6.1, at classes/Initialization.php

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