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

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