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

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