PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.1
YayMail – WooCommerce Email Customizer v4.4.1
4.4.6 4.4.5 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 All 57 releases
yaymail / src / Engine / Backend / SettingsPage.php

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

268 lines 12.7 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 $plugin_work = Helpers::get_plugin_work_info();
123
124 wp_localize_script(
125 'module/yaymail/yaymail-main.tsx',
126 'yaymailData',
127 array_merge(
128 [
129 'is_rtl' => is_rtl(),
130 'urls' => [
131 'vite_dynamic_base' => YAYMAIL_PLUGIN_URL . 'assets/dist/yaymail/',
132 'asset_url' => YAYMAIL_PLUGIN_URL . 'assets/images/',
133 'home_url' => home_url(),
134 'wc_placeholder_img_src' => function_exists( 'wc_placeholder_img_src' ) ? wc_placeholder_img_src() : '',
135 ],
136 'admin_ajax' => [
137 'url' => admin_url( 'admin-ajax.php' ),
138 'nonce' => wp_create_nonce( 'yaymail_frontend_nonce' ),
139 ],
140 'rest_path' => [
141 'root' => esc_url_raw( rest_url() ),
142 'base' => YAYMAIL_REST_NAMESPACE,
143 'nonce' => wp_create_nonce( 'wp_rest' ),
144 ],
145 'shared' => [
146 'util_functions' => [],
147 'stores' => [],
148 'core_components' => [],
149 'activated_addons' => Localize::get_activated_addons(),
150 ],
151 'list_orders' => Localize::get_list_orders(),
152 'i18n' => apply_filters(
153 'yaymail_translations',
154 []
155 ),
156 'builder' => [
157 'font_families' => [
158 '"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif',
159 'Georgia, serif',
160 '"Times New Roman", Times, Serif',
161 'Arial, Helvetica, sans-serif',
162 '"Arial Black", Gadget, sans-serif',
163 '"Comic Sans MS", cursive, sans-serif',
164 'Tahoma, Geneva, sans-serif',
165 '"Trebuchet MS", Helvetica, sans-serif',
166 'Verdana, Geneva, sans-serif',
167 '"Courier New", Courier, monospace',
168 '"Lucida Console", Monaco, monospace',
169 '"Outfit", "DM Sans", sans-serif',
170 '"Kodchasan", system-ui, sans-serif',
171 '"Fraunces", serif',
172 ],
173 'social_icons' => Localize::get_social_icons_data(),
174 'revision_limit' => RevisionController::YAYMAIL_TEMPLATE_REVISION_LIMIT,
175 'global_headers_footers' => Localize::get_global_headers_footers(),
176 'section_templates' => SectionTemplateService::get_instance()->get_list_data(),
177 'patterns' => PatternService::get_instance()->get_list_data(),
178 ],
179 'colors' => [
180 'default_background_color' => YAYMAIL_COLOR_BACKGROUND_DEFAULT,
181 'default_text_link_color' => YAYMAIL_COLOR_WC_DEFAULT,
182 'default_content_background_color' => YAYMAIL_COLOR_CONTENT_BACKGROUND_DEFAULT,
183 'default_content_text_color' => YAYMAIL_COLOR_CONTENT_TEXT_DEFAULT,
184 'default_title_color' => YAYMAIL_COLOR_TITLE_DEFAULT,
185 ],
186 'smtp' => [
187 'link_detail' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp&section=description&TB_iframe=true&width=600&height=800' ),
188 'setting' => admin_url( 'admin.php?page=yaysmtp' ),
189 'is_active' => Helpers::check_plugin_installed( 'yaysmtp/yay-smtp.php' ) || Helpers::check_plugin_installed( 'yaysmtp-pro/yay-smtp.php' ),
190 ],
191 'reviewed' => boolval( get_option( 'yaymail_review' ) ),
192 'ghf_tour' => get_option( 'yaymail_ghf_tour', 'initial' ),
193 'test_email_address' => get_option( 'yaymail_default_email_test', wp_get_current_user()->user_email ),
194 'site_title' => get_option( 'blogname' ),
195 // TODO: legacy: use get_user_meta
196 'wc_emails' => $_wc_emails,
197 'is_critical_migration_required' => MigrationModel::get_instance()->check_if_critical_migration_required(),
198 'supported_plugins' => SupportedPlugins::get_instance()->get_slug_name_supported_plugins(),
199 'show_multi_select_notice' => get_option( 'yaymail_show_multi_select_notice', 'yes' ),
200 'viewed_new_elements' => ! empty( get_option( 'yaymail_viewed_new_elements', [] ) ) ? get_option( 'yaymail_viewed_new_elements' ) : [],
201 'is_yaymail_loader' => function_exists( 'YayMail\\init' ),
202 'addons_platform' => [
203 'has_wc_customizer' => $plugin_work['yaymail'],
204 'has_wp_customizer' => $plugin_work['yay-wp-email-customizer'],
205 ],
206 'woocommerce_email_styles' => $this->get_scoped_woocommerce_email_styles(),
207 ],
208 apply_filters( 'yaymail_additional_localized_variables', [] )
209 )
210 );
211 }
212
213 private function get_scoped_woocommerce_email_styles() {
214 if ( ! function_exists( 'WC' ) ) {
215 return '';
216 }
217
218 $raw_styles = wp_unslash( wc_get_template_html( 'emails/email-styles.php' ) );
219 return Helpers::scope_css_block( $raw_styles, '.yaymail-customizer-template-section' );
220 }
221
222 /**
223 * Add new column to action column
224 */
225 public function woocommerce_email_setting_columns( $array ) {
226 if ( isset( $array['actions'] ) ) {
227 unset( $array['actions'] );
228 return array_merge(
229 $array,
230 [
231 'yaymail_customizer' => '',
232 'actions' => '',
233 ]
234 );
235 }
236 return $array;
237 }
238
239 /**
240 * Add link to setting column
241 */
242 public function woocommerce_email_setting_column_yaymail_customizer( $email ) {
243 $email_id = $email->id;
244 if ( 'yith-coupon-email-system' === $email->id ) {
245 if ( class_exists( 'YayMailYITHWooCouponEmailSystem\templateDefault\DefaultCouponEmailSystem' ) ) {
246 $email_id = 'YWCES_register';
247 }
248 }
249
250 echo '<td class="wc-email-settings-table-template">
251 <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>';
252 }
253
254 public function fix_conflict_plugins_styles() {
255 if ( ! function_exists( 'get_current_screen' ) ) {
256 return;
257 }
258 $screen = get_current_screen();
259 if ( $this->yaymail_hook_surfix === $screen->id ) {
260 wp_dequeue_style( 'real-media-library-lite-rml' );
261 wp_dequeue_script( 'real-media-library-lite-rml' );
262 wp_dequeue_style( 'real-media-library-rml' );
263 wp_dequeue_script( 'real-media-library-rml' );
264 wp_dequeue_style( 'real-category-library-admin' );
265 }
266 }
267 }
268