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

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