PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.4.0
EmailKit – Email Customizer for WooCommerce & WP v1.4.0
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / MetaField / StyleLoad.php

StyleLoad.php in EmailKit – Email Customizer for WooCommerce & WP 1.4.0, at includes/Admin/MetaField/StyleLoad.php

138 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\MetaField;
4
5 defined('ABSPATH') || exit;
6
7 use EmailKit;
8
9 class StyleLoad
10 {
11 private $emailKit;
12
13 public function __construct()
14 {
15 add_action('init', function () {
16 add_action('wp_enqueue_scripts', [$this, 'addEnqueue']);
17 });
18 }
19
20
21 public function addEnqueue()
22 {
23 $this->builder_data();
24
25 ?>
26
27 <script id="__NEXT_DATA__" type="application/json">
28 {
29 "props": {
30 "pageProps": {}
31 },
32 "page": "/",
33 "query": {},
34 "buildId": "BNHEjAAqfCFPc8hjndtt6",
35 "assetPrefix": ".",
36 "nextExport": true,
37 "autoExport": true,
38 "isFallback": false
39 }
40 </script>
41 <?php
42
43
44
45 // $response = wp_remote_get(EMAILKIT_URL . 'build/build-manifest.json');
46
47 // if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) {
48 // $json_data = wp_remote_retrieve_body($response);
49 // $json_data = json_decode($json_data, true);
50
51 // if('' ==$json_data || !is_array($json_data)) {
52 // return;
53 // }
54 // if ($json_data && is_array($json_data)) {
55
56 // $scripts = $json_data["js"];
57 // $styles = $json_data["css"];
58
59 // foreach ($scripts as $index => $script) {
60 // wp_enqueue_script("emailkit-js" . $index, EMAILKIT_URL . $script, ['wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data'], EMAILKIT_VERSION, true);
61 // }
62 // foreach ($styles as $index => $style) {
63 // wp_enqueue_style("emailkit-css" . $index, EMAILKIT_URL . $style, [], EMAILKIT_VERSION);
64 // }
65 // }
66 // }
67
68 wp_enqueue_script("emailkit-js", EMAILKIT_URL . 'dist/app.js', ['wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data'], EMAILKIT_VERSION, true);
69 wp_enqueue_style("emailkit-css", EMAILKIT_URL . 'dist/app.css', [], EMAILKIT_VERSION);
70 if (is_admin()) {
71 wp_enqueue_style('emailkit-admin-style', EMAILKIT_URL . 'assets/dist/admin/styles/email-builder-navbar.css', [], EMAILKIT_VERSION);
72 }
73 }
74
75 public function builder_data()
76 {
77 //add_filter('show_admin_bar', '__return_false');
78
79 // Remove all WordPress actions
80 //remove_all_actions('wp_head');
81 remove_all_actions('wp_print_styles');
82 /* remove_all_actions('wp_print_head_scripts');
83 remove_all_actions('wp_footer');
84
85 // Handle `wp_enqueue_scripts`
86 remove_all_actions('wp_enqueue_scripts');
87 remove_all_actions('after_wp_tiny_mce');
88
89 // Handle `wp_head`
90 add_action('wp_head', 'wp_enqueue_scripts', 1);
91 add_action('wp_head', 'wp_print_styles', 8);
92 add_action('wp_head', 'wp_print_head_scripts', 9);
93 add_action('wp_head', 'wp_site_icon');
94
95
96 // Handle `wp_footer`
97 add_action('wp_footer', 'wp_print_footer_scripts', 20);
98 add_action('wp_footer', 'wp_auth_check_html', 30); */
99
100
101 // Hello Elementor theme style conflict with emailkit
102
103 if ( get_template() == 'hello-elementor' ) {
104
105 wp_dequeue_style('hello-elementor');
106 }
107
108
109 $_nonce = wp_create_nonce('wp_rest');
110 $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
111 $config = [
112 'version' => EMAILKIT_VERSION,
113 'restNonce' => esc_attr($_nonce),
114 'siteUrl' => esc_url(get_site_url()),
115 'assetsUrl' => esc_url(EMAILKIT_URL . 'assets/'),
116 'baseApi' => esc_url(get_rest_url(null, 'emailkit/v1/')),
117 'baseUrl' => esc_url(EMAILKIT_URL),
118 'adminUrl' => esc_url(admin_url()),
119 'adminEmail' => get_option('admin_email'),
120 'post_id' => $post_id,
121 'template_status' => get_post_meta($post_id,'emailkit_template_status',true),
122 'template_type' => get_post_meta($post_id,'emailkit_template_type',true),
123 'email_type' => get_post_meta($post_id,'emailkit_email_type',true),
124 ];
125
126
127
128
129 ?>
130 <script>
131 localStorage.removeItem('editorState');
132 window.emailKit = window.emailKit ?? {};
133 window.emailKit.config = <?php echo wp_json_encode($config); ?>;
134 </script>
135 <?php
136 }
137 }
138