PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.0
YayMail – WooCommerce Email Customizer v4.4.0
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Engine / Backend / SettingsPage.php

SettingsPage.php in YayMail – WooCommerce Email Customizer 4.4.0, at src/Engine/Backend/SettingsPage.php

263 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Engine\Backend;
4
5 use YayMail\Controllers\RevisionController;
6 use YayMail\TemplatePatterns\PatternService;
7 use YayMail\Models\MigrationModel;
8 use YayMail\SupportedPlugins;
9 use YayMail\TemplatePatterns\SectionTemplateService;
10 use YayMail\Utils\SingletonTrait;
11 use YayMail\Utils\YayMailViteApp;
12 use YayMail\Utils\Localize;
13 use YayMail\Utils\Helpers;
14 /**
15 * YayMail Page
16 */
17 class SettingsPage {
18 use SingletonTrait;
19
20 private $yaymail_hook_surfix = null;
21
22 /**
23 * Constructor
24 */
25 protected function __construct() {
26 $this->init_hooks();
27 }
28
29 /**
30 * Initialize hooks when class init
31 */
32 protected function init_hooks() {
33 // Submenu is registered by YayCommerce AdminShell (YaymailPluginAdapter); keep hook id for enqueue/screen checks.
34 if ( defined( 'YAYMAIL_PREFIX' ) ) {
35 $this->yaymail_hook_surfix = 'yaycommerce_page_' . YAYMAIL_PREFIX . '-settings';
36 }
37
38 // Register Menu
39 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ], 30 );
40 add_filter( 'mce_external_plugins', [ $this, 'register_wp_editor_plugins_script' ] );
41
42 // Add Column YayMail Customizer on Setting email of WooCommerce (only when WC is active)
43 if ( yaymail_is_wc_installed() ) {
44 add_filter( 'woocommerce_email_setting_columns', [ $this, 'woocommerce_email_setting_columns' ] );
45 add_action( 'woocommerce_email_setting_column_yaymail_customizer', [ $this, 'woocommerce_email_setting_column_yaymail_customizer' ] );
46 }
47
48 // Fix conflict plugins styles in Settings page
49 add_action( 'admin_enqueue_scripts', [ $this, 'fix_conflict_plugins_styles' ], PHP_INT_MAX );
50 }
51
52 /**
53 * Render the settings page
54 */
55 public function render_yaymail_page() {
56 include_once YAYMAIL_PLUGIN_PATH . 'templates/pages/settings.php';
57 }
58
59 /**
60 * Enqueue scripts using in settings page
61 */
62 public function register_wp_editor_plugins_script( $plugin_array ) {
63
64 $plugin_array['advlist'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/advlist/plugin.min.js';
65 $plugin_array['autolink'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/autolink/plugin.min.js';
66 $plugin_array['searchreplace'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/searchreplace/plugin.min.js';
67 $plugin_array['code'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/code/plugin.min.js';
68 $plugin_array['visualblocks'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/visualblocks/plugin.min.js';
69 $plugin_array['table'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/table/plugin.min.js';
70 $plugin_array['insertdatetime'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/insertdatetime/plugin.min.js';
71
72 return $plugin_array;
73 }
74
75 public function admin_enqueue_scripts( $hook_suffix ) {
76 if ( in_array( $hook_suffix, [ $this->yaymail_hook_surfix ], true ) ) {
77 do_action( 'yaymail_before_enqueue_settings_page_scripts' );
78 // Enqueue script here
79 YayMailViteApp::get_instance()->enqueue_entry( 'yaymail-main.tsx', [ 'react', 'react-dom', 'wp-i18n' ] );
80 add_action( 'yaymail_after_enqueue_scripts', [ $this, 'localize_js_vars' ] );
81
82 wp_enqueue_media();
83 wp_enqueue_editor();
84 wp_enqueue_script( 'accounting' );
85 do_action( 'yaymail_after_enqueue_settings_page_scripts' );
86 }
87 }
88
89 /**
90 * Register localize data
91 */
92 public function localize_js_vars() {
93 if ( yaymail_is_wc_installed() ) {
94 $_wc_emails = wc()->mailer()->emails;
95
96 // override template base for wc emails
97 foreach ( $_wc_emails as $email ) {
98 $reflector = new \ReflectionClass( $email );
99 $email->template_base = $reflector->getFileName();
100 unset( $reflector );
101 }
102
103 $_wc_emails = array_map(
104 function( $email ) {
105 return (object) [
106 'id' => $email->id,
107 'title' => $email->title,
108 'enabled' => $email->enabled,
109 'description' => $email->description,
110 'template_base' => $email->template_base,
111 'recipient' => $email->recipient,
112 'content_type' => $email->get_content_type(),
113 'setting_page_url' => Helpers::yaymail_get_url_email_setting_page( $email->id ),
114 ];
115 },
116 $_wc_emails
117 );
118 } else {
119 $_wc_emails = [];
120 }//end if
121
122 wp_localize_script(
123 'module/yaymail/yaymail-main.tsx',
124 'yaymailData',
125 array_merge(
126 [
127 'is_rtl' => is_rtl(),
128 'urls' => [
129 'vite_dynamic_base' => YAYMAIL_PLUGIN_URL . 'assets/dist/yaymail/',
130 'asset_url' => YAYMAIL_PLUGIN_URL . 'assets/images/',
131 'home_url' => home_url(),
132 'wc_placeholder_img_src' => function_exists( 'wc_placeholder_img_src' ) ? wc_placeholder_img_src() : '',
133 ],
134 'admin_ajax' => [
135 'url' => admin_url( 'admin-ajax.php' ),
136 'nonce' => wp_create_nonce( 'yaymail_frontend_nonce' ),
137 ],
138 'rest_path' => [
139 'root' => esc_url_raw( rest_url() ),
140 'base' => YAYMAIL_REST_NAMESPACE,
141 'nonce' => wp_create_nonce( 'wp_rest' ),
142 ],
143 'shared' => [
144 'util_functions' => [],
145 'stores' => [],
146 'core_components' => [],
147 'activated_addons' => Localize::get_activated_addons(),
148 ],
149 'list_orders' => Localize::get_list_orders(),
150 'i18n' => apply_filters(
151 'yaymail_translations',
152 []
153 ),
154 'builder' => [
155 'font_families' => [
156 '"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif',
157 'Georgia, serif',
158 '"Times New Roman", Times, Serif',
159 'Arial, Helvetica, sans-serif',
160 '"Arial Black", Gadget, sans-serif',
161 '"Comic Sans MS", cursive, sans-serif',
162 'Tahoma, Geneva, sans-serif',
163 '"Trebuchet MS", Helvetica, sans-serif',
164 'Verdana, Geneva, sans-serif',
165 '"Courier New", Courier, monospace',
166 '"Lucida Console", Monaco, monospace',
167 ],
168 'social_icons' => Localize::get_social_icons_data(),
169 'revision_limit' => RevisionController::YAYMAIL_TEMPLATE_REVISION_LIMIT,
170 'global_headers_footers' => Localize::get_global_headers_footers(),
171 'section_templates' => SectionTemplateService::get_instance()->get_list_data(),
172 'patterns' => PatternService::get_instance()->get_list_data(),
173 ],
174 'colors' => [
175 'default_background_color' => YAYMAIL_COLOR_BACKGROUND_DEFAULT,
176 'default_text_link_color' => YAYMAIL_COLOR_WC_DEFAULT,
177 'default_content_background_color' => YAYMAIL_COLOR_CONTENT_BACKGROUND_DEFAULT,
178 'default_content_text_color' => YAYMAIL_COLOR_CONTENT_TEXT_DEFAULT,
179 'default_title_color' => YAYMAIL_COLOR_TITLE_DEFAULT,
180 ],
181 'smtp' => [
182 'link_detail' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp&section=description&TB_iframe=true&width=600&height=800' ),
183 'setting' => admin_url( 'admin.php?page=yaysmtp' ),
184 'is_active' => Helpers::check_plugin_installed( 'yaysmtp/yay-smtp.php' ) || Helpers::check_plugin_installed( 'yaysmtp-pro/yay-smtp.php' ),
185 ],
186 'reviewed' => boolval( get_option( 'yaymail_review' ) ),
187 'ghf_tour' => get_option( 'yaymail_ghf_tour', 'initial' ),
188 'test_email_address' => get_option( 'yaymail_default_email_test', wp_get_current_user()->user_email ),
189 'site_title' => get_option( 'blogname' ),
190 // TODO: legacy: use get_user_meta
191 'wc_emails' => $_wc_emails,
192 'is_critical_migration_required' => MigrationModel::get_instance()->check_if_critical_migration_required(),
193 'supported_plugins' => SupportedPlugins::get_instance()->get_slug_name_supported_plugins(),
194 'show_multi_select_notice' => get_option( 'yaymail_show_multi_select_notice', 'yes' ),
195 'viewed_new_elements' => ! empty( get_option( 'yaymail_viewed_new_elements', [] ) ) ? get_option( 'yaymail_viewed_new_elements' ) : [],
196 'is_yaymail_loader' => function_exists( 'YayMail\\init' ),
197 'addons_platform' => [
198 'has_wc_customizer' => Helpers::is_yaymail_woocommerce_core_active(),
199 'has_wp_customizer' => Helpers::is_yaymail_wp_active(),
200 ],
201 'woocommerce_email_styles' => $this->get_scoped_woocommerce_email_styles(),
202 ],
203 apply_filters( 'yaymail_additional_localized_variables', [] )
204 )
205 );
206 }
207
208 private function get_scoped_woocommerce_email_styles() {
209 if ( ! function_exists( 'WC' ) ) {
210 return '';
211 }
212
213 $raw_styles = wp_unslash( wc_get_template_html( 'emails/email-styles.php' ) );
214 return Helpers::scope_css_block( $raw_styles, '.yaymail-customizer-template-section' );
215 }
216
217 /**
218 * Add new column to action column
219 */
220 public function woocommerce_email_setting_columns( $array ) {
221 if ( isset( $array['actions'] ) ) {
222 unset( $array['actions'] );
223 return array_merge(
224 $array,
225 [
226 'yaymail_customizer' => '',
227 'actions' => '',
228 ]
229 );
230 }
231 return $array;
232 }
233
234 /**
235 * Add link to setting column
236 */
237 public function woocommerce_email_setting_column_yaymail_customizer( $email ) {
238 $email_id = $email->id;
239 if ( 'yith-coupon-email-system' === $email->id ) {
240 if ( class_exists( 'YayMailYITHWooCouponEmailSystem\templateDefault\DefaultCouponEmailSystem' ) ) {
241 $email_id = 'YWCES_register';
242 }
243 }
244
245 echo '<td class="wc-email-settings-table-template">
246 <a class="button alignright" target="_blank" href="' . esc_attr( admin_url( 'admin.php?page=yaymail-settings#/customizer' ) ) . '?template=' . esc_attr( $email_id ) . '">' . esc_html( __( 'Customize with YayMail', 'yaymail' ) ) . '</a></td>';
247 }
248
249 public function fix_conflict_plugins_styles() {
250 if ( ! function_exists( 'get_current_screen' ) ) {
251 return;
252 }
253 $screen = get_current_screen();
254 if ( $this->yaymail_hook_surfix === $screen->id ) {
255 wp_dequeue_style( 'real-media-library-lite-rml' );
256 wp_dequeue_script( 'real-media-library-lite-rml' );
257 wp_dequeue_style( 'real-media-library-rml' );
258 wp_dequeue_script( 'real-media-library-rml' );
259 wp_dequeue_style( 'real-category-library-admin' );
260 }
261 }
262 }
263