PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.9.10
Post Grid Gutenberg Blocks – PostX v2.9.10
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Initialization.php

Initialization.php in Post Grid Gutenberg Blocks – PostX 2.9.10, at classes/Initialization.php

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