PluginProbe
Post Grid Gutenberg Blocks – PostX / 3.1.5
Post Grid Gutenberg Blocks – PostX v3.1.5
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 3.1.5, at classes/Initialization.php

944 lines 42.8 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 use FluentCrm\App\Services\Sanitize;
11
12 defined('ABSPATH') || exit;
13
14 /**
15 * Initialization class.
16 */
17 class ULTP_Initialization{
18
19 private $all_blocks;
20
21 /**
22 * Setup class.
23 *
24 * @since v.1.1.0
25 */
26 public function __construct() {
27 $this->compatibility_check();
28 $this->requires(); // Include Necessary Files
29 $this->blocks(); // Include Blocks
30 $this->include_addons(); // Include Addons
31
32 add_action('wp', array($this, 'popular_posts_tracker_callback'));
33 add_filter('block_categories_all', array($this, 'register_category_callback'), 999999999, 2); // Block Category Register
34 add_action('after_setup_theme', array($this, 'add_image_size'));
35
36 add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor
37 add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel
38 add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend
39 register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook'));
40 add_action( 'activated_plugin', array($this, 'activation_redirect'));
41
42 add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call
43 add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User
44 add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call
45 add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User
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, 'check_theme_compatibility'));
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
60 /**
61 * Theme Switch Callback
62 *
63 * @since v.1.1.0
64 * @return NULL
65 */
66 public function wpxpo_swithch_thememe () {
67 $this->check_theme_compatibility();
68 }
69
70
71 /**
72 * Theme Compatibility Action
73 *
74 * @since v.1.1.0
75 * @return NULL
76 */
77 public function check_theme_compatibility() {
78 $licence = apply_filters( 'ultp_theme_integration' , FALSE);
79 $theme = get_transient( 'ulpt_theme_enable' );
80
81 if ($licence ) {
82 if ($theme != 'integration' ) {
83 $themes = wp_get_theme();
84 $api_params = array(
85 'wpxpo_theme_action' => 'theme_license',
86 'slug' => $themes->get('TextDomain'),
87 'author' => $themes->get('Author'),
88 'item_id' => 181,
89 'url' => home_url()
90 );
91
92 $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
93
94 if (!is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) {
95 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
96 if (isset($license_data->license)) {
97 if ($license_data->license == 'valid' ) {
98 set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time
99 }
100 }
101 }
102 }
103 } else {
104 if ($theme == 'integration' ) {
105 delete_transient('ulpt_theme_enable');
106 }
107 }
108 }
109
110
111 /**
112 * Check Compatibility
113 *
114 * @since v.1.0.0
115 * @return NULL
116 */
117 public function compatibility_check() {
118 require_once ULTP_PATH.'classes/Compatibility.php';
119 new \ULTP\Compatibility();
120 }
121
122
123 /**
124 * Option Panel CSS and JS Scripts
125 *
126 * @since v.1.0.0
127 * @return NULL
128 */
129 public function register_scripts_option_panel_callback() {
130 $is_active = ultimate_post()->is_lc_active();
131 $license_key = get_option('edd_ultp_license_key');
132
133 // Custom Font Support Added
134 $font_settings = ultimate_post()->get_setting('ultp_custom_font');
135 $custom_fonts = array();
136 if ($font_settings == 'true') {
137 wp_enqueue_media();
138 $args = array(
139 'post_type' => 'ultp_custom_font',
140 'post_status' => 'publish',
141 'numberposts' => 333,
142 'order' => 'ASC'
143 );
144 $posts = get_posts( $args );
145 if ($posts) {
146 foreach( $posts as $post) {
147 setup_postdata( $post );
148 $font = get_post_meta($post->ID , '__font_settings', true);
149
150 if ( $font ) {
151 array_push( $custom_fonts, array(
152 'title' => $post->post_title,
153 'font' => $font
154 ));
155 }
156 }
157 wp_reset_postdata();
158 }
159 }
160
161 wp_enqueue_style('wp-color-picker');
162 wp_enqueue_script('wp-color-picker');
163 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
164 wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER);
165
166 wp_localize_script('ultp-option-script', 'ultp_option_panel', array(
167 'url' => ULTP_URL,
168 'active' => $is_active,
169 'security' => wp_create_nonce('ultp-nonce'),
170 'ajax' => admin_url('admin-ajax.php'),
171 'license' => $license_key,
172 'settings' => ultimate_post()->get_setting(),
173 'addons' => ultimate_post()->all_addons(),
174 'premium_link' => ultimate_post()->get_premium_link(),
175 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
176 'custom_fonts' => $custom_fonts,
177 'addons_settings' => apply_filters('ultp_settings', []),
178 'post_type' => get_post_type(),
179 'saved_template_url' => admin_url('admin.php?page=ultp-settings#saved-templates'),
180 ));
181
182 /* === Installation Wizard === */
183 $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
184 if ($_page == 'ultp-initial-setup-wizard') {
185 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);
186 wp_set_script_translations( 'ultp-initial-setup-script', 'ultimate-post', ULTP_PATH . 'languages/' );
187 }
188
189 /* === Builder And Setting Pannel === */
190 // if ($_page == 'ultp-settings' || get_post_type(get_the_ID()) == 'ultp_builder') {
191 if (get_post_type(get_the_ID()) == 'ultp_builder') {
192 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);
193 wp_localize_script('ultp-conditions-script', 'ultp_condition', array(
194 'url' => ULTP_URL,
195 'active' => $is_active,
196 'premium_link' => ultimate_post()->get_premium_link(),
197 'license' => $license_key,
198 'builder_url' => admin_url('admin.php?page=ultp-settings#builder'),
199 'affiliate_id' => apply_filters( 'ultp_affiliate_id', FALSE )
200 ));
201 wp_set_script_translations( 'ultp-conditions-script', 'ultimate-post', ULTP_PATH . 'languages/' );
202 }
203
204 /* === Dashboard === */
205 $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
206 if ($_page == 'ultp-settings') {
207 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);
208 wp_localize_script('ultp-dashboard-script', 'ultp_dashboard_pannel', array(
209 'url' => ULTP_URL,
210 'active' => $is_active,
211 'license' => $license_key,
212 'settings' => ultimate_post()->get_setting(),
213 'addons' => ultimate_post()->all_addons(),
214 'addons_settings' => apply_filters('ultp_settings', []),
215 'premium_link' => ultimate_post()->get_premium_link(),
216 'builder_url' => admin_url('admin.php?page=ultp-settings#builder'),
217 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
218 'version' => ULTP_VER,
219 'setup_wizard_link' => admin_url('admin.php?page=ultp-initial-setup-wizard'),
220 'helloBar' => get_transient('ultp_helloBar'),
221 'status' => get_option( 'edd_ultp_license_status' ),
222 'expire' => get_option( 'edd_ultp_license_expire' )
223 ));
224 wp_set_script_translations( 'ultp-dashboard-script', 'ultimate-post', ULTP_PATH . 'languages/' );
225 }
226
227 }
228
229
230 /**
231 * Only Frontend CSS and JS Scripts
232 *
233 * @since v.1.0.0
234 * @return NULL
235 */
236 public function register_scripts_front_callback() {
237 $call_common = false;
238 if (isset($_GET['preview_id']) && isset($_GET['preview_nonce'])) {
239 $call_common = true;
240 ultimate_post()->register_scripts_common();
241 } else if ('yes' == get_post_meta(ultimate_post()->get_ID(), '_ultp_active', true)) {
242 $call_common = true;
243 ultimate_post()->register_scripts_common();
244 } else if (ultimate_post()->is_builder()) {
245 $call_common = true;
246 ultimate_post()->register_scripts_common();
247 } else if (apply_filters('postx_common_script', false)) {
248 $call_common = true;
249 ultimate_post()->register_scripts_common();
250 } else if (isset($_GET['et_fb'])) { // Divi Backend Builder
251 $call_common = true;
252 ultimate_post()->register_scripts_common();
253 }
254
255 // For WidgetWidget
256 $has_block = false;
257 $widget_blocks = array();
258 global $wp_registered_sidebars, $sidebars_widgets;
259 foreach ($wp_registered_sidebars as $key => $value) {
260 if (is_active_sidebar($key)) {
261 foreach ($sidebars_widgets[$key] as $val) {
262 if (strpos($val, 'block-') !== false) {
263 if (empty($widget_blocks)) {
264 $widget_blocks = get_option( 'widget_block' );
265 }
266 foreach ( (array) $widget_blocks as $block ) {
267 if (isset( $block['content'] ) && strpos($block['content'], 'wp:ultimate-post') !== false ) {
268 $has_block = true;
269 break;
270 }
271 }
272 if ($has_block) {
273 break;
274 }
275 }
276 }
277 }
278 }
279 if ($has_block) {
280 if (!$call_common) {
281 ultimate_post()->register_scripts_common();
282 }
283 $css = get_option('ultp-widget', true);
284 if ($css) {
285 wp_register_style('ultp-post-widget', false );
286 wp_enqueue_style('ultp-post-widget' );
287 wp_add_inline_style('ultp-post-widget', $css);
288 }
289 }
290 }
291
292
293 /**
294 * Only Backend CSS and JS Scripts
295 *
296 * @since v.1.0.0
297 * @return NULL
298 */
299 public function register_scripts_back_callback() {
300 ultimate_post()->register_scripts_common();
301 global $pagenow;
302 $depends = 'wp-editor';
303 if ($pagenow === 'widgets.php' ) {
304 $depends = 'wp-edit-widgets';
305 }
306 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);
307 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
308 if (is_rtl()) {
309 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
310 }
311 $is_active = ultimate_post()->is_lc_active();
312 $post_type = get_post_type();
313 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
314 'url' => ULTP_URL,
315 'ajax' => admin_url('admin-ajax.php'),
316 'security' => wp_create_nonce('ultp-nonce'),
317 'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'),
318 'upload' => wp_upload_dir()['basedir'] . '/ultp',
319 'premium_link' => ultimate_post()->get_premium_link(),
320 'license' => $is_active ? get_option('edd_ultp_license_key') : '',
321 'active' => $is_active,
322 'archive' => ultimate_post()->is_archive_builder(),
323 'settings' => ultimate_post()->get_setting(),
324 'post_type' => $post_type == 'premade' ? 'ultp_builder' : $post_type, // premade used for ultp.wpxpo.com
325 'date_format' => get_option('date_format'),
326 'time_format' => get_option('time_format'),
327 'blog' => get_current_blog_id(),
328 'archive_child' => ultimate_post()->is_archive_child_builder(),
329 'affiliate_id' => apply_filters( 'ultp_affiliate_id', FALSE ),
330 'category_url' =>admin_url( 'edit-tags.php?taxonomy=category' ),
331 'disable_image_size' => ultimate_post()->get_setting('disable_image_size')
332 ));
333 wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
334 }
335
336
337 /**
338 * Fire When Plugin First Install
339 *
340 * @since v.1.0.0
341 * @return NULL
342 */
343 public function install_hook() {
344 if (!get_option('ultp_options')) {
345 ultimate_post()->init_set_data();
346 }
347 if (!get_transient('wpxpo_installation_date')) {
348 set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
349 }
350 }
351
352
353 /**
354 * Redirect After Active Plugin
355 *
356 * @since v.1.0.0
357 * @param STRING | Plugin Path
358 * @return NULL
359 */
360 public function activation_redirect($plugin) {
361 if (wp_doing_ajax()) {
362 return;
363 }
364
365 if ($plugin == 'ultimate-post/ultimate-post.php' ) {
366 if (ultimate_post()->get_setting('init_setup') != 'yes') {
367 exit(wp_safe_redirect(admin_url('admin.php?page=ultp-initial-setup-wizard'))); //phpcs:ignore
368 } else {
369 exit(wp_safe_redirect(admin_url('admin.php?page=ultp-settings#home'))); //phpcs:ignore
370 }
371 }
372 }
373
374
375 /**
376 * Require Blocks
377 *
378 * @since v.1.0.0
379 * @return NULL
380 */
381 public function blocks() {
382 global $unique_ID;
383 $setting = ultimate_post()->get_setting();
384 require_once ULTP_PATH.'blocks/Post_List_1.php';
385 require_once ULTP_PATH.'blocks/Post_List_2.php';
386 require_once ULTP_PATH.'blocks/Post_List_3.php';
387 require_once ULTP_PATH.'blocks/Post_List_4.php';
388 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
389 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
390 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
391 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
392 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
393 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
394 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
395 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
396 require_once ULTP_PATH.'blocks/Post_Slider_2.php';
397 require_once ULTP_PATH.'blocks/Post_Module_1.php';
398 require_once ULTP_PATH.'blocks/Post_Module_2.php';
399 require_once ULTP_PATH.'blocks/Heading.php';
400 require_once ULTP_PATH.'blocks/Image.php';
401 require_once ULTP_PATH.'blocks/Taxonomy.php';
402 require_once ULTP_PATH.'blocks/News_Ticker.php';
403 require_once ULTP_PATH.'blocks/Advanced_Search.php';
404
405 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
406 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
407 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
408 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
409 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
410 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
411 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
412 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
413 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
414 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
415 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
416 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
417 $this->all_blocks['ultimate-post_post-slider-2'] = new \ULTP\blocks\Post_Slider_2();
418 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
419 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
420 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
421 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
422 $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
423 $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\News_Ticker();
424 $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\Advanced_Search();
425
426 if (ultimate_post()->get_setting('ultp_builder') == 'true') {
427 require_once ULTP_PATH.'addons/builder/blocks/Archive_Title.php';
428 require_once ULTP_PATH.'addons/builder/blocks/Post_Title.php';
429 require_once ULTP_PATH.'addons/builder/blocks/Post_Content.php';
430 require_once ULTP_PATH.'addons/builder/blocks/Post_Featured_Image.php';
431 require_once ULTP_PATH.'addons/builder/blocks/Post_Breadcrumb.php';
432 require_once ULTP_PATH.'addons/builder/blocks/Post_Tag.php';
433 require_once ULTP_PATH.'addons/builder/blocks/Post_Category.php';
434 require_once ULTP_PATH.'addons/builder/blocks/Next_Previous.php';
435 require_once ULTP_PATH.'addons/builder/blocks/Post_Excerpt.php';
436 require_once ULTP_PATH.'addons/builder/blocks/Author_Box.php';
437 require_once ULTP_PATH.'addons/builder/blocks/Post_Comments.php';
438 require_once ULTP_PATH.'addons/builder/blocks/Post_View_Count.php';
439 require_once ULTP_PATH.'addons/builder/blocks/Post_Reading_Time.php';
440 require_once ULTP_PATH.'addons/builder/blocks/Post_Comment_Count.php';
441 require_once ULTP_PATH.'addons/builder/blocks/Post_Author_Meta.php';
442 require_once ULTP_PATH.'addons/builder/blocks/Post_Date_Meta.php';
443 // require_once ULTP_PATH.'addons/builder/blocks/Related_Posts.php';
444 require_once ULTP_PATH.'addons/builder/blocks/Post_Social_Share.php';
445 require_once ULTP_PATH.'addons/builder/blocks/Advance_Post_Meta.php';
446
447 new \ULTP\blocks\Archive_Title();
448 new \ULTP\blocks\Post_Title();
449 new \ULTP\blocks\Post_Content();
450 new \ULTP\blocks\Post_Featured_Image();
451 new \ULTP\blocks\Post_Breadcrumb();
452 new \ULTP\blocks\Post_Tag();
453 new \ULTP\blocks\Post_Category();
454 new \ULTP\blocks\Next_Previous();
455 new \ULTP\blocks\Post_Excerpt();
456 new \ULTP\blocks\Author_Box();
457 new \ULTP\blocks\Post_Comments();
458 new \ULTP\blocks\Post_View_Count();
459 new \ULTP\blocks\Post_Reading_Time();
460 new \ULTP\blocks\Post_Comment_Count();
461 new \ULTP\blocks\Post_Author_Meta();
462 new \ULTP\blocks\Post_Date_Meta();
463 // new \ULTP\blocks\Related_Posts();
464 new \ULTP\blocks\Post_Social_Share();
465 new \ULTP\blocks\Advance_Post_Meta();
466 }
467 }
468
469
470 /**
471 * Necessary Requires Class
472 *
473 * @since v.1.0.0
474 * @return NULL
475 */
476 public function requires() {
477 require_once ULTP_PATH.'classes/Notice.php';
478 require_once ULTP_PATH.'classes/Styles.php';
479 require_once ULTP_PATH.'classes/Options.php';
480 require_once ULTP_PATH.'classes/REST_API.php';
481 require_once ULTP_PATH.'classes/Caches.php';
482 new \ULTP\REST_API();
483 new \ULTP\Options();
484 new \ULTP\Caches();
485 new \ULTP\Styles();
486 new \ULTP\Notice();
487
488 require_once ULTP_PATH.'classes/Deactive.php';
489 new \ULTP\Deactive();
490 }
491
492
493 /**
494 * Block Categories Initialization
495 *
496 * @since v.1.0.0
497 * @param $categories(ARRAY) | $post (ARRAY)
498 * @return NULL
499 */
500 public function register_category_callback( $categories, $post ) {
501 $attr = array(
502 array(
503 'slug' => 'ultimate-post',
504 'title' => __('PostX - Gutenberg Post Blocks', 'ultimate-post')
505 ),
506 array(
507 'slug' => 'postx-site-builder',
508 'title' => __('PostX Site Builder', 'ultimate-post')
509 )
510 );
511 return array_merge($attr, $categories);
512 }
513
514
515 /**
516 * Post View Counter for Every Post
517 *
518 * @since v.1.0.0
519 * @param NUMBER | Post ID
520 * @return NULL
521 */
522 public function popular_posts_tracker_callback($post_id) {
523 if (!is_single()) { return; }
524 global $post;
525 $post_id = isset($post->ID) ? $post->ID : '';
526 $isEnable = apply_filters('ultp_view_cookies', true);
527 // add_filter( 'ultp_view_cookies', '__return_false' );
528 $cookies_disable = ultimate_post()->get_setting('disable_view_cookies');
529 if ($post_id && $isEnable && $cookies_disable != 'yes') {
530 $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? sanitize_text_field($_COOKIE['ultp_view_'.$post_id]) : false;
531 if (!$has_cookie) {
532 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
533 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
534 setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
535 }
536 }
537 }
538
539
540 /**
541 * Set Image Size
542 *
543 * @since v.1.0.0
544 * @return NULL
545 */
546 public function add_image_size() {
547 $size_disable = ultimate_post()->get_setting('disable_image_size');
548 if ($size_disable != 'yes') {
549 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
550 add_image_size('ultp_layout_landscape', 870, 570, true);
551 add_image_size('ultp_layout_portrait', 600, 900, true);
552 add_image_size('ultp_layout_square', 600, 600, true);
553 }
554 }
555
556
557 /**
558 * Include Addons Directory
559 *
560 * @since v.1.0.0
561 * @return NULL
562 */
563 public function include_addons() {
564 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
565 if (count($addons_dir) > 0) {
566 foreach( $addons_dir as $key => $value ) {
567 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
568 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
569 if (file_exists($file_name) ) {
570 include_once $file_name;
571 }
572 }
573 }
574 }
575
576
577 /**
578 * Next Preview Callback of the Blocks
579 *
580 * @since v.1.0.0
581 * @return STRING
582 */
583 public function ultp_next_prev_callback() {
584 if (! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce'))) {
585 return ;
586 }
587
588 $paged = isset($_POST['paged'])?sanitize_text_field($_POST['paged']):'';
589 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
590 $postId = isset($_POST['postId'])? sanitize_text_field($_POST['postId']):'';
591 $blockRaw = isset($_POST['blockName'])? sanitize_text_field($_POST['blockName']):'';
592 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
593 $blockName = str_replace('_','/', $blockRaw);
594 $widgetBlockId = isset($_POST['widgetBlockId'])?sanitize_text_field($_POST['widgetBlockId']):'';
595 $filterValue = isset($_POST['filterValue'])?sanitize_text_field($_POST['filterValue']):'';
596 $filterType = isset($_POST['filterType'])?sanitize_text_field($_POST['filterType']):'';
597 $exclude_post_id = isset($_POST['exclude']) ? sanitize_text_field($_POST['exclude']) : '';
598
599 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
600 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
601
602 if($widgetBlockId) {
603 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
604 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, '', $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, '');
605 }elseif ($paged && $blockId && $postId && $blockName ) {
606 $post = get_post($postId);
607 if(has_blocks($post->post_content)) {
608 $blocks = parse_blocks($post->post_content);
609 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, '', $exclude_post_id);
610 }
611 }
612 }
613
614 /**
615 * Pagination for filter cal'back
616 *
617 * @since v.2.8.9
618 * @return STRING
619 */
620 public function pagination_for_filter( $attr, $postId, $blockRaw, $filter_attributes ) {
621 $attr['queryNumber'] = ultimate_post()->get_post_number(4, $attr['queryNumber'], $attr['queryNumPosts']);
622 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
623 $pageNum = ultimate_post()->get_page_number($attr, $recent_posts->found_posts);
624
625 $data_filter_value = 'data-filter-value=" ' . $filter_attributes['queryTaxValue']. '"';
626 $data_filter_type = 'data-filter-type=" ' . $filter_attributes['queryTax']. '"';
627 $wraper_after = '';
628 $style = $pageNum == 1 ? 'style="display:none"' : '';
629
630 if($attr['paginationType'] == 'loadMore') {
631 $wraper_after .= '<div '.$style.' class="ultp-loadmore "'. $data_filter_value . $data_filter_type .'>';
632 $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']).'>'.( isset($attr['loadMoreText']) ? $attr['loadMoreText'] : 'Load More' ).' <span class="ultp-spin">'.ultimate_post()->svg_icon('refresh').'</span></span>';
633 $wraper_after .= '</div>';
634 }
635 else if($attr['paginationType'] == 'navigation') {
636 $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']). $data_filter_value . $data_filter_type .'>';
637 $wraper_after .= ultimate_post()->next_prev();
638 $wraper_after .= '</div>';
639 }
640 else if($attr['paginationType'] == 'pagination') {
641 $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']). $data_filter_value . $data_filter_type .'>';
642 $wraper_after .= ultimate_post()->pagination($pageNum, $attr['paginationNav'], $attr['paginationText'], $attr["paginationAjax"], isset($_SERVER['HTTP_REFERER'])?esc_url_raw($_SERVER['HTTP_REFERER']):'');
643 $wraper_after .= '</div>';
644 }
645 wp_reset_query();
646
647 return $wraper_after;
648 }
649
650 /**
651 * Filter Callback of the Blocks
652 *
653 * @since v.1.0.0
654 * @return STRING
655 */
656 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, &$toReturn, $widgetBlockId='') {
657 foreach ($blocks as $key => $value) {
658 if ($blockName == $value['blockName']) {
659 if ($value['attrs']['blockId'] == $blockId) {
660 // if(!$value['attrs']['currentPostId']) {
661 // $this->update_block_attr( $postId, $blocks, $key, $widgetBlockId );
662 // }
663 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
664 if ($taxonomy) {
665 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
666 $value['attrs']['queryTax'] = $taxtype;
667 $value['attrs']['ajaxCall'] = true;
668 }
669 if (isset($value['attrs']['queryNumber'])) {
670 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
671 }
672 $attr = array_merge($attr, $value['attrs']);
673
674 $filter_attributes = [];
675 $filter_attributes['queryTaxValue'] = $taxonomy;
676 $filter_attributes['queryTax'] = $taxtype;
677
678 $toReturn = [
679 'blocks' => $this->all_blocks[$blockRaw]->content($attr, true),
680 'pagination' => $this->pagination_for_filter($attr, $postId, $blockRaw, $filter_attributes),
681 'paginationType' => $attr['paginationType'],
682 'paginationShow' => $attr['paginationShow']
683 ];
684 }
685 }
686 if (!empty($value['innerBlocks'])) {
687 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, $widgetBlockId);
688 }
689 }
690 return $toReturn;
691 }
692
693
694 /**
695 * Filter Callback of the Blocks
696 *
697 * @since v.1.0.0
698 * @return STRING
699 */
700 public function ultp_filter_callback() {
701 if (! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce'))) {
702 return ;
703 }
704
705 $taxtype = isset($_POST['taxtype'])? sanitize_text_field($_POST['taxtype']):'';
706 if ($taxtype ) {
707 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
708 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
709 $taxonomy = isset($_POST['taxonomy'])?sanitize_text_field($_POST['taxonomy']):'';
710 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
711 $blockName = str_replace('_','/', $blockRaw);
712 $post = get_post($postId);
713 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
714 $toReturn = [];
715 if($widgetBlockId) {
716 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
717 $data = $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, $widgetBlockId);
718 }elseif (has_blocks($post->post_content)) {
719 $blocks = parse_blocks($post->post_content);
720 $data = $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, '');
721 }
722 return wp_send_json_success( [
723 'filteredData' => $data
724 ] );
725 }
726 }
727
728
729 /**
730 * Pagination of the Blocks
731 *
732 * @since v.1.0.0
733 * @return STRING
734 */
735 public function ultp_pagination_callback() {
736 if (! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce'))) {
737 return ;
738 }
739
740 $paged = isset($_POST['paged'])? sanitize_text_field($_POST['paged']):'';
741 if ($paged) {
742 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
743 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
744 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
745 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
746 $blockName = str_replace('_','/', $blockRaw);
747 $post = get_post($postId);
748 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
749 $filterValue = isset($_POST['filterValue'])? sanitize_text_field($_POST['filterValue']):'';
750 $filterType = isset($_POST['filterType'])? sanitize_text_field($_POST['filterType']):'';
751 $exclude_post_id = isset($_POST['exclude']) ? sanitize_text_field($_POST['exclude']) : '';
752 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
753 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
754
755 if($widgetBlockId) {
756 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
757 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, '', $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, '');
758 }elseif(has_blocks($post->post_content)) {
759 $blocks = parse_blocks($post->post_content);
760 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, '', $exclude_post_id);
761 }
762 }
763 }
764
765 /**
766 * share Count callback
767 *
768 * @since v.1.0.0
769 * @return STRING
770 */
771 public function ultp_shareCount_callback() {
772 if (! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce'))) {
773 return ;
774 }
775 $id =isset($_POST['postId'])? sanitize_text_field($_POST['postId']):'';
776 $count = isset($_POST['shareCount'])? sanitize_text_field($_POST['shareCount']):'';
777 $post_id = $id;
778 $new_count = $count+1;
779 update_post_meta($post_id, 'share_count', $new_count);
780 }
781
782 /**
783 * update_block_attrUpdate Block Attr for Pagination Loadmore and Navigation
784 *
785 * @since v.3.1.1
786 */
787 function update_block_attr($postId, $blocks, $key, $widgetBlockId ) {
788 if($widgetBlockId) {
789 $widget_blocks = get_option('widget_block');
790 $block_parsed = parse_blocks($widget_blocks[$widgetBlockId]['content']);
791 $block_parsed[$key]['attrs']['currentPostId'] = 'widgets';
792 $widget_blocks[$widgetBlockId]['content'] = serialize_blocks($block_parsed);
793 update_option('widget_block', str_replace('u0022', '\u0022', $widget_blocks));
794 } else {
795 $blocks[$key]['attrs']['currentPostId'] = $postId;
796 wp_update_post(array(
797 'ID' => $postId,
798 'post_content' => str_replace('u0022', '\u0022', serialize_blocks($blocks))
799 ));
800 }
801 }
802
803 /**
804 * Blocks Content Start
805 *
806 * @since v.1.0.0
807 * @return STRING
808 */
809 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds=[], $ultp_current_unique_posts=[] , $widgetBlockId='', $exclude_post_id = '') {
810 foreach ($blocks as $key => $value) {
811 if ($blockName == $value['blockName']) {
812 if ($value['attrs']['blockId'] == $blockId) {
813 // if(!$value['attrs']['currentPostId']) {
814 // $this->update_block_attr( $postId, $blocks, $key, $widgetBlockId );
815 // }
816 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
817 $value['attrs']['paged'] = $paged;
818 if ($builder) {
819 $value['attrs']['builder'] = $builder;
820 }
821 if ($postId) {
822 $attr['current_post'] = $postId;
823 if(get_post_type($postId) == 'ultp_builder' && !$builder){
824 $attr['current_post'] = $exclude_post_id;
825 }
826 }
827 if (isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique']) {
828 $value['attrs']['loadMoreQueryUnique'] = $ultp_uniqueIds;
829 $ultp_uniqueIds[$value['attrs']['queryUnique']] = array_diff( $ultp_uniqueIds[$value['attrs']['queryUnique']], $ultp_current_unique_posts );
830 $value['attrs']['savedQueryUnique'] = $ultp_uniqueIds;
831 $value['attrs']['ultp_current_unique_posts'] = $ultp_current_unique_posts;
832 }
833 if(isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] && ( $value['attrs']['paginationType'] == 'loadMore' || $value['attrs']['paginationType'] == 'navigation') && isset($ultp_uniqueIds) && !isset($ultp_current_unique_posts)) {
834 die();
835 }
836
837 if($filterValue) {
838 $value['attrs']['queryTaxValue'] = json_encode(array($filterValue));
839 $value['attrs']['queryTax'] = $filterType;
840 $value['attrs']['checkFilter'] = true;
841 }
842 // Exclude Current Post From Pagination
843 if($exclude_post_id){
844 $queryArr = json_decode( $value['attrs']['queryExclude']);
845 $queryArr[] = array(
846 'value' => $exclude_post_id,
847 'title' => ''
848 );
849 $value['attrs']['queryExclude'] = json_encode($queryArr);
850 }
851 $attr = array_merge($attr, $value['attrs']);
852 echo $this->all_blocks[$blockRaw]->content($attr, true); //phpcs:ignore
853 die();
854 }
855 }
856 if (!empty($value['innerBlocks'])) {
857 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, $exclude_post_id);
858 }
859 }
860 }
861
862 /**
863 * WordPress Plugin Notice
864 *
865 * @since v.2.6.4
866 * @return NULL
867 */
868 public function in_plugin_settings_update_message() {
869 $response = wp_remote_get(
870 'https://plugins.svn.wordpress.org/ultimate-post/trunk/readme.txt', array(
871 'method' => 'GET'
872 ));
873
874 if ( is_wp_error( $response ) || $response['response']['code'] != 200 ) {
875 return;
876 }
877
878 $changelog_lines = preg_split("/(\r\n|\n|\r)/", $response['body']);
879
880 $is_copy = false;
881 $current_tag = '';
882 $tag_text = 'Stable tag:';
883 if (!empty($changelog_lines)) {
884 echo '<hr style="border-color:#dba617;"/>';
885 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>';
886 echo '<hr style="border-color:#dba617;"/>';
887 echo '<ul style="max-height:200px;overflow:scroll;">';
888 foreach ($changelog_lines as $key => $line) {
889 // Get Current Vesion
890 if ($current_tag == '') {
891 if (strpos($line, $tag_text) !== false) {
892 $current_tag = trim(str_replace($tag_text, '', $line));
893 }
894 } else {
895 if ($is_copy) {
896 if (strpos($line, '= '.ULTP_VER) !== false) {
897 break;
898 }
899 if (!empty($line)) {
900 if (strpos($line, '= ') !== false) {
901 echo '<li style="color:#50575e;font-weight:bold;"><br/>'.esc_html($line).'</li>';
902 } else {
903 echo '<li>'.esc_html($line).'</li>';
904 }
905 }
906 } else {
907 if (strpos($line, '= '.$current_tag) !== false) { // Current Version
908 $is_copy = true;
909 echo '<li style="color:#50575e;font-weight:bold;">'.esc_html($line).'</li>';
910 }
911 }
912 }
913 }
914 echo '</ul>';
915 }
916 }
917
918 /**
919 * Check Plugin Upgrade
920 *
921 * @since 2.4.3
922 *
923 * @return void
924 */
925 public function plugin_upgrade_completed() {
926 if (ultimate_post()->get_setting('init_setup') != 'yes') {
927 ultimate_post()->set_setting('init_setup', 'yes');
928 }
929 }
930
931 /**
932 * Search Result Data Showing
933 *
934 * @since V.2.9.10
935 * @param STRING | Search Query
936 * @return ARRAY | Search Result ( Post )
937 */
938 public function ultp_get_search_result() {
939 $result = ultimate_post()->get_search_data( isset($_POST['data'])?sanitize_text_field($_POST['data']):''); //phpcs:disable WordPress.Security.NonceVerification.Missing
940 return wp_send_json_success( [
941 'result_list' => $result
942 ] );
943 }
944 }