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

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