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

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