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

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