← All changes
|
includes/Admin/EmailKitEditor/EmailKitEditorInit.php
+96
-58
1.2.0
→
1.6.9
View file →
| @@ -1,58 +1,96 @@ | ||
| 1 | -<?php | |
| 2 | -namespace EmailKit\Admin\EmailKitEditor; | |
| 3 | - | |
| 4 | -use EmailKit\Admin\MetaField\StyleLoad; | |
| 5 | - | |
| 6 | -defined('ABSPATH') || exit('No direct script access allowed!'); | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * EmailKitEditorInit | |
| 10 | - * | |
| 11 | - * @since 1.0.0 | |
| 12 | - */ | |
| 13 | - | |
| 14 | -class EmailKitEditorInit | |
| 15 | -{ | |
| 16 | - | |
| 17 | - public function __construct() | |
| 18 | - { | |
| 19 | - if(!current_user_can( 'manage_options' )){ | |
| 20 | - return; | |
| 21 | - } | |
| 22 | - $post_id = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL | |
| 23 | - $action = isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL | |
| 24 | - $post_type = get_post_type($post_id); | |
| 25 | - | |
| 26 | - if (empty($post_id) || $action != 'emailkit-builder' || $post_type != 'emailkit') { | |
| 27 | - return; | |
| 28 | - } | |
| 29 | - | |
| 30 | - new StyleLoad(); | |
| 31 | - add_action('wp_loaded', [$this, 'add_editor_template']); | |
| 32 | - } | |
| 33 | - | |
| 34 | - public function add_editor_template() | |
| 35 | - { | |
| 36 | - ?> | |
| 37 | - <!DOCTYPE html> | |
| 38 | - <html> | |
| 39 | - <head> | |
| 40 | - <?php wp_head(); ?> | |
| 41 | - <meta charSet="utf-8" /> | |
| 42 | - <meta name="viewport" content="width=device-width" /> | |
| 43 | - <meta name="next-head-count" content="2" /> | |
| 44 | - </head> | |
| 45 | - | |
| 46 | - <body class="<?php body_class(['post-'.get_the_ID()]); ?>"> | |
| 47 | - | |
| 48 | - <?php | |
| 49 | - require_once EMAILKIT_PATH . '/build/server/pages/editor.php'; | |
| 50 | - wp_footer(); | |
| 51 | - ?> | |
| 52 | - | |
| 53 | - </body> | |
| 54 | - </html> | |
| 55 | - <?php | |
| 56 | - exit(); | |
| 57 | - } | |
| 58 | -} | |
| 1 | +<?php | |
| 2 | +namespace EmailKit\Admin\EmailKitEditor; | |
| 3 | + | |
| 4 | +use EmailKit\Admin\MetaField\StyleLoad; | |
| 5 | + | |
| 6 | +defined('ABSPATH') || exit('No direct script access allowed!'); | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * EmailKitEditorInit | |
| 10 | + * | |
| 11 | + * @since 1.0.0 | |
| 12 | + */ | |
| 13 | + | |
| 14 | +class EmailKitEditorInit | |
| 15 | +{ | |
| 16 | + | |
| 17 | + public function __construct() | |
| 18 | + { | |
| 19 | + if(!current_user_can( 'manage_options' )){ | |
| 20 | + return; | |
| 21 | + } | |
| 22 | + | |
| 23 | + $post_id = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL | |
| 24 | + $action = isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL | |
| 25 | + $post_type = get_post_type($post_id); | |
| 26 | + | |
| 27 | + if (empty($post_id) || $action != 'emailkit-builder' || $post_type != 'emailkit') { | |
| 28 | + return; | |
| 29 | + } | |
| 30 | + add_action('init', function () use($post_id) { | |
| 31 | + $dep = \EmailKit\Admin\Dependency::check(get_post_meta($post_id,'emailkit_email_type', true)); | |
| 32 | + | |
| 33 | + if(true !== $dep){ | |
| 34 | + wp_die( | |
| 35 | + sprintf( | |
| 36 | + /* translators: 1: dependency action label, e.g. "Install WooCommerce". 2: "Check here" link to the plugin page. */ | |
| 37 | + esc_html__( 'Need to %1$s %2$s', 'emailkit' ), | |
| 38 | + esc_html( $dep['label'] ?? '' ), | |
| 39 | + "<a href='" . esc_url( $dep['url'] ?? '' ) . "'>" . esc_html__( 'Check here', 'emailkit' ) . "</a>" | |
| 40 | + ), | |
| 41 | + esc_html__( 'Need to activate plugin', 'emailkit' ) | |
| 42 | + ); | |
| 43 | + } | |
| 44 | + }); | |
| 45 | + | |
| 46 | + new StyleLoad(); | |
| 47 | + add_action('wp_loaded', [$this, 'add_editor_template']); | |
| 48 | + } | |
| 49 | + | |
| 50 | + | |
| 51 | + public function add_editor_template() | |
| 52 | + { | |
| 53 | + | |
| 54 | + if(is_plugin_active('uafrica-shipping/uafrica-shipping.php') || ( get_template() == 'entry' )){ | |
| 55 | + // Check if WooCommerce is active and initialize session if needed | |
| 56 | + if (class_exists('WooCommerce') && function_exists('WC')) { | |
| 57 | + if (is_null(WC()->session) && !headers_sent()) { | |
| 58 | + WC()->session = new \WC_Session_Handler(); | |
| 59 | + WC()->session->init(); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + } | |
| 63 | + ?> | |
| 64 | + <!DOCTYPE html> | |
| 65 | + <html> | |
| 66 | + <head> | |
| 67 | + <?php wp_head(); ?> | |
| 68 | + <meta charSet="utf-8" /> | |
| 69 | + <meta name="viewport" content="width=device-width" /> | |
| 70 | + <meta name="next-head-count" content="2" /> | |
| 71 | + </head> | |
| 72 | + | |
| 73 | + <body class="<?php | |
| 74 | + // Temporarily remove all body_class filters so third-party plugins that call | |
| 75 | + // admin-only functions (e.g. get_current_screen) cannot cause fatal errors | |
| 76 | + // in this custom editor context. WordPress core classes are still applied. | |
| 77 | + global $wp_filter; | |
| 78 | + $saved_body_class_filter = isset( $wp_filter['body_class'] ) ? clone $wp_filter['body_class'] : null; | |
| 79 | + remove_all_filters( 'body_class' ); | |
| 80 | + body_class( [ 'post-' . get_the_ID() ] ); | |
| 81 | + if ( $saved_body_class_filter !== null ) { | |
| 82 | + $wp_filter['body_class'] = $saved_body_class_filter; | |
| 83 | + } | |
| 84 | + ?>"> | |
| 85 | + | |
| 86 | + <?php | |
| 87 | + require_once EMAILKIT_PATH . '/dist/editor.php'; | |
| 88 | + wp_footer(); | |
| 89 | + ?> | |
| 90 | + | |
| 91 | + </body> | |
| 92 | + </html> | |
| 93 | + <?php | |
| 94 | + exit(); | |
| 95 | + } | |
| 96 | +} | |