PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.4
Post Grid Gutenberg Blocks – PostX v5.0.4
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 5.0.4, at classes/Initialization.php

607 lines 20.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Initialization Action.
5 *
6 * @package ULTP\ULTP_Initialization
7 * @since v.1.1.0
8 */
9
10 namespace ULTP;
11
12 defined( 'ABSPATH' ) || exit;
13
14 use ULTP\Includes\Durbin\Xpo;
15
16 /**
17 * Initialization class.
18 *
19 * Handles plugin initialization for Ultimate Post.
20 *
21 * @package ULTP\Initialization
22 * @since 4.0.0
23 */
24 class ULTP_Initialization {
25
26 /**
27 * Setup class.
28 *
29 * @since 4.0.0
30 * @return void No return value.
31 */
32 public function __construct() {
33
34 $this->compatibility_check();
35 $this->requires();
36 $this->include_addons();
37
38 add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ) ); // add body class in editor.
39 add_filter( 'body_class', array( $this, 'add_body_class' ) ); // add body class in front end.
40
41 add_action( 'wp', array( $this, 'popular_posts_tracker_callback' ) );
42 add_action( 'after_setup_theme', array( $this, 'add_image_size' ) );
43 add_filter( 'block_categories_all', array( $this, 'register_category_callback' ), 999999999, 2 ); // Block Category Register.
44
45 add_filter( 'safe_style_css', array( $this, 'ultp_handle_safe_style_css' ) ); // support for css used in svg icon.
46 add_filter( 'wp_kses_allowed_html', array( $this, 'ultp_handle_allowed_html' ), 99, 2 ); // support for svg icon used in list, row, icon block.
47
48 add_action( 'enqueue_block_editor_assets', array( $this, 'register_block_scripts_editor_area' ) ); // Only editor.
49 add_action( 'admin_enqueue_scripts', array( $this, 'register_option_panel_scripts_callback' ) ); // Option Panel.
50 register_activation_hook( ULTP_PATH . 'ultimate-post.php', array( $this, 'plugin_activation_hook' ) );
51 add_action( 'activated_plugin', array( $this, 'ultp_plugin_activation' ) ); // Plugin Activation Call.
52 }
53
54 /**
55 * Check plugin compatibility.
56 *
57 * @since v.1.0.0
58 * @return void
59 */
60 public function compatibility_check() {
61 require_once ULTP_PATH . 'classes/Compatibility.php';
62 new \ULTP\Compatibility();
63 }
64
65 /**
66 * Load all required classes.
67 *
68 * @since v.1.0.0
69 * @return void No return value.
70 */
71 public function requires() {
72 require_once ULTP_PATH . 'classes/Styles.php';
73 require_once ULTP_PATH . 'classes/Options.php';
74 require_once ULTP_PATH . 'classes/REST_API.php';
75 require_once ULTP_PATH . 'classes/Caches.php';
76 require_once ULTP_PATH . 'classes/Importer.php';
77 require_once ULTP_PATH . 'classes/Dashboard.php';
78 require_once ULTP_PATH . 'classes/Blocks.php';
79 new \ULTP\REST_API();
80 new \ULTP\Options();
81 new \ULTP\Caches();
82 new \ULTP\Styles();
83 new \ULTP\Importer();
84 new \ULTP\Dashboard();
85 new \ULTP\Blocks();
86
87 require_once ULTP_PATH . 'includes/durbin/class-durbin-client.php';
88 require_once ULTP_PATH . 'includes/durbin/class-xpo.php';
89 require_once ULTP_PATH . 'includes/deactive/class-deactive.php';
90 require_once ULTP_PATH . 'includes/notice/class-notice.php';
91 require_once ULTP_PATH . 'includes/durbin/class-our-plugins.php';
92 new \ULTP\Includes\Deactive\Deactive();
93 new \ULTP\Includes\notice\Notice();
94 new \ULTP\Includes\Durbin\OurPlugins();
95 }
96
97 /**
98 * Include all addons from the addons directory.
99 *
100 * @since v.1.0.0
101 * @return void
102 */
103 public function include_addons() {
104 $addons_dir = array_filter( glob( ULTP_PATH . 'addons/*' ), 'is_dir' );
105 if ( count( $addons_dir ) > 0 ) {
106 foreach ( $addons_dir as $key => $value ) {
107 $addon_dir_name = str_replace( dirname( $value ) . '/', '', $value );
108 $file_name = ULTP_PATH . 'addons/' . $addon_dir_name . '/init.php';
109 if ( file_exists( $file_name ) ) {
110 include_once $file_name;
111 }
112 }
113 }
114 }
115
116
117 /**
118 * Add admin body class in editor.
119 *
120 * @since v.3.1.6
121 * @param STRING $classes The existing admin body classes.
122 * @return STRING Modified admin body classes.
123 */
124 public function add_admin_body_class( $classes ) {
125 $classes .= ' postx-admin-page ';
126 return $classes;
127 }
128
129 /**
130 * Add body class in front end.
131 *
132 * @since v.3.1.6
133 * @param ARRAY $classes The existing body classes.
134 * @return ARRAY Modified body classes.
135 */
136 public function add_body_class( $classes ) {
137 $classes[] = 'postx-page';
138 return $classes;
139 }
140
141 /**
142 * Post view counter for every post.
143 *
144 * @since v.1.0.0
145 * @param INT $post_id The post ID.
146 * @return NULL No return value.
147 */
148 public function popular_posts_tracker_callback( $post_id ) {
149 if ( ! is_single() ) {
150 return;
151 }
152 global $post;
153 $post_id = isset( $post->ID ) ? $post->ID : '';
154 $isEnable = apply_filters( 'ultp_view_cookies', true );
155 // add_filter( 'ultp_view_cookies', '__return_false' );
156 $cookies_disable = ultimate_post()->get_setting( 'disable_view_cookies' );
157 if ( $post_id && $isEnable && $cookies_disable != 'yes' ) {
158 $has_cookie = isset( $_COOKIE[ 'ultp_view_' . $post_id ] ) ? sanitize_text_field( $_COOKIE[ 'ultp_view_' . $post_id ] ) : false;
159 if ( ! $has_cookie ) {
160 $count = (int) get_post_meta( $post_id, '__post_views_count', true );
161 update_post_meta( $post_id, '__post_views_count', $count ? (int) $count + 1 : 1 );
162 setcookie( 'ultp_view_' . $post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
163 }
164 }
165 }
166
167 /**
168 * Set image sizes for the plugin.
169 *
170 * @since v.1.0.0
171 * @return void No return value.
172 */
173 public function add_image_size() {
174 $size_disable = ultimate_post()->get_setting( 'disable_image_size' );
175 if ( $size_disable != 'yes' ) {
176 add_image_size( 'ultp_layout_landscape_large', 1200, 800, true );
177 add_image_size( 'ultp_layout_landscape', 870, 570, true );
178 add_image_size( 'ultp_layout_portrait', 600, 900, true );
179 add_image_size( 'ultp_layout_square', 600, 600, true );
180 }
181 }
182
183 /**
184 * Block categories initialization.
185 *
186 * @since v.1.0.0
187 * @param ARRAY $categories The block categories.
188 * @param ARRAY $post The post object.
189 * @return ARRAY Modified block categories.
190 */
191 public function register_category_callback( $categories, $post ) {
192 $attr = array(
193 array(
194 'slug' => 'ultimate-post',
195 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' ),
196 ),
197 array(
198 'slug' => 'postx-site-builder',
199 'title' => __( 'PostX Site Builder', 'ultimate-post' ),
200 ),
201 );
202 return array_merge( $attr, $categories );
203 }
204
205 /**
206 * Add support for CSS to use SVG.
207 *
208 * @since 4.0.0
209 * @param ARRAY $styles The allowed CSS styles.
210 * @return ARRAY Modified allowed CSS styles.
211 */
212 public function ultp_handle_safe_style_css( $styles ) {
213 if ( ! is_multisite() && ! current_user_can( 'edit_posts' ) ) {
214 return $styles;
215 }
216 return array_merge(
217 $styles,
218 array(
219 'opacity',
220 // for SVG gradients.
221 // 'stop-opacity',
222 // 'stop-color',
223 )
224 );
225 }
226
227 /**
228 * Add support for HTML tags to use SVG.
229 *
230 * @since 4.0.0
231 * @param ARRAY $tags The allowed HTML tags.
232 * @param STRING $context The context for allowed HTML.
233 * @return ARRAY Modified allowed HTML tags.
234 */
235 public function ultp_handle_allowed_html( $tags, $context ) {
236 if ( 'post' !== $context && ! is_multisite() && ! current_user_can( 'edit_posts' ) ) {
237 return $tags;
238 }
239 if ( ! isset( $tags['svg'] ) ) {
240 $tags['svg'] = array_merge(
241 array(
242 'xmlns' => true,
243 // 'xmlns:xlink' => true,
244 // 'xlink:href' => true,
245 // 'xml:id' => true,
246 // 'xlink:title' => true,
247 // 'xml:space' => true,
248 'viewbox' => true,
249 'enable-background' => true,
250 'version' => true,
251 'preserveaspectratio' => true,
252 'fill' => true,
253 )
254 );
255 }
256 if ( ! isset( $tags['path'] ) ) {
257 $tags['path'] = array(
258 'd' => true,
259 'stroke' => true,
260 'stroke-miterlimit' => true,
261 'data-original' => true,
262 'class' => true,
263 'transform' => true,
264 'style' => true,
265 'opacity' => true,
266 'fill' => true,
267 );
268 }
269 if ( ! isset( $tags['g'] ) ) {
270 $tags['g'] = array(
271 'transform' => true,
272 'clip-path' => true,
273 );
274 }
275 if ( ! isset( $tags['clippath'] ) ) {
276 $tags['clippath'] = array();
277 }
278 if ( ! isset( $tags['defs'] ) ) {
279 $tags['defs'] = array();
280 }
281 if ( ! isset( $tags['rect'] ) ) {
282 $tags['rect'] = array(
283 'rx' => true,
284 'height' => true,
285 'width' => true,
286 'transform' => true,
287 'x' => true,
288 'fill' => true,
289 );
290 }
291 if ( ! isset( $tags['circle'] ) ) {
292 $tags['circle'] = array(
293 'cx' => true,
294 'cy' => true,
295 'transform' => true,
296 'r' => true,
297 );
298 }
299 if ( ! isset( $tags['polygon'] ) ) {
300 $tags['polygon'] = array(
301 'points' => true,
302 );
303 }
304 if ( ! isset( $tags['lineargradient'] ) ) {
305 $tags['lineargradient'] = array(
306 'gradienttransform' => true,
307 'id' => true,
308 );
309 }
310 if ( ! isset( $tags['stop'] ) ) {
311 $tags['stop'] = array(
312 'offset' => true,
313 'stop-color' => true,
314 'style' => true,
315 'stop-opacity' => true,
316 );
317 }
318 return $tags;
319 }
320
321 /**
322 * Plugin activation callback.
323 *
324 * @since v.1.1.0
325 * @param STRING $plugin The plugin file path.
326 * @return NULL No return value.
327 */
328 public function ultp_plugin_activation( $plugin ) {
329 if ( wp_doing_ajax() ) {
330 return;
331 }
332 if ( $plugin == 'ultimate-post/ultimate-post.php' ) {
333 if ( wp_doing_ajax() || is_network_admin() || isset( $_GET['activate-multi'] ) || isset( $_POST['action'] ) && 'activate-selected' == $_POST['action'] ) {
334 return;
335 }
336 if ( ultimate_post()->get_setting( 'init_setup' ) != 'yes' ) {
337 ultimate_post()->set_setting( 'init_setup', 'yes' );
338 exit(wp_safe_redirect(admin_url('admin.php?page=ultp-setup-wizard'))); //phpcs:ignore
339 } else {
340 exit(wp_safe_redirect(admin_url('admin.php?page=ultp-settings#home'))); //phpcs:ignore
341 }
342 }
343 }
344
345 /**
346 * Enqueue option panel CSS and JS scripts.
347 *
348 * @since v.1.0.0
349 * @return void No return value.
350 */
351 public function register_option_panel_scripts_callback() {
352 $is_active = ultimate_post()->is_lc_active();
353 $license_key = Xpo::get_lc_key();
354 $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // @codingStandardsIgnoreLine
355 $post_type = get_post_type();
356
357 wp_enqueue_style( 'wp-color-picker' );
358 wp_enqueue_script( 'wp-color-picker' );
359
360 wp_enqueue_script( 'ultp-option-script', ULTP_URL . 'assets/js/ultp-option.js', array( 'jquery' ), ULTP_VER, true );
361 wp_enqueue_style( 'ultp-option-style', ULTP_URL . 'assets/css/ultp-option.css', array(), ULTP_VER );
362 wp_localize_script(
363 'ultp-option-script',
364 'ultp_option_panel',
365 array(
366 'url' => ULTP_URL,
367 'version' => ULTP_VER,
368 'active' => $is_active,
369 'security' => wp_create_nonce( 'ultp-nonce' ),
370 'ajax' => admin_url( 'admin-ajax.php' ),
371 'settings' => ultimate_post()->get_setting(),
372 'post_type' => $post_type,
373 'saved_template_url' => admin_url( 'admin.php?page=ultp-settings#saved-templates' ),
374 )
375 );
376
377 if ( $post_type == 'ultp_custom_font' ) {
378 $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
379 if ( $font_settings == 'true' ) {
380 wp_enqueue_media();
381 }
382 }
383
384 /* === Installation Wizard === */
385 if ( $_page == 'ultp-setup-wizard' ) {
386 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 );
387 wp_set_script_translations( 'ultp-initial-setup-script', 'ultimate-post', ULTP_PATH . 'languages/' );
388 }
389
390 /* === Builder And Setting Pannel === */
391 if ( get_post_type( get_the_ID() ) == 'ultp_builder' ) {
392 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 );
393 wp_localize_script(
394 'ultp-conditions-script',
395 'ultp_condition',
396 array(
397 'url' => ULTP_URL,
398 'active' => $is_active,
399 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
400 )
401 );
402 wp_set_script_translations( 'ultp-conditions-script', 'ultimate-post', ULTP_PATH . 'languages/' );
403 }
404
405 /* === Dashboard === */
406 if ( $_page == 'ultp-settings' ) {
407 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 );
408 $user_info = get_userdata( get_current_user_id() );
409 wp_localize_script(
410 'ultp-dashboard-script',
411 'ultp_dashboard_pannel',
412 array_merge(
413 array(
414 'ajax' => admin_url( 'admin-ajax.php' ),
415 'security' => wp_create_nonce( 'ultp-nonce' ),
416 'url' => ULTP_URL,
417 'active' => $is_active,
418 'license' => $license_key,
419 'settings' => ultimate_post()->get_setting(),
420 'addons_settings' => apply_filters( 'ultp_settings', array() ),
421 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
422 'version' => ULTP_VER,
423 'setup_wizard_link' => admin_url( 'admin.php?page=ultp-setup-wizard' ),
424 'is_free' => ! $is_active,
425 'user_email' => wp_get_current_user()->user_email,
426 'home_url' => home_url(),
427 'generalDiscount' => get_transient( 'ultp_generalDiscount' ),
428 'helloBar' => Xpo::get_transient_without_cache( 'ultp_helloBar' ),
429 'userInfo' => array(
430 'name' => $user_info->first_name ? $user_info->first_name . ( $user_info->last_name ? ' ' . $user_info->last_name : '' ) : $user_info->user_login,
431 'email' => $user_info->user_email,
432 ),
433 ),
434 Xpo::get_wow_products_details()
435 )
436 );
437 wp_set_script_translations( 'ultp-dashboard-script', 'ultimate-post', ULTP_PATH . 'languages/' );
438 }
439 }
440
441 /**
442 * Enqueue backend CSS and JS scripts for the block editor.
443 *
444 * @since v.1.0.0
445 * @return void No return value.
446 */
447 public function register_block_scripts_editor_area() {
448 ultimate_post()->register_scripts_common();
449 global $pagenow;
450 $depends = 'wp-editor';
451 if ( $pagenow === 'widgets.php' ) {
452 $depends = 'wp-edit-widgets';
453 }
454 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 );
455 wp_enqueue_style( 'ultp-blocks-editor-css', ULTP_URL . 'assets/css/blocks.editor.css', array(), ULTP_VER );
456 if ( is_rtl() ) {
457 wp_enqueue_style( 'ultp-blocks-editor-rtl-css', ULTP_URL . 'assets/css/rtl.css', array(), ULTP_VER );
458 }
459 $is_active = ultimate_post()->is_lc_active();
460 $post_type = get_post_type();
461
462 // Custom Font Support Added
463 $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
464 $custom_fonts = array();
465 if ( $font_settings == 'true' ) {
466 $args = array(
467 'post_type' => 'ultp_custom_font',
468 'post_status' => 'publish',
469 'numberposts' => -1,
470 'order' => 'ASC',
471 );
472 $posts = get_posts( $args );
473 if ( $posts ) {
474 foreach ( $posts as $post ) {
475 setup_postdata( $post );
476 $font = get_post_meta( $post->ID, '__font_settings', true );
477
478 if ( $font ) {
479 array_push(
480 $custom_fonts,
481 array(
482 'title' => $post->post_title,
483 'font' => $font,
484 )
485 );
486 }
487 }
488 wp_reset_postdata();
489 }
490 }
491
492 wp_localize_script(
493 'ultp-blocks-editor-script',
494 'ultp_data',
495 array(
496 'url' => ULTP_URL,
497 'ajax' => admin_url( 'admin-ajax.php' ),
498 'security' => wp_create_nonce( 'ultp-nonce' ),
499 'hide_import_btn' => ultimate_post()->get_setting( 'hide_import_btn' ),
500 'premium_link' => Xpo::generate_utm_link(),
501 'license' => $is_active ? Xpo::get_lc_key() : '',
502 'active' => $is_active,
503 'archive' => ultimate_post()->is_archive_builder(),
504 'settings' => ultimate_post()->get_setting(),
505 'post_type' => $post_type == 'premade' ? 'ultp_builder' : $post_type, // premade used for ultp.wpxpo.com
506 'date_format' => get_option( 'date_format' ),
507 'time_format' => get_option( 'time_format' ),
508 'blog' => get_current_blog_id(),
509 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
510 'category_url' => admin_url( 'edit-tags.php?taxonomy=category' ),
511 'disable_image_size' => ultimate_post()->get_setting( 'disable_image_size' ),
512 'dark_logo' => get_option( 'ultp_site_dark_logo' ) ? get_option( 'ultp_site_dark_logo' ) : false,
513 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
514 'custom_fonts' => $custom_fonts,
515 )
516 );
517 wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
518 }
519
520
521 /**
522 * Fire when plugin is first installed.
523 *
524 * @since v.1.0.0
525 * @return void No return value.
526 */
527 public function plugin_activation_hook() {
528 $data = get_option( 'ultp_options', array() );
529 $currentDate = new \DateTime();
530 $currentDate->setTime( 0, 0, 0, 0 );
531 $init_data = array(
532 'preloader_style' => 'style1',
533 'preloader_color' => '#037fff',
534 'container_width' => '1140',
535 'hide_import_btn' => '',
536 'disable_image_size' => '',
537 'disable_view_cookies' => '',
538 'disable_google_font' => '',
539 'ultp_templates' => 'true',
540 'ultp_elementor' => 'true',
541 'ultp_table_of_content' => 'true',
542 'ultp_builder' => 'true',
543 'ultp_dynamic_content' => 'true',
544 'ultp_custom_font' => 'true',
545 'ultp_chatgpt' => 'true',
546 'post_grid_1' => 'yes',
547 'post_grid_2' => 'yes',
548 'post_grid_3' => 'yes',
549 'post_grid_4' => 'yes',
550 'post_grid_5' => 'yes',
551 'post_grid_6' => 'yes',
552 'post_grid_7' => 'yes',
553 'post_list_1' => 'yes',
554 'post_list_2' => 'yes',
555 'post_list_3' => 'yes',
556 'post_list_4' => 'yes',
557 'post_module_1' => 'yes',
558 'post_module_2' => 'yes',
559 'post_slider_1' => 'yes',
560 'post_slider_2' => 'yes',
561 'heading' => 'yes',
562 'image' => 'yes',
563 'taxonomy' => 'yes',
564 'wrapper' => 'yes',
565 'news_ticker' => 'yes',
566 'accordion' => 'yes',
567 'star_rating' => 'yes',
568 'youtube_gallery' => 'yes',
569 'builder_advance_post_meta' => 'yes',
570 'builder_archive_title' => 'yes',
571 'builder_author_box' => 'yes',
572 'builder_post_next_previous' => 'yes',
573 'builder_post_author_meta' => 'yes',
574 'builder_post_breadcrumb' => 'yes',
575 'builder_post_category' => 'yes',
576 'builder_post_comment_count' => 'yes',
577 'builder_post_comments' => 'yes',
578 'builder_post_content' => 'yes',
579 'builder_post_date_meta' => 'yes',
580 'builder_post_excerpt' => 'yes',
581 'builder_post_featured_image' => 'yes',
582 'builder_post_reading_time' => 'yes',
583 'builder_post_social_share' => 'yes',
584 'builder_post_tag' => 'yes',
585 'builder_post_title' => 'yes',
586 'builder_post_view_count' => 'yes',
587 'save_version' => wp_rand( 1, 1000 ),
588 'activated_date' => $currentDate->getTimestamp(),
589 );
590 if ( empty( $data ) ) {
591 update_option( 'ultp_options', $init_data );
592 $GLOBALS['ultp_settings'] = $init_data;
593 } else {
594 foreach ( $init_data as $key => $single ) {
595 if ( ! isset( $data[ $key ] ) ) {
596 $data[ $key ] = $single;
597 }
598 }
599 update_option( 'ultp_options', $data );
600 $GLOBALS['ultp_settings'] = $data;
601 }
602 if ( ! get_transient( 'wpxpo_installation_date' ) ) {
603 set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
604 }
605 }
606 }
607