PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.6.0
Post Grid Gutenberg Blocks – PostX v2.6.0
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.0, at classes/Initialization.php

652 lines 24.2 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 ));
245
246 wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
247 }
248
249
250 /**
251 * Fire When Plugin First Install
252 *
253 * @since v.1.0.0
254 * @return NULL
255 */
256 public function install_hook() {
257 if (!get_option('ultp_options')) {
258 ultimate_post()->init_set_data();
259 }
260 }
261
262
263 /**
264 * Redirect After Active Plugin
265 *
266 * @since v.1.0.0
267 * @param STRING | Plugin Path
268 * @return NULL
269 */
270 public function activation_redirect($plugin) {
271 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
272 exit(wp_redirect(admin_url('admin.php?page=ultp-settings#tutorials')));
273 }
274 }
275
276
277 /**
278 * Require Blocks
279 *
280 * @since v.1.0.0
281 * @return NULL
282 */
283 public function blocks() {
284 global $unique_ID;
285 $setting = ultimate_post()->get_setting();
286 if (!isset($setting['post_list_1']) || $setting['post_list_1'] == 'yes') {
287 require_once ULTP_PATH.'blocks/Post_List_1.php';
288 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
289 }
290 if (!isset($setting['post_list_2']) || $setting['post_list_2'] == 'yes') {
291 require_once ULTP_PATH.'blocks/Post_List_2.php';
292 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
293 }
294 if (!isset($setting['post_list_3']) || $setting['post_list_3'] == 'yes') {
295 require_once ULTP_PATH.'blocks/Post_List_3.php';
296 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
297 }
298 if (!isset($setting['post_list_4']) || $setting['post_list_4'] == 'yes') {
299 require_once ULTP_PATH.'blocks/Post_List_4.php';
300 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
301 }
302 if (!isset($setting['post_grid_1']) || $setting['post_grid_1'] == 'yes') {
303 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
304 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
305 }
306 if (!isset($setting['post_grid_2']) || $setting['post_grid_2'] == 'yes') {
307 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
308 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
309 }
310 if (!isset($setting['post_grid_3']) || $setting['post_grid_3'] == 'yes') {
311 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
312 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
313 }
314 if (!isset($setting['post_grid_4']) || $setting['post_grid_4'] == 'yes') {
315 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
316 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
317 }
318 if (!isset($setting['post_grid_5']) || $setting['post_grid_5'] == 'yes') {
319 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
320 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
321 }
322 if (!isset($setting['post_grid_6']) || $setting['post_grid_6'] == 'yes') {
323 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
324 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
325 }
326 if (!isset($setting['post_grid_7']) || $setting['post_grid_7'] == 'yes') {
327 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
328 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
329 }
330 if (!isset($setting['post_slider_1']) || $setting['post_slider_1'] == 'yes') {
331 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
332 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
333 }
334 if (!isset($setting['post_module_1']) || $setting['post_module_1'] == 'yes') {
335 require_once ULTP_PATH.'blocks/Post_Module_1.php';
336 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
337 }
338 if (!isset($setting['post_module_2']) || $setting['post_module_2'] == 'yes') {
339 require_once ULTP_PATH.'blocks/Post_Module_2.php';
340 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
341 }
342 if (!isset($setting['heading']) || $setting['heading'] == 'yes') {
343 require_once ULTP_PATH.'blocks/Heading.php';
344 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
345 }
346 if (!isset($setting['image']) || $setting['image'] == 'yes') {
347 require_once ULTP_PATH.'blocks/Image.php';
348 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
349 }
350 if (!isset($setting['taxonomy']) || $setting['taxonomy'] == 'yes') {
351 require_once ULTP_PATH.'blocks/Taxonomy.php';
352 $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
353 }
354
355 if (!isset($setting['news_ticker']) || $setting['news_ticker'] == 'yes') {
356 require_once ULTP_PATH.'blocks/News_Ticker.php';
357 $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\News_Ticker();
358 }
359
360 if (!isset($setting['archive_title']) || $setting['archive_title'] == 'yes') {
361 require_once ULTP_PATH.'blocks/Archive_Title.php';
362 $this->all_blocks['ultimate-post_archive-title'] = new \ULTP\blocks\Archive_Title();
363 }
364 }
365
366
367 /**
368 * Necessary Requires Class
369 *
370 * @since v.1.0.0
371 * @return NULL
372 */
373 public function requires() {
374 require_once ULTP_PATH.'classes/Notice.php';
375 require_once ULTP_PATH.'classes/Styles.php';
376 require_once ULTP_PATH.'classes/Options.php';
377 require_once ULTP_PATH.'classes/REST_API.php';
378 require_once ULTP_PATH.'classes/Caches.php';
379 new \ULTP\REST_API();
380 new \ULTP\Caches();
381 new \ULTP\Options();
382 new \ULTP\Styles();
383 new \ULTP\Notice();
384
385 require_once ULTP_PATH.'classes/Deactive.php';
386 new \ULTP\Deactive();
387 }
388
389
390 /**
391 * Block Categories Initialization
392 *
393 * @since v.1.0.0
394 * @param $categories(ARRAY) | $post (ARRAY)
395 * @return NULL
396 */
397 public function register_category_callback( $categories, $post ) {
398 return array_merge(
399 array(
400 array(
401 'slug' => 'ultimate-post',
402 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' )
403 )
404 ), $categories
405 );
406 }
407
408
409 /**
410 * Post View Counter for Every Post
411 *
412 * @since v.1.0.0
413 * @param NUMBER | Post ID
414 * @return NULL
415 */
416 public function popular_posts_tracker_callback($post_id) {
417 if (!is_single()){ return; }
418 global $post;
419 $post_id = $post->ID;
420 $isEnable = apply_filters('ultp_view_cookies', true);
421 // add_filter( 'ultp_view_cookies', '__return_true' );
422 if ($post_id && $isEnable) {
423 $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false;
424 if (!$has_cookie) {
425 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
426 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
427 setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
428 }
429 }
430 }
431
432
433 /**
434 * Set Image Size
435 *
436 * @since v.1.0.0
437 * @return NULL
438 */
439 public function add_image_size() {
440 $size_disable = ultimate_post()->get_setting('disable_image_size');
441 if ($size_disable != 'yes') {
442 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
443 add_image_size('ultp_layout_landscape', 870, 570, true);
444 add_image_size('ultp_layout_portrait', 600, 900, true);
445 add_image_size('ultp_layout_square', 600, 600, true);
446 }
447 }
448
449
450 /**
451 * Include Addons Directory
452 *
453 * @since v.1.0.0
454 * @return NULL
455 */
456 public function include_addons() {
457 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
458 if (count($addons_dir) > 0) {
459 foreach( $addons_dir as $key => $value ) {
460 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
461 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
462 if ( file_exists($file_name) ) {
463 include_once $file_name;
464 }
465 }
466 }
467 }
468
469
470 /**
471 * Addon Callback
472 *
473 * @since v.1.0.0
474 * @return STRING
475 */
476 public function ultp_addon_callback() {
477 if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
478 return ;
479 }
480 $addon_name = sanitize_text_field($_POST['addon']);
481 $addon_value = sanitize_text_field($_POST['value']);
482 if ($addon_name && current_user_can('administrator')) {
483 $addon_data = ultimate_post()->get_setting();
484 $addon_data[$addon_name] = $addon_value;
485 $GLOBALS['ultp_settings'][$addon_name] = $addon_value;
486 update_option('ultp_options', $addon_data);
487 }
488 }
489
490
491 /**
492 * Next Preview Callback of the Blocks
493 *
494 * @since v.1.0.0
495 * @return STRING
496 */
497 public function ultp_next_prev_callback() {
498 if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
499 return ;
500 }
501
502 $paged = sanitize_text_field($_POST['paged']);
503 $blockId = sanitize_text_field($_POST['blockId']);
504 $postId = sanitize_text_field($_POST['postId']);
505 $blockRaw = sanitize_text_field($_POST['blockName']);
506 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
507
508 $blockName = str_replace('_','/', $blockRaw);
509
510 if( $paged && $blockId && $postId && $blockName ) {
511 $post = get_post($postId);
512 if (has_blocks($post->post_content)) {
513 $blocks = parse_blocks($post->post_content);
514 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
515 }
516 }
517 }
518
519
520 /**
521 * Filter Callback of the Blocks
522 *
523 * @since v.1.0.0
524 * @return STRING
525 */
526 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
527 foreach ($blocks as $key => $value) {
528 if($blockName == $value['blockName']) {
529 if($value['attrs']['blockId'] == $blockId) {
530 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
531 if($taxonomy) {
532 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
533 $value['attrs']['queryTax'] = $taxtype;
534 }
535 if(isset($value['attrs']['queryNumber'])){
536 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
537 }
538 $attr = array_merge($attr, $value['attrs']);
539 echo $this->all_blocks[$blockRaw]->content($attr, true);
540 die();
541 }
542 }
543 if(!empty($value['innerBlocks'])){
544 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
545 }
546 }
547 }
548
549
550 /**
551 * Filter Callback of the Blocks
552 *
553 * @since v.1.0.0
554 * @return STRING
555 */
556 public function ultp_filter_callback() {
557 if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
558 return ;
559 }
560
561 $taxtype = sanitize_text_field($_POST['taxtype']);
562 if( $taxtype ) {
563 $blockId = sanitize_text_field($_POST['blockId']);
564 $postId = sanitize_text_field($_POST['postId']);
565 $taxonomy = sanitize_text_field($_POST['taxonomy']);
566 $blockRaw = sanitize_text_field($_POST['blockName']);
567 $blockName = str_replace('_','/', $blockRaw);
568 $post = get_post($postId);
569 if (has_blocks($post->post_content)) {
570 $blocks = parse_blocks($post->post_content);
571 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
572 }
573 }
574 }
575
576
577 /**
578 * Pagination of the Blocks
579 *
580 * @since v.1.0.0
581 * @return STRING
582 */
583 public function ultp_pagination_callback() {
584 if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local) {
585 return ;
586 }
587
588 $paged = sanitize_text_field($_POST['paged']);
589 if($paged) {
590 $blockId = sanitize_text_field($_POST['blockId']);
591 $postId = sanitize_text_field($_POST['postId']);
592 $blockRaw = sanitize_text_field($_POST['blockName']);
593 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
594 $blockName = str_replace('_','/', $blockRaw);
595 $post = get_post($postId);
596 if (has_blocks($post->post_content)) {
597 $blocks = parse_blocks($post->post_content);
598 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
599 }
600 }
601 }
602
603
604 /**
605 * Blocks Content Start
606 *
607 * @since v.1.0.0
608 * @return STRING
609 */
610 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId) {
611 foreach ($blocks as $key => $value) {
612 if($blockName == $value['blockName']) {
613 if($value['attrs']['blockId'] == $blockId) {
614 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
615 $value['attrs']['paged'] = $paged;
616 if ($builder) {
617 $value['attrs']['builder'] = $builder;
618 }
619 if ($postId) {
620 $attr['current_post'] = $postId;
621 }
622 $attr = array_merge($attr, $value['attrs']);
623 echo $this->all_blocks[$blockRaw]->content($attr, true);
624 die();
625 }
626 }
627 if(!empty($value['innerBlocks'])){
628 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
629 }
630 }
631 }
632
633 /**
634 * Save Settings of Option Panel
635 *
636 * @since v.2.6.0
637 * @return NULL
638 */
639 public function save_plugin_settings_data() {
640 if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
641 return ;
642 }
643 $data = ultimate_post()->recursive_sanitize_text_field($_POST['data']);
644 if (count($data) > 0) {
645 foreach ($data as $key => $val) {
646 ultimate_post()->set_setting($key, $val);
647 }
648 }
649 wp_send_json_success(__('Settings Data Saved...', 'ultimate-post'));
650 }
651
652 }