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

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