PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.3
Post Grid Gutenberg Blocks – PostX v4.1.3
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 4.1.3, at classes/Initialization.php

1,324 lines 61.7 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
26 $this->compatibility_check();
27 $this->requires(); // Include Necessary Files
28 $this->blocks(); // Include Blocks
29 $this->include_addons(); // Include Addons
30
31 add_action( 'wp', array( $this, 'popular_posts_tracker_callback' ) );
32 add_filter( 'block_categories_all', array( $this, 'register_category_callback' ), 999999999, 2 ); // Block Category Register
33 add_action( 'after_setup_theme', array( $this, 'add_image_size' ) );
34
35 add_action( 'enqueue_block_editor_assets', array( $this, 'register_scripts_back_callback' ) ); // Only editor
36 add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts_option_panel_callback' ) ); // Option Panel
37 add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts_front_callback' ) ); // Both frontend
38 register_activation_hook( ULTP_PATH.'ultimate-post.php', array( $this, 'install_hook' ) );
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_adv_filter', array( $this, 'ultp_adv_filter_callback' ) );
45 add_action( 'wp_ajax_nopriv_ultp_adv_filter', array( $this, 'ultp_adv_filter_callback' ) );
46 add_action( 'wp_ajax_ultp_pagination', array( $this, 'ultp_pagination_callback' )); // Page Number AJAX Call
47 add_action( 'wp_ajax_nopriv_ultp_pagination',array( $this, 'ultp_pagination_callback' )); // Page Number AJAX Call Logout User
48 add_action( 'wp_ajax_ultp_share_count', array( $this, 'ultp_shareCount_callback' )); // share Count save
49
50 add_action('admin_init', array($this, 'admin_init_functionalities'));
51 add_action( 'after_switch_theme', array($this, 'wpxpo_swithch_thememe'));
52
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 // add_action( 'wp_ajax_ultp_getsearch_result', array($this, 'ultp_get_search_result')); // Search Result Showing
58
59 add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ) ); // add body class in editor
60 add_filter( 'body_class', array( $this, 'add_body_class') ); // add body class in front end
61
62 add_filter( 'wp_kses_allowed_html', [ $this, 'ultp_handle_allowed_html' ], 99, 2 ); // support for svg icon used in list, row, icon block
63 add_filter( 'safe_style_css', [ $this, 'ultp_handle_safe_style_css' ] ); // support for css used in svg icon
64 }
65
66 /**
67 * Add support for css to use svg
68 *
69 * @since 4.0.0
70 * @return styles
71 */
72 public function ultp_handle_safe_style_css( $styles ) {
73 if( !is_multisite() && !current_user_can('edit_posts') ) {
74 return $styles;
75 }
76 return array_merge( $styles, array(
77 'opacity',
78 // for SVG gradients.
79 // 'stop-opacity',
80 // 'stop-color',
81 ) );
82 }
83
84 /**
85 * Add support for html tag to use svg
86 *
87 * @since 4.0.0
88 * @return supported_tags
89 */
90 public function ultp_handle_allowed_html ($tags, $context) {
91 if ( 'post' !== $context && !is_multisite() && !current_user_can('edit_posts') ) {
92 return $tags;
93 }
94 if ( ! isset( $tags['svg'] ) ) {
95 $tags['svg'] = array_merge(
96 [
97 'xmlns' => true,
98 // 'xmlns:xlink' => true,
99 // 'xlink:href' => true,
100 // 'xml:id' => true,
101 // 'xlink:title' => true,
102 // 'xml:space' => true,
103 'viewbox' => true,
104 'enable-background' => true,
105 'version' => true,
106 'preserveaspectratio' => true,
107 'fill' => true,
108 ]
109 );
110 }
111 if ( ! isset( $tags['path'] ) ) {
112 $tags['path'] = [
113 'd' => true,
114 'stroke' => true,
115 'stroke-miterlimit' => true,
116 'data-original' => true,
117 'class' => true,
118 'transform' => true,
119 'style' => true,
120 'opacity' => true,
121 'fill' => true
122 ];
123 }
124 if ( ! isset( $tags['g'] ) ) {
125 $tags['g'] = [
126 'transform' => true,
127 'clip-path' => true,
128 ];
129 }
130 if ( ! isset( $tags['clippath'] ) ) {
131 $tags['clippath'] = [];
132 }
133 if ( ! isset( $tags['defs'] ) ) {
134 $tags['defs'] = [
135 ];
136 }
137 if ( ! isset( $tags['rect'] ) ) {
138 $tags['rect'] = [
139 'rx' => true,
140 'height' => true,
141 'width' => true,
142 'transform' => true,
143 'x' => true,
144 'fill' => true,
145 ];
146 }
147 if ( ! isset( $tags['circle'] ) ) {
148 $tags['circle'] = [
149 'cx' => true,
150 'cy' => true,
151 'transform' => true,
152 'r' => true,
153 ];
154 }
155 if ( ! isset( $tags['polygon'] ) ) {
156 $tags['polygon'] = [
157 'points' => true,
158 ];
159 }
160 if ( ! isset( $tags['lineargradient'] ) ) {
161 $tags['lineargradient'] = [
162 'gradienttransform' => true,
163 'id' => true,
164 ];
165 }
166 if ( ! isset( $tags['stop'] ) ) {
167 $tags['stop'] = [
168 'offset' => true,
169 'stop-color' => true,
170 'style' => true,
171 'stop-opacity' => true,
172 ];
173 }
174 return $tags;
175 }
176
177 /**
178 * Add Admin Body_class
179 *
180 * @since v.3.1.6
181 * @return NULL
182 */
183 public function add_admin_body_class ($classes) {
184 $classes .= " postx-admin-page ";
185 return $classes;
186 }
187 /**
188 * Theme Switch Callback
189 *
190 * @since v.3.1.6
191 * @return NULL
192 */
193 public function add_body_class ($classes) {
194 $classes[] = "postx-page";
195 return $classes;
196 }
197
198 /**
199 * Theme Switch Callback
200 *
201 * @since v.1.1.0
202 * @return NULL
203 */
204 public function wpxpo_swithch_thememe () {
205 $this->check_theme_compatibility();
206 }
207 /**
208 * Theme Switch Callback
209 *
210 * @since v.1.1.0
211 * @return NULL
212 */
213 public function admin_init_functionalities () {
214 $this->handle_wizard_redirect(); // redirect to either home or wizard page
215 $this->check_theme_compatibility();
216 }
217
218 /**
219 * Theme Switch Callback
220 *
221 * @since v.1.1.0
222 * @return NULL
223 */
224 public function handle_wizard_redirect () {
225 if ( !ultimate_post()->get_transient_without_cache('ultp_activation_redirect') ) {
226 return ;
227 }
228 if ( wp_doing_ajax() ) {
229 return;
230 }
231 ultimate_post()->set_transient_without_cache('ultp_activation_redirect', true, 1);
232
233 if ( is_network_admin() || isset($_GET['activate-multi']) ) {
234 return ;
235 }
236
237 if ( ultimate_post()->get_setting('init_setup') != 'yes' ) {
238 ultimate_post()->set_setting('init_setup', 'yes');
239 exit(wp_safe_redirect(admin_url('admin.php?page=ultp-initial-setup-wizard'))); //phpcs:ignore
240 }
241 }
242
243
244 /**
245 * Theme Compatibility Action
246 *
247 * @since v.1.1.0
248 * @return NULL
249 */
250 public function check_theme_compatibility() {
251 $licence = apply_filters( 'ultp_theme_integration' , FALSE );
252 $theme = get_transient( 'ulpt_theme_enable' );
253
254 if ( $licence ) {
255 if ( $theme != 'integration' ) {
256 $themes = wp_get_theme();
257 $api_params = array(
258 'wpxpo_theme_action' => 'theme_license',
259 'slug' => $themes->get('TextDomain'),
260 'author' => $themes->get('Author'),
261 'item_id' => 181,
262 'url' => home_url()
263 );
264
265 $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
266
267 if ( !is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) {
268 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
269 if ( isset($license_data->license) ) {
270 if ( $license_data->license == 'valid' ) {
271 set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time
272 }
273 }
274 }
275 }
276 } else {
277 if ( $theme == 'integration' ) {
278 delete_transient( 'ulpt_theme_enable' );
279 }
280 }
281 }
282
283
284 /**
285 * Check Compatibility
286 *
287 * @since v.1.0.0
288 * @return NULL
289 */
290 public function compatibility_check() {
291 require_once ULTP_PATH.'classes/Compatibility.php';
292 new \ULTP\Compatibility();
293 }
294
295
296 /**
297 * Option Panel CSS and JS Scripts
298 *
299 * @since v.1.0.0
300 * @return NULL
301 */
302 public function register_scripts_option_panel_callback() {
303 $is_active = ultimate_post()->is_lc_active();
304 $license_key = get_option( 'edd_ultp_license_key' );
305 $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // @codingStandardsIgnoreLine
306
307 // Custom Font Support Added
308 $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
309 $custom_fonts = array();
310 if ( $font_settings == 'true' ) {
311 wp_enqueue_media();
312 $args = array(
313 'post_type' => 'ultp_custom_font',
314 'post_status' => 'publish',
315 'numberposts' => 333,
316 'order' => 'ASC'
317 );
318 $posts = get_posts( $args );
319 if ( $posts ) {
320 foreach( $posts as $post ) {
321 setup_postdata( $post );
322 $font = get_post_meta($post->ID , '__font_settings', true);
323
324 if ( $font ) {
325 array_push( $custom_fonts, array(
326 'title' => $post->post_title,
327 'font' => $font
328 ));
329 }
330 }
331 wp_reset_postdata();
332 }
333 }
334
335 wp_enqueue_style( 'wp-color-picker' );
336 wp_enqueue_script( 'wp-color-picker' );
337 wp_enqueue_script( 'ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true );
338 wp_enqueue_style( 'ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER );
339
340 wp_localize_script( 'ultp-option-script', 'ultp_option_panel', array(
341 'url' => ULTP_URL,
342 'version' => ULTP_VER,
343 'active' => $is_active,
344 'security' => wp_create_nonce('ultp-nonce'),
345 'ajax' => admin_url('admin-ajax.php'),
346 'license' => $license_key,
347 'settings' => ultimate_post()->get_setting(),
348 'addons' => ultimate_post()->all_addons(),
349 'premium_link' => ultimate_post()->get_premium_link(),
350 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
351 'custom_fonts' => $custom_fonts,
352 'addons_settings' => apply_filters('ultp_settings', []),
353 'post_type' => get_post_type(),
354 'saved_template_url' => admin_url('admin.php?page=ultp-settings#saved-templates'),
355 ));
356
357 /* === Installation Wizard === */
358 if ( $_page == 'ultp-initial-setup-wizard' ) {
359 wp_enqueue_script( 'ultp-initial-setup-script', ULTP_URL.'assets/js/ultp_initial_setup_min.js', array('wp-i18n', 'wp-api-fetch', 'wp-api-request'), ULTP_VER, true );
360 wp_set_script_translations( 'ultp-initial-setup-script', 'ultimate-post', ULTP_PATH . 'languages/' );
361 }
362
363 /* === Builder And Setting Pannel === */
364 if ( get_post_type(get_the_ID()) == 'ultp_builder' ) {
365 wp_enqueue_script( 'ultp-conditions-script', ULTP_URL.'addons/builder/assets/js/conditions.js', array('wp-i18n', 'wp-api-fetch','wp-components','wp-i18n','wp-blocks'), ULTP_VER, true );
366 wp_localize_script( 'ultp-conditions-script', 'ultp_condition', array(
367 'url' => ULTP_URL,
368 'active' => $is_active,
369 'premium_link' => ultimate_post()->get_premium_link(),
370 'license' => $license_key,
371 'builder_url' => admin_url('admin.php?page=ultp-settings#builder'),
372 'affiliate_id' => apply_filters( 'ultp_affiliate_id', FALSE )
373 ) );
374 wp_set_script_translations( 'ultp-conditions-script', 'ultimate-post', ULTP_PATH . 'languages/' );
375 }
376
377 /* === Dashboard === */
378 $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
379 if ($_page == 'ultp-settings') {
380 wp_enqueue_script('ultp-dashboard-script', ULTP_URL.'assets/js/ultp_dashboard_min.js', array('wp-i18n', 'wp-api-fetch', 'wp-api-request', 'wp-components','wp-blocks'), ULTP_VER, true);
381 wp_localize_script('ultp-dashboard-script', 'ultp_dashboard_pannel', array(
382 'ajax' => admin_url('admin-ajax.php'),
383 'security' => wp_create_nonce('ultp-nonce'),
384 'url' => ULTP_URL,
385 'active' => $is_active,
386 'license' => $license_key,
387 'settings' => ultimate_post()->get_setting(),
388 'addons' => ultimate_post()->all_addons(),
389 'addons_settings' => apply_filters('ultp_settings', []),
390 'premium_link' => ultimate_post()->get_premium_link(),
391 'builder_url' => admin_url('admin.php?page=ultp-settings#builder'),
392 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
393 'version' => ULTP_VER,
394 'setup_wizard_link' => admin_url('admin.php?page=ultp-initial-setup-wizard'),
395 'helloBar' => get_transient('ultp_helloBar'.ULTP_HELLOBAR),
396 'status' => get_option( 'edd_ultp_license_status' ),
397 'expire' => get_option( 'edd_ultp_license_expire' ),
398 'is_free' => !ultimate_post()->is_lc_active(),
399 'is_pro' => (ultimate_post()->is_lc_active() && get_option('edd_ultp_license_expire') != 'lifetime'),
400 'user_email' => wp_get_current_user()->user_email,
401 'home_url' => home_url(),
402 'generalDiscount' => get_transient('ultp_generalDiscount'),
403 ) );
404 wp_set_script_translations( 'ultp-dashboard-script', 'ultimate-post', ULTP_PATH . 'languages/' );
405 }
406
407 }
408
409
410 /**
411 * Only Frontend CSS and JS Scripts
412 *
413 * @since v.1.0.0
414 * @return NULL
415 */
416 public function register_scripts_front_callback() {
417 $call_common = false;
418 if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { // @codingStandardsIgnoreLine
419 $call_common = true;
420 ultimate_post()->register_scripts_common();
421 } else if ( 'yes' == get_post_meta(ultimate_post()->get_ID(), '_ultp_active', true) ) {
422 $call_common = true;
423 ultimate_post()->register_scripts_common();
424 } else if ( ultimate_post()->is_builder() ) {
425 $call_common = true;
426 ultimate_post()->register_scripts_common();
427 } else if ( apply_filters('postx_common_script', false) ) {
428 $call_common = true;
429 ultimate_post()->register_scripts_common();
430 } else if ( isset($_GET['et_fb']) ) { // @codingStandardsIgnoreLine
431 $call_common = true;
432 ultimate_post()->register_scripts_common();
433 }
434
435 // For WidgetWidget
436 $has_block = false;
437 $widget_blocks = array();
438 global $wp_registered_sidebars, $sidebars_widgets;
439 foreach ( $wp_registered_sidebars as $key => $value ) {
440 if ( is_active_sidebar($key) ) {
441 foreach ( $sidebars_widgets[$key] as $val ) {
442 if ( strpos($val, 'block-') !== false ) {
443 if ( empty($widget_blocks) ) {
444 $widget_blocks = get_option( 'widget_block' );
445 }
446 foreach ( (array) $widget_blocks as $block ) {
447 if ( isset( $block['content'] ) && strpos($block['content'], 'wp:ultimate-post') !== false ) {
448 $has_block = true;
449 break;
450 }
451 }
452 if ( $has_block ) {
453 break;
454 }
455 }
456 }
457 }
458 }
459 if ( $has_block ) {
460 if ( !$call_common ) {
461 ultimate_post()->register_scripts_common();
462 }
463 $css = get_option('ultp-widget', true);
464 if ( $css ) {
465 wp_register_style( 'ultp-post-widget', false );
466 wp_enqueue_style( 'ultp-post-widget' );
467 wp_add_inline_style( 'ultp-post-widget', $css);
468 }
469 }
470 }
471
472
473 /**
474 * Only Backend CSS and JS Scripts
475 *
476 * @since v.1.0.0
477 * @return NULL
478 */
479 public function register_scripts_back_callback() {
480 ultimate_post()->register_scripts_common();
481 global $pagenow;
482 $depends = 'wp-editor';
483 if ( $pagenow === 'widgets.php' ) {
484 $depends = 'wp-edit-widgets';
485 }
486 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 );
487 wp_enqueue_style( 'ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER );
488 if ( is_rtl() ) {
489 wp_enqueue_style( 'ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER );
490 }
491 $is_active = ultimate_post()->is_lc_active();
492 $post_type = get_post_type();
493 wp_localize_script( 'ultp-blocks-editor-script', 'ultp_data', array(
494 'url' => ULTP_URL,
495 'ajax' => admin_url('admin-ajax.php'),
496 'security' => wp_create_nonce('ultp-nonce'),
497 'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'),
498 'upload' => wp_upload_dir()['basedir'] . '/ultp',
499 'premium_link' => ultimate_post()->get_premium_link(),
500 'license' => $is_active ? get_option('edd_ultp_license_key') : '',
501 'active' => $is_active,
502 'archive' => ultimate_post()->is_archive_builder(),
503 'settings' => ultimate_post()->get_setting(),
504 'post_type' => $post_type == 'premade' ? 'ultp_builder' : $post_type, // premade used for ultp.wpxpo.com
505 'date_format' => get_option('date_format'),
506 'time_format' => get_option('time_format'),
507 'blog' => get_current_blog_id(),
508 'archive_child' => ultimate_post()->is_archive_child_builder(),
509 'affiliate_id' => apply_filters( 'ultp_affiliate_id', FALSE ),
510 'category_url' =>admin_url( 'edit-tags.php?taxonomy=category' ),
511 'disable_image_size' => ultimate_post()->get_setting('disable_image_size'),
512 'dark_logo' => get_option('ultp_site_dark_logo') ? get_option('ultp_site_dark_logo') : false,
513 'builder_url' => admin_url('admin.php?page=ultp-settings#builder')
514 ));
515 wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
516 }
517
518
519 /**
520 * Fire When Plugin First Install
521 *
522 * @since v.1.0.0
523 * @return NULL
524 */
525 public function install_hook() {
526 $data = get_option( 'ultp_options', array() );
527 $currentDate = new \DateTime();
528 $currentDate->setTime(0, 0, 0, 0);
529 // if ( empty( $data ) ) {
530 $init_data = array(
531 'css_save_as' => 'wp_head',
532 'preloader_style' => 'style1',
533 'preloader_color' => '#037fff',
534 'container_width' => '1140',
535 'hide_import_btn' => '',
536 'disable_image_size'=> '',
537 'disable_view_cookies' => '',
538 'disable_google_font' => '',
539 'ultp_templates' => 'true',
540 'ultp_elementor' => 'true',
541 'ultp_table_of_content'=> 'true',
542 'ultp_builder' => 'true',
543 'ultp_custom_font' => 'true',
544 'ultp_chatgpt' => 'true',
545 'post_grid_1' => 'yes',
546 'post_grid_2' => 'yes',
547 'post_grid_3' => 'yes',
548 'post_grid_4' => 'yes',
549 'post_grid_5' => 'yes',
550 'post_grid_6' => 'yes',
551 'post_grid_7' => 'yes',
552 'post_list_1' => 'yes',
553 'post_list_2' => 'yes',
554 'post_list_3' => 'yes',
555 'post_list_4' => 'yes',
556 'post_module_1' => 'yes',
557 'post_module_2' => 'yes',
558 'post_slider_1' => 'yes',
559 'post_slider_2' => 'yes',
560 'heading' => 'yes',
561 'image' => 'yes',
562 'taxonomy' => 'yes',
563 'wrapper' => 'yes',
564 'news_ticker' => 'yes',
565 'builder_advance_post_meta' => 'yes',
566 'builder_archive_title' => 'yes',
567 'builder_author_box' => 'yes',
568 'builder_post_next_previous'=> 'yes',
569 'builder_post_author_meta' => 'yes',
570 'builder_post_breadcrumb' => 'yes',
571 'builder_post_category' => 'yes',
572 'builder_post_comment_count'=> 'yes',
573 'builder_post_comments' => 'yes',
574 'builder_post_content' => 'yes',
575 'builder_post_date_meta' => 'yes',
576 'builder_post_excerpt' => 'yes',
577 'builder_post_featured_image'=> 'yes',
578 'builder_post_reading_time' => 'yes',
579 'builder_post_social_share' => 'yes',
580 'builder_post_tag' => 'yes',
581 'builder_post_title' => 'yes',
582 'builder_post_view_count' => 'yes',
583 'save_version' => wp_rand(1, 1000),
584 'activated_date' => $currentDate->getTimestamp()
585 );
586 if ( empty( $data ) ) {
587 update_option( 'ultp_options', $init_data );
588 $GLOBALS['ultp_settings'] = $init_data;
589 } else {
590 foreach ( $init_data as $key => $single ) {
591 if ( ! isset( $data[$key] ) ) {
592 $data[$key] = $single;
593 }
594 }
595 update_option( 'ultp_options', $data );
596 $GLOBALS['ultp_settings'] = $data;
597 }
598 // }
599 if (!get_transient( 'wpxpo_installation_date' )) {
600 set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
601 }
602
603 if ( !ultimate_post()->get_transient_without_cache('ultp_activation_redirect') ) { // set transient to show wizard
604 ultimate_post()->set_transient_without_cache('ultp_activation_redirect', true, MINUTE_IN_SECONDS);
605 }
606 }
607
608
609 /**
610 * Require Blocks
611 *
612 * @since v.1.0.0
613 * @return NULL
614 */
615 public function blocks() {
616 global $unique_ID;
617 $setting = ultimate_post()->get_setting();
618 require_once ULTP_PATH.'blocks/Post_List_1.php';
619 require_once ULTP_PATH.'blocks/Post_List_2.php';
620 require_once ULTP_PATH.'blocks/Post_List_3.php';
621 require_once ULTP_PATH.'blocks/Post_List_4.php';
622 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
623 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
624 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
625 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
626 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
627 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
628 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
629 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
630 require_once ULTP_PATH.'blocks/Post_Slider_2.php';
631 require_once ULTP_PATH.'blocks/Post_Module_1.php';
632 require_once ULTP_PATH.'blocks/Post_Module_2.php';
633 require_once ULTP_PATH.'blocks/Heading.php';
634 require_once ULTP_PATH.'blocks/Image.php';
635 require_once ULTP_PATH.'blocks/Taxonomy.php';
636 require_once ULTP_PATH.'blocks/News_Ticker.php';
637 require_once ULTP_PATH.'blocks/Advanced_Search.php';
638 require_once ULTP_PATH.'blocks/Advanced_Filter.php';
639 require_once ULTP_PATH.'blocks/Dark_Light.php';
640
641 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
642 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
643 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
644 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
645 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
646 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
647 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
648 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
649 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
650 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
651 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
652 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
653 $this->all_blocks['ultimate-post_post-slider-2'] = new \ULTP\blocks\Post_Slider_2();
654 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
655 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
656 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
657 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
658 $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
659 $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\News_Ticker();
660 $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\Advanced_Search();
661 $this->all_blocks['ultimate-post_advanced-filter'] = new \ULTP\blocks\Advanced_Filter();
662 $this->all_blocks['ultimate-post_dark-light'] = new \ULTP\blocks\Dark_Light();
663
664 if ( ultimate_post()->get_setting('ultp_builder') == 'true' ) {
665 require_once ULTP_PATH.'addons/builder/blocks/Archive_Title.php';
666 require_once ULTP_PATH.'addons/builder/blocks/Post_Title.php';
667 require_once ULTP_PATH.'addons/builder/blocks/Post_Content.php';
668 require_once ULTP_PATH.'addons/builder/blocks/Post_Featured_Image.php';
669 require_once ULTP_PATH.'addons/builder/blocks/Post_Breadcrumb.php';
670 require_once ULTP_PATH.'addons/builder/blocks/Post_Tag.php';
671 require_once ULTP_PATH.'addons/builder/blocks/Post_Category.php';
672 require_once ULTP_PATH.'addons/builder/blocks/Next_Previous.php';
673 require_once ULTP_PATH.'addons/builder/blocks/Post_Excerpt.php';
674 require_once ULTP_PATH.'addons/builder/blocks/Author_Box.php';
675 require_once ULTP_PATH.'addons/builder/blocks/Post_Comments.php';
676 require_once ULTP_PATH.'addons/builder/blocks/Post_View_Count.php';
677 require_once ULTP_PATH.'addons/builder/blocks/Post_Reading_Time.php';
678 require_once ULTP_PATH.'addons/builder/blocks/Post_Comment_Count.php';
679 require_once ULTP_PATH.'addons/builder/blocks/Post_Author_Meta.php';
680 require_once ULTP_PATH.'addons/builder/blocks/Post_Date_Meta.php';
681 require_once ULTP_PATH.'addons/builder/blocks/Post_Social_Share.php';
682 require_once ULTP_PATH.'addons/builder/blocks/Advance_Post_Meta.php';
683
684 new \ULTP\blocks\Archive_Title();
685 new \ULTP\blocks\Post_Title();
686 new \ULTP\blocks\Post_Content();
687 new \ULTP\blocks\Post_Featured_Image();
688 new \ULTP\blocks\Post_Breadcrumb();
689 new \ULTP\blocks\Post_Tag();
690 new \ULTP\blocks\Post_Category();
691 new \ULTP\blocks\Next_Previous();
692 new \ULTP\blocks\Post_Excerpt();
693 new \ULTP\blocks\Author_Box();
694 new \ULTP\blocks\Post_Comments();
695 new \ULTP\blocks\Post_View_Count();
696 new \ULTP\blocks\Post_Reading_Time();
697 new \ULTP\blocks\Post_Comment_Count();
698 new \ULTP\blocks\Post_Author_Meta();
699 new \ULTP\blocks\Post_Date_Meta();
700 new \ULTP\blocks\Post_Social_Share();
701 new \ULTP\blocks\Advance_Post_Meta();
702 }
703 }
704
705
706 /**
707 * Necessary Requires Class
708 *
709 * @since v.1.0.0
710 * @return NULL
711 */
712 public function requires() {
713 require_once ULTP_PATH.'classes/Notice.php';
714 require_once ULTP_PATH.'classes/Styles.php';
715 require_once ULTP_PATH.'classes/Options.php';
716 require_once ULTP_PATH.'classes/REST_API.php';
717 require_once ULTP_PATH.'classes/Caches.php';
718 require_once ULTP_PATH.'classes/Importer.php';
719 new \ULTP\REST_API();
720 new \ULTP\Options();
721 new \ULTP\Caches();
722 new \ULTP\Styles();
723 new \ULTP\Notice();
724 new \ULTP\Importer();
725
726 require_once ULTP_PATH.'classes/Deactive.php';
727 new \ULTP\Deactive();
728 }
729
730
731 /**
732 * Block Categories Initialization
733 *
734 * @since v.1.0.0
735 * @param $categories(ARRAY) | $post (ARRAY)
736 * @return NULL
737 */
738 public function register_category_callback( $categories, $post ) {
739 $attr = array(
740 array(
741 'slug' => 'ultimate-post',
742 'title' => __('PostX - Gutenberg Post Blocks', 'ultimate-post')
743 ),
744 array(
745 'slug' => 'postx-site-builder',
746 'title' => __('PostX Site Builder', 'ultimate-post')
747 )
748 );
749 return array_merge($attr, $categories);
750 }
751
752
753 /**
754 * Post View Counter for Every Post
755 *
756 * @since v.1.0.0
757 * @param NUMBER | Post ID
758 * @return NULL
759 */
760 public function popular_posts_tracker_callback($post_id) {
761 if ( !is_single() ) { return; }
762 global $post;
763 $post_id = isset($post->ID) ? $post->ID : '';
764 $isEnable = apply_filters('ultp_view_cookies', true);
765 // add_filter( 'ultp_view_cookies', '__return_false' );
766 $cookies_disable = ultimate_post()->get_setting('disable_view_cookies');
767 if ( $post_id && $isEnable && $cookies_disable != 'yes' ) {
768 $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? sanitize_text_field($_COOKIE['ultp_view_'.$post_id]) : false;
769 if ( !$has_cookie ) {
770 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
771 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
772 setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
773 }
774 }
775 }
776
777
778 /**
779 * Set Image Size
780 *
781 * @since v.1.0.0
782 * @return NULL
783 */
784 public function add_image_size() {
785 $size_disable = ultimate_post()->get_setting('disable_image_size');
786 if ( $size_disable != 'yes' ) {
787 add_image_size( 'ultp_layout_landscape_large', 1200, 800, true );
788 add_image_size( 'ultp_layout_landscape', 870, 570, true );
789 add_image_size( 'ultp_layout_portrait', 600, 900, true );
790 add_image_size( 'ultp_layout_square', 600, 600, true );
791 }
792 }
793
794
795 /**
796 * Include Addons Directory
797 *
798 * @since v.1.0.0
799 * @return NULL
800 */
801 public function include_addons() {
802 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
803 if ( count($addons_dir) > 0 ) {
804 foreach( $addons_dir as $key => $value ) {
805 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
806 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
807 if ( file_exists($file_name) ) {
808 include_once $file_name;
809 }
810 }
811 }
812 }
813
814
815 /**
816 * Next Preview Callback of the Blocks
817 *
818 * @since v.1.0.0
819 * @return STRING
820 */
821 public function ultp_next_prev_callback() {
822 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
823 return ;
824 }
825
826 $paged = isset($_POST['paged'])?sanitize_text_field($_POST['paged']):'';
827 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
828 $postId = isset($_POST['postId'])? sanitize_text_field($_POST['postId']):'';
829 $blockRaw = isset($_POST['blockName'])? sanitize_text_field($_POST['blockName']):'';
830 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
831 $blockName = str_replace('_','/', $blockRaw);
832 $widgetBlockId = isset($_POST['widgetBlockId'])?sanitize_text_field($_POST['widgetBlockId']):'';
833 $exclude_post_id = isset($_POST['exclude']) ? sanitize_text_field($_POST['exclude']) : '';
834
835 $is_adv = isset($_POST['isAdv'])? ultimate_post()->ultp_rest_sanitize_params($_POST['isAdv']) : false;
836 $filterValue = isset($_POST['filterValue']) ?
837 (
838 is_array($_POST['filterValue']) ?
839 ultimate_post()->ultp_rest_sanitize_params( $_POST['filterValue'] ) :
840 sanitize_text_field($_POST['filterValue'])
841 ) :
842 '';
843
844 $filterType = isset($_POST['filterType'])? sanitize_text_field($_POST['filterType']):'';
845 $filterShow = isset($_POST['filterShow']) ? sanitize_text_field($_POST['filterShow']) : false;
846 $checkFilter = isset($_POST['checkFilter']) ? sanitize_text_field($_POST['checkFilter']) : false;
847 $author = isset($_POST['author']) ? sanitize_text_field( $_POST['author'] ) : false;
848 $orderby = isset($_POST['orderby']) ? sanitize_text_field( $_POST['orderby'] ) : 'date';
849 $order = isset($_POST['order']) ? sanitize_text_field( $_POST['order'] ) : 'DESC';
850 $search = isset($_POST['search']) ? sanitize_text_field( $_POST['search'] ) : '';
851 $adv_sort = isset($_POST['adv_sort']) ? sanitize_text_field( $_POST['adv_sort'] ) : '';
852
853 $adv_filter_data = array(
854 "is_adv" => filter_var($is_adv, FILTER_VALIDATE_BOOLEAN),
855 "filterShow" => filter_var($filterShow, FILTER_VALIDATE_BOOLEAN),
856 "checkFilter" => filter_var($checkFilter, FILTER_VALIDATE_BOOLEAN),
857 "author" => $author ? wp_json_encode($author) : false,
858 "orderby" => $orderby,
859 "order" => $order,
860 "search" => $search,
861 "adv_sort" => $adv_sort,
862 "notFirstLoad" => true
863 );
864
865 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
866 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
867
868 if( $widgetBlockId ) {
869 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
870 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, '', $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, '', $adv_filter_data);
871 }elseif ($paged && $blockId && $postId && $blockName ) {
872 $post = get_post($postId);
873 if( has_blocks($post->post_content) ) {
874 $blocks = parse_blocks($post->post_content);
875 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, '', $exclude_post_id, $adv_filter_data);
876 }
877 }
878 }
879
880 /**
881 * Pagination for filter cal'back
882 *
883 * @since v.2.8.9
884 * @return STRING
885 */
886 public function pagination_for_filter( $attr, $postId, $blockRaw, $filter_attributes ) {
887 $attr['queryNumber'] = ultimate_post()->get_post_number(4, $attr['queryNumber'], $attr['queryNumPosts']);
888 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
889 $pageNum = ultimate_post()->get_page_number($attr, $recent_posts->found_posts);
890
891 $datasets = ultimate_post()->get_adv_data_attrs(null, $filter_attributes);
892 $datasets .= ' data-for="ultp-block-' . sanitize_html_class($attr['blockId']) . '" ';
893
894 $wraper_after = '';
895 $style = $pageNum == 1 ? 'style="display:none"' : '';
896
897 if( $attr['paginationType'] == 'loadMore' ) {
898 $wraper_after .= '<div '.$style.' class="ultp-loadmore "'.'>';
899 $wraper_after .= '<span class="ultp-loadmore-action" tabindex="0" role="button" data-pages="'.$pageNum.'" data-pagenum="1" data-blockid="'.$attr['blockId'].'" data-blockname="'.$blockRaw.'" data-postid="'.$postId.'" '.ultimate_post()->get_builder_attr($attr['queryType']). $datasets.'>'.( isset($attr['loadMoreText']) ? $attr['loadMoreText'] : 'Load More' ).' <span class="ultp-spin">'.ultimate_post()->svg_icon('refresh').'</span></span>';
900 $wraper_after .= '</div>';
901 }
902 else if( $attr['paginationType'] == 'navigation' ) {
903 $wraper_after .= '<div '.$style.' class="ultp-next-prev-wrap" data-pages="'.$pageNum.'" data-pagenum="1" data-blockid="'.$attr['blockId'].'" data-blockname="'.$blockRaw.'" data-postid="'.$postId.'" '.ultimate_post()->get_builder_attr($attr['queryType']). $datasets .'>';
904 $wraper_after .= ultimate_post()->next_prev();
905 $wraper_after .= '</div>';
906 }
907 else if( $attr['paginationType'] == 'pagination' ) {
908 $wraper_after .= '<div class="ultp-pagination-wrap'.($attr["paginationAjax"] ? " ultp-pagination-ajax-action" : "").'" data-paged="1" data-blockid="'.$attr['blockId'].'" data-postid="'.$postId.'" data-pages="'.$pageNum.'" data-blockname="'.$blockRaw.'" '.ultimate_post()->get_builder_attr($attr['queryType']). $datasets .'>';
909 $wraper_after .= ultimate_post()->pagination($pageNum, $attr['paginationNav'], $attr['paginationText'], $attr["paginationAjax"], isset($_SERVER['HTTP_REFERER'])?esc_url_raw($_SERVER['HTTP_REFERER']):'');
910 $wraper_after .= '</div>';
911 }
912 wp_reset_query();
913
914 return $wraper_after;
915 }
916
917 /**
918 * Filter Callback of the Blocks
919 *
920 * @since v.1.0.0
921 * @return string
922 */
923 public function filter_block_return( $blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, &$toReturn, $widgetBlockId='', $adv_filter_data=[], $ultp_uniqueIds=[], $ultp_current_unique_posts=[] ) {
924 foreach ( $blocks as $key => $value ) {
925 if ( $blockName == $value['blockName'] ) {
926 if ( $value['attrs']['blockId'] == $blockId ) {
927
928 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
929 if ( $taxonomy ) {
930
931 if (isset($adv_filter_data['is_adv']) && $adv_filter_data['is_adv']) {
932 $value['attrs']['queryTaxValue'] = wp_json_encode($taxonomy);
933 $value['attrs']['queryRelation'] = 'AND';
934 $value['attrs']['queryAuthor'] = $adv_filter_data['author'];
935 $value['attrs']['queryOrderBy'] = $adv_filter_data['orderby'];
936 $value['attrs']['queryOrder'] = $adv_filter_data['order'];
937 $value['attrs']['querySearch'] = $adv_filter_data['search'];
938 $value['attrs']['queryQuick'] = $adv_filter_data['adv_sort'];
939 } else {
940 $value['attrs']['queryTaxValue'] = wp_json_encode(array($taxonomy));
941 }
942
943 $value['attrs']['queryTax'] = $taxtype;
944 $value['attrs']['ajaxCall'] = true;
945 }
946 if ( isset($value['attrs']['queryNumber']) ) {
947 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
948 }
949
950 if ( isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] ) {
951 $value['attrs']['loadMoreQueryUnique'] = $ultp_uniqueIds;
952 $ultp_uniqueIds[$value['attrs']['queryUnique']] = array_diff( $ultp_uniqueIds[$value['attrs']['queryUnique']], $ultp_current_unique_posts );
953 $value['attrs']['savedQueryUnique'] = $ultp_uniqueIds;
954 $value['attrs']['ultp_current_unique_posts'] = $ultp_current_unique_posts;
955 }
956
957 $attr = array_merge($attr, $value['attrs']);
958
959 $filter_attributes = [];
960
961 $filter_attributes['isAdv'] = isset($adv_filter_data['is_adv']) ? $adv_filter_data['is_adv'] : false;
962 $filter_attributes['queryTaxValue'] = $filter_attributes['isAdv'] ? wp_json_encode($taxonomy) : $taxonomy;
963 $filter_attributes['queryTax'] = $taxtype;
964
965 if ($filter_attributes['isAdv']) {
966 $filter_attributes['queryAuthor'] = $adv_filter_data['author'];
967 $filter_attributes['queryOrderBy'] = $adv_filter_data['orderby'];
968 $filter_attributes['queryOrder'] = $adv_filter_data['order'];
969 $filter_attributes['querySearch'] = $adv_filter_data['search'];
970 $filter_attributes['queryQuick'] = $adv_filter_data['adv_sort'];
971 }
972
973 $toReturn = [
974 'blocks' => $this->all_blocks[$blockRaw]->content($attr, true),
975 'pagination' => $this->pagination_for_filter($attr, $postId, $blockRaw, $filter_attributes),
976 'paginationType' => $attr['paginationType'],
977 'paginationShow' => $attr['paginationShow']
978 ];
979 }
980 }
981 if ( !empty($value['innerBlocks']) ) {
982 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, $widgetBlockId, $adv_filter_data, $ultp_uniqueIds, $ultp_current_unique_posts);
983 }
984 }
985 return $toReturn;
986 }
987
988
989 /**
990 * Filter Callback of the Blocks
991 *
992 * @since v.1.0.0
993 * @return STRING
994 */
995 public function ultp_filter_callback() {
996 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
997 return ;
998 }
999
1000 $taxtype = isset($_POST['taxtype'])? sanitize_text_field($_POST['taxtype']):'';
1001 if ( $taxtype ) {
1002 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
1003 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
1004 $taxonomy = isset($_POST['taxonomy'])?sanitize_text_field($_POST['taxonomy']):'';
1005 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
1006 $blockName = str_replace('_','/', $blockRaw);
1007 $post = get_post($postId);
1008 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
1009 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
1010 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
1011 $toReturn = [];
1012
1013 if( $widgetBlockId ) {
1014 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
1015 $data = $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, $widgetBlockId, [], $ultp_uniqueIds, $ultp_current_unique_posts);
1016 }elseif ( has_blocks($post->post_content) ) {
1017 $blocks = parse_blocks($post->post_content);
1018 $data = $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, '', [], $ultp_uniqueIds, $ultp_current_unique_posts);
1019 }
1020 return wp_send_json_success( [
1021 'filteredData' => $data
1022 ] );
1023 }
1024 }
1025
1026 /**
1027 * Advanced Filter Callback of the Blocks
1028 *
1029 * @since v.3.2.4
1030 * @return string
1031 */
1032 public function ultp_adv_filter_callback() {
1033 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
1034 return ;
1035 }
1036
1037 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
1038 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
1039
1040 $taxonomy = isset($_POST['taxonomy']) ? ultimate_post()->ultp_rest_sanitize_params( $_POST['taxonomy'] ) : '[]';
1041
1042 $author = isset($_POST['author']) ? ultimate_post()->ultp_rest_sanitize_params( $_POST['author'] ) : false;
1043 $orderby = isset($_POST['orderby']) ? sanitize_text_field( $_POST['orderby'] ) : 'date';
1044 $order = isset($_POST['order']) ? sanitize_text_field( $_POST['order'] ) : 'DESC';
1045 $search = isset($_POST['search']) ? sanitize_text_field( $_POST['search'] ) : '';
1046 $adv_sort = isset($_POST['adv_sort']) ? sanitize_text_field( $_POST['adv_sort'] ) : '';
1047
1048 $adv_filter_data = array(
1049 "is_adv" => true,
1050 "filterShow" => true,
1051 "checkFilter" => true,
1052 "author" => $author ? wp_json_encode($author) : false,
1053 "orderby" => $orderby,
1054 "order" => $order,
1055 "search" => $search,
1056 "adv_sort" => $adv_sort
1057 );
1058
1059 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
1060 $blockName = str_replace('_','/', $blockRaw);
1061 $post = get_post($postId);
1062 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
1063 $toReturn = [];
1064
1065 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
1066 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
1067
1068 if( $widgetBlockId ) {
1069 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
1070 $data = $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, 'multiTaxonomy', $taxonomy, $postId, $toReturn, $widgetBlockId, $adv_filter_data, $ultp_uniqueIds, $ultp_current_unique_posts);
1071 }elseif ( has_blocks($post->post_content) ) {
1072 $blocks = parse_blocks($post->post_content);
1073 $data = $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, 'multiTaxonomy', $taxonomy, $postId, $toReturn, '', $adv_filter_data, $ultp_uniqueIds, $ultp_current_unique_posts);
1074 }
1075 return wp_send_json_success( [
1076 'filteredData' => $data
1077 ] );
1078 }
1079
1080 /**
1081 * Pagination of the Blocks
1082 *
1083 * @since v.1.0.0
1084 * @return STRING
1085 */
1086 public function ultp_pagination_callback() {
1087 if (! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce'))) {
1088 return ;
1089 }
1090
1091 $paged = isset($_POST['paged'])? sanitize_text_field($_POST['paged']):'';
1092 if ( $paged ) {
1093 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
1094 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
1095 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
1096 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
1097 $blockName = str_replace('_','/', $blockRaw);
1098 $post = get_post($postId);
1099 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
1100 $exclude_post_id = isset($_POST['exclude']) ? sanitize_text_field($_POST['exclude']) : '';
1101
1102 $is_adv = isset($_POST['isAdv'])? ultimate_post()->ultp_rest_sanitize_params($_POST['isAdv']) : false;
1103 $filterValue = isset($_POST['filterValue']) ?
1104 (
1105 is_array($_POST['filterValue']) ?
1106 ultimate_post()->ultp_rest_sanitize_params( $_POST['filterValue'] ) :
1107 sanitize_text_field($_POST['filterValue'])
1108 ) :
1109 '';
1110
1111 $filterType = isset($_POST['filterType'])? sanitize_text_field($_POST['filterType']):'';
1112 $filterShow = isset($_POST['filterShow']) ? sanitize_text_field($_POST['filterShow']) : false;
1113 $checkFilter = isset($_POST['checkFilter']) ? sanitize_text_field($_POST['checkFilter']) : false;
1114 $author = isset($_POST['author']) ? sanitize_text_field( $_POST['author'] ) : false;
1115 $orderby = isset($_POST['orderby']) ? sanitize_text_field( $_POST['orderby'] ) : 'date';
1116 $order = isset($_POST['order']) ? sanitize_text_field( $_POST['order'] ) : 'DESC';
1117 $search = isset($_POST['search']) ? sanitize_text_field( $_POST['search'] ) : '';
1118 $adv_sort = isset($_POST['adv_sort']) ? sanitize_text_field( $_POST['adv_sort'] ) : '';
1119
1120 $adv_filter_data = array(
1121 "is_adv" => filter_var($is_adv, FILTER_VALIDATE_BOOLEAN),
1122 "filterShow" => filter_var($filterShow, FILTER_VALIDATE_BOOLEAN),
1123 "checkFilter" => filter_var($checkFilter, FILTER_VALIDATE_BOOLEAN),
1124 "author" => $author ? wp_json_encode($author) : false,
1125 "orderby" => $orderby,
1126 "order" => $order,
1127 "search" => $search,
1128 "adv_sort" => $adv_sort,
1129 );
1130
1131
1132 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
1133 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
1134
1135 if( $widgetBlockId ) {
1136 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
1137 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, '', $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, '', $adv_filter_data);
1138 }elseif( has_blocks($post->post_content) ) {
1139 $blocks = parse_blocks($post->post_content);
1140 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, '', $exclude_post_id, $adv_filter_data);
1141 }
1142 }
1143 }
1144
1145 /**
1146 * share Count callback
1147 *
1148 * @since v.1.0.0
1149 * @return STRING
1150 */
1151 public function ultp_shareCount_callback() {
1152 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
1153 return ;
1154 }
1155 $id =isset($_POST['postId'])? sanitize_text_field($_POST['postId']):'';
1156 $count = isset($_POST['shareCount'])? sanitize_text_field($_POST['shareCount']):'';
1157 $post_id = $id;
1158 $new_count = $count+1;
1159 update_post_meta($post_id, 'share_count', $new_count);
1160 }
1161
1162 /**
1163 * update_block_attrUpdate Block Attr for Pagination Loadmore and Navigation
1164 *
1165 * @since v.3.1.1
1166 */
1167 function update_block_attr($postId, $blocks, $key, $widgetBlockId ) {
1168 if( $widgetBlockId ) {
1169 $widget_blocks = get_option('widget_block');
1170 $block_parsed = parse_blocks($widget_blocks[$widgetBlockId]['content']);
1171 $block_parsed[$key]['attrs']['currentPostId'] = 'widgets';
1172 $widget_blocks[$widgetBlockId]['content'] = serialize_blocks($block_parsed);
1173 update_option('widget_block', str_replace('u0022', '\u0022', $widget_blocks));
1174 } else {
1175 $blocks[$key]['attrs']['currentPostId'] = $postId;
1176 wp_update_post(array(
1177 'ID' => $postId,
1178 'post_content' => str_replace('u0022', '\u0022', serialize_blocks($blocks))
1179 ));
1180 }
1181 }
1182
1183 /**
1184 * Blocks Content Start
1185 *
1186 * @since v.1.0.0
1187 * @return STRING
1188 */
1189 public function block_return( $blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds=[], $ultp_current_unique_posts=[] , $widgetBlockId='', $exclude_post_id = '', $adv_filter_data=[] ) {
1190 foreach ( $blocks as $key => $value ) {
1191 if ($blockName == $value['blockName']) {
1192 if ( $value['attrs']['blockId'] == $blockId ) {
1193 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
1194
1195 // Fix for grid blocks that do not support load more by default (pagination block)
1196 if (isset($adv_filter_data['notFirstLoad']) && $adv_filter_data['notFirstLoad']) {
1197 $attr['notFirstLoad'] = $adv_filter_data['notFirstLoad'];
1198 }
1199
1200 $value['attrs']['paged'] = $paged;
1201 if ( $builder ) {
1202 $value['attrs']['builder'] = $builder;
1203 }
1204 if ( $postId ) {
1205 $attr['current_post'] = $postId;
1206 if( get_post_type($postId) == 'ultp_builder' && !$builder ){
1207 $attr['current_post'] = $exclude_post_id;
1208 }
1209 }
1210 if ( isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] ) {
1211 $value['attrs']['loadMoreQueryUnique'] = $ultp_uniqueIds;
1212 $ultp_uniqueIds[$value['attrs']['queryUnique']] = array_diff( $ultp_uniqueIds[$value['attrs']['queryUnique']], $ultp_current_unique_posts );
1213 $value['attrs']['savedQueryUnique'] = $ultp_uniqueIds;
1214 $value['attrs']['ultp_current_unique_posts'] = $ultp_current_unique_posts;
1215 }
1216 if( isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] && ( $value['attrs']['paginationType'] == 'loadMore' || $value['attrs']['paginationType'] == 'navigation') && isset($ultp_uniqueIds) && !isset($ultp_current_unique_posts) ) {
1217 die();
1218 }
1219
1220 if( $filterValue ) {
1221 $value['attrs']['queryTaxValue'] = $adv_filter_data["is_adv"] ? wp_json_encode($filterValue) : wp_json_encode(array($filterValue));
1222 $value['attrs']['queryTax'] = $filterType;
1223 $value['attrs']['checkFilter'] = true;
1224 $value['attrs']['filterShow'] = $adv_filter_data["filterShow"];
1225 $value['attrs']['queryAuthor'] = $adv_filter_data["author"];
1226 $value['attrs']['queryOrderBy'] = $adv_filter_data["orderby"];
1227 $value['attrs']['queryOrder'] = $adv_filter_data["order"];
1228 $value['attrs']['querySearch'] = $adv_filter_data["search"];
1229 $value['attrs']['queryQuick'] = $adv_filter_data["adv_sort"];
1230
1231 if ($adv_filter_data["is_adv"]) {
1232 $value['attrs']['queryRelation'] = 'AND';
1233 }
1234 }
1235 // Exclude Current Post From Pagination
1236 if( $exclude_post_id ){
1237 $queryArr = json_decode( $value['attrs']['queryExclude']);
1238 $queryArr[] = array(
1239 'value' => $exclude_post_id,
1240 'title' => ''
1241 );
1242 $value['attrs']['queryExclude'] = wp_json_encode($queryArr);
1243 }
1244 $attr = array_merge($attr, $value['attrs']);
1245 echo $this->all_blocks[$blockRaw]->content($attr, true); //phpcs:ignore
1246 die();
1247 }
1248 }
1249 if ( !empty($value['innerBlocks']) ) {
1250 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, $exclude_post_id, $adv_filter_data);
1251 }
1252 }
1253 }
1254
1255 /**
1256 * WordPress Plugin Notice
1257 *
1258 * @since v.2.6.4
1259 * @return NULL
1260 */
1261 public function in_plugin_settings_update_message() {
1262 $response = wp_remote_get(
1263 'https://plugins.svn.wordpress.org/ultimate-post/trunk/readme.txt', array(
1264 'method' => 'GET'
1265 ));
1266
1267 if ( is_wp_error( $response ) || $response['response']['code'] != 200 ) {
1268 return;
1269 }
1270
1271 $changelog_lines = preg_split("/(\r\n|\n|\r)/", $response['body']);
1272
1273 $is_copy = false;
1274 $current_tag = '';
1275 $tag_text = 'Stable tag:';
1276 if ( !empty($changelog_lines) ) {
1277 echo '<hr style="border-color:#dba617;"/>';
1278 echo '<div style="color:#50575e;font-size:13px;font-weight:bold;"> <span style="color:#f56e28;" class="dashicons dashicons-warning"></span> ' . esc_html('PostX is ready for the next update. Changelog:-') . '</div>';
1279 echo '<hr style="border-color:#dba617;"/>';
1280 echo '<ul style="max-height:200px;overflow:scroll;">';
1281 foreach ( $changelog_lines as $key => $line ) {
1282 // Get Current Vesion
1283 if ( $current_tag == '' ) {
1284 if ( strpos($line, $tag_text) !== false ) {
1285 $current_tag = trim(str_replace($tag_text, '', $line));
1286 }
1287 } else {
1288 if ( $is_copy ) {
1289 if ( strpos($line, '= '.ULTP_VER) !== false ) {
1290 break;
1291 }
1292 if ( !empty($line) ) {
1293 if ( strpos($line, '= ') !== false ) {
1294 echo '<li style="color:#50575e;font-weight:bold;"><br/>'.esc_html($line).'</li>';
1295 } else {
1296 echo '<li>'.esc_html($line).'</li>';
1297 }
1298 }
1299 } else {
1300 if ( strpos($line, '= '.$current_tag) !== false ) { // Current Version
1301 $is_copy = true;
1302 echo '<li style="color:#50575e;font-weight:bold;">'.esc_html($line).'</li>';
1303 }
1304 }
1305 }
1306 }
1307 echo '</ul>';
1308 }
1309 }
1310
1311 /**
1312 * Check Plugin Upgrade
1313 *
1314 * @since 2.4.3
1315 *
1316 * @return void
1317 */
1318 public function plugin_upgrade_completed() {
1319 if ( ultimate_post()->get_setting('init_setup') != 'yes' ) {
1320 ultimate_post()->set_setting('init_setup', 'yes');
1321 }
1322 }
1323
1324 }