PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.3
YayMail – WooCommerce Email Customizer v4.3.3
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
← All changes | src/Engine/Backend/SettingsPage.php +85 -110 trunk4.3.3 View file →
@@ -18,10 +18,8 @@
18 18 use SingletonTrait;
19 19
20 20 private $yaymail_hook_surfix = null;
21 21
22 - private $yay_wp_hook_surfix = null;
23 -
24 22 /**
25 23 * Constructor
26 24 */
27 25 protected function __construct() {
@@ -31,27 +29,19 @@
31 29 /**
32 30 * Initialize hooks when class init
33 31 */
34 32 protected function init_hooks() {
35 - // Submenu is registered by YayCommerce AdminShell; keep each platform's
36 - // settings-screen hook id (sourced from the registered platform) for the
37 - // enqueue/screen checks below.
38 - $yaymail_platform = \YayMail\Platform\PlatformRegistry::get( 'yaymail' );
39 - if ( $yaymail_platform ) {
40 - $this->yaymail_hook_surfix = $yaymail_platform->hook_suffix();
41 - }
42 - $wp_platform = \YayMail\Platform\PlatformRegistry::get( 'email-builder' );
43 - if ( $wp_platform ) {
44 - $this->yay_wp_hook_surfix = $wp_platform->hook_suffix();
45 - }
33 + // Register Menu
34 + add_action( 'admin_menu', [ $this, 'add_yaymail_menu' ], YAYMAIL_MENU_PRIORITY );
46 35 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ], 30 );
36 +
37 + add_filter( 'plugin_action_links_' . YAYMAIL_PLUGIN_BASENAME, [ $this, 'plugin_action_links' ] );
38 + add_filter( 'plugin_row_meta', [ $this, 'add_support_and_docs_links' ], 10, 2 );
47 39 add_filter( 'mce_external_plugins', [ $this, 'register_wp_editor_plugins_script' ] );
48 40
49 - // Add Column YayMail Customizer on Setting email of WooCommerce (only when WC is active)
50 - if ( yaymail_is_wc_installed() ) {
51 - add_filter( 'woocommerce_email_setting_columns', [ $this, 'woocommerce_email_setting_columns' ] );
52 - add_action( 'woocommerce_email_setting_column_yaymail_customizer', [ $this, 'woocommerce_email_setting_column_yaymail_customizer' ] );
53 - }
41 + // Add Column YayMail Customizer on Setting email of WooCommerce
42 + add_filter( 'woocommerce_email_setting_columns', [ $this, 'woocommerce_email_setting_columns' ] );
43 + add_action( 'woocommerce_email_setting_column_yaymail_customizer', [ $this, 'woocommerce_email_setting_column_yaymail_customizer' ] );
54 44
55 45 // Fix conflict plugins styles in Settings page
56 46 add_action( 'admin_enqueue_scripts', [ $this, 'fix_conflict_plugins_styles' ], PHP_INT_MAX );
57 47 }
@@ -56,38 +46,48 @@
56 46 add_action( 'admin_enqueue_scripts', [ $this, 'fix_conflict_plugins_styles' ], PHP_INT_MAX );
57 47 }
58 48
59 49 /**
50 + * Register the YayMAil sub menu to WordPress YayCommerce menu.
51 + */
52 + public function add_yaymail_menu() {
53 + $menu_args = [
54 + 'parent_slug' => 'yaycommerce',
55 + 'page_title' => __( 'Email Builder Settings', 'yaymail' ),
56 + 'menu_title' => __( 'YayMail', 'yaymail' ),
57 + 'capability' => 'manage_woocommerce',
58 + 'menu_slug' => YAYMAIL_PREFIX . '-settings',
59 + 'function' => [ $this, 'render_yaymail_page' ],
60 + 'position' => 0,
61 + ];
62 + $this->yaymail_hook_surfix = add_submenu_page( $menu_args['parent_slug'], $menu_args['page_title'], $menu_args['menu_title'], $menu_args['capability'], $menu_args['menu_slug'], $menu_args['function'], $menu_args['position'] );
63 + }
64 +
65 + /**
66 + * Render the settings page
67 + */
68 + public function render_yaymail_page() {
69 + include_once YAYMAIL_PLUGIN_PATH . 'templates/pages/settings.php';
70 + }
71 +
72 + /**
60 73 * Enqueue scripts using in settings page
61 74 */
62 75 public function register_wp_editor_plugins_script( $plugin_array ) {
63 - // mce_external_plugins also runs on the frontend (e.g. Avada Live Builder
64 - // calling _WP_Editors::editor_settings() from wp_footer). get_current_screen()
65 - // is admin-only and is not defined there.
66 - if ( ! function_exists( 'get_current_screen' ) ) {
67 - return $plugin_array;
68 - }
69 76
70 - $plugin_url = YAYMAIL_PLUGIN_URL;
71 - $screen = get_current_screen();
72 - $yaymail_platform = \YayMail\Platform\PlatformRegistry::get( 'yaymail' );
73 - if ( ( ! $yaymail_platform || ! $screen || $screen->id !== $yaymail_platform->hook_suffix() ) && defined( 'YAYWP_PLUGIN_URL' ) ) {
74 - $plugin_url = YAYWP_PLUGIN_URL;
75 - }
77 + $plugin_array['advlist'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/advlist/plugin.min.js';
78 + $plugin_array['autolink'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/autolink/plugin.min.js';
79 + $plugin_array['searchreplace'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/searchreplace/plugin.min.js';
80 + $plugin_array['code'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/code/plugin.min.js';
81 + $plugin_array['visualblocks'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/visualblocks/plugin.min.js';
82 + $plugin_array['table'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/table/plugin.min.js';
83 + $plugin_array['insertdatetime'] = YAYMAIL_PLUGIN_URL . 'assets/scripts/wp-editor-plugins/insertdatetime/plugin.min.js';
76 84
77 - $plugin_array['advlist'] = $plugin_url . 'assets/scripts/wp-editor-plugins/advlist/plugin.min.js';
78 - $plugin_array['autolink'] = $plugin_url . 'assets/scripts/wp-editor-plugins/autolink/plugin.min.js';
79 - $plugin_array['searchreplace'] = $plugin_url . 'assets/scripts/wp-editor-plugins/searchreplace/plugin.min.js';
80 - $plugin_array['code'] = $plugin_url . 'assets/scripts/wp-editor-plugins/code/plugin.min.js';
81 - $plugin_array['visualblocks'] = $plugin_url . 'assets/scripts/wp-editor-plugins/visualblocks/plugin.min.js';
82 - $plugin_array['table'] = $plugin_url . 'assets/scripts/wp-editor-plugins/table/plugin.min.js';
83 - $plugin_array['insertdatetime'] = $plugin_url . 'assets/scripts/wp-editor-plugins/insertdatetime/plugin.min.js';
84 -
85 85 return $plugin_array;
86 86 }
87 87
88 88 public function admin_enqueue_scripts( $hook_suffix ) {
89 - if ( in_array( $hook_suffix, [ $this->yaymail_hook_surfix, $this->yay_wp_hook_surfix ], true ) ) {
89 + if ( in_array( $hook_suffix, [ $this->yaymail_hook_surfix ], true ) && class_exists( 'WC_Emails' ) ) {
90 90 do_action( 'yaymail_before_enqueue_settings_page_scripts' );
91 91 // Enqueue script here
92 92 YayMailViteApp::get_instance()->enqueue_entry( 'yaymail-main.tsx', [ 'react', 'react-dom', 'wp-i18n' ] );
93 93 add_action( 'yaymail_after_enqueue_scripts', [ $this, 'localize_js_vars' ] );
@@ -102,40 +102,33 @@
102 102 /**
103 103 * Register localize data
104 104 */
105 105 public function localize_js_vars() {
106 - $screen = get_current_screen();
107 - $current_platform = \YayMail\Platform\PlatformRegistry::from_screen( $screen );
108 - if ( $screen->id === $this->yaymail_hook_surfix ) {
109 - $_wc_emails = wc()->mailer()->emails;
110 106
111 - // override template base for wc emails
112 - foreach ( $_wc_emails as $email ) {
113 - $reflector = new \ReflectionClass( $email );
114 - $email->template_base = $reflector->getFileName();
115 - unset( $reflector );
116 - }
107 + $_wc_emails = wc()->mailer()->emails;
117 108
118 - $_wc_emails = array_map(
119 - function( $email ) {
120 - return (object) [
121 - 'id' => $email->id,
122 - 'title' => $email->title,
123 - 'enabled' => $email->enabled,
124 - 'description' => $email->description,
125 - 'template_base' => $email->template_base,
126 - 'recipient' => $email->recipient,
127 - 'content_type' => $email->get_content_type(),
128 - 'setting_page_url' => Helpers::yaymail_get_url_email_setting_page( $email->id ),
129 - ];
130 - },
131 - $_wc_emails
132 - );
133 - } else {
134 - $_wc_emails = [];
135 - }//end if
109 + // override template base for wc emails
110 + foreach ( $_wc_emails as $email ) {
111 + $reflector = new \ReflectionClass( $email );
112 + $email->template_base = $reflector->getFileName();
113 + unset( $reflector );
114 + }
136 115
137 - $plugin_work = Helpers::get_plugin_work_info();
116 + $_wc_emails = array_map(
117 + function( $email ) {
118 + return (object) [
119 + 'id' => $email->id,
120 + 'title' => $email->title,
121 + 'enabled' => $email->enabled,
122 + 'description' => $email->description,
123 + 'template_base' => $email->template_base,
124 + 'recipient' => $email->recipient,
125 + 'content_type' => $email->get_content_type(),
126 + 'setting_page_url' => Helpers::yaymail_get_url_email_setting_page( $email->id ),
127 + ];
128 + },
129 + $_wc_emails
130 + );
138 131
139 132 wp_localize_script(
140 133 'module/yaymail/yaymail-main.tsx',
141 134 'yaymailData',
@@ -180,46 +173,18 @@
180 173 '"Trebuchet MS", Helvetica, sans-serif',
181 174 'Verdana, Geneva, sans-serif',
182 175 '"Courier New", Courier, monospace',
183 176 '"Lucida Console", Monaco, monospace',
184 - '"Outfit", "DM Sans", sans-serif',
185 - '"Kodchasan", system-ui, sans-serif',
186 - '"Fraunces", serif',
187 - '"Rethink Sans","Helvetica Neue",Helvetica,Roboto,Arial,sans-serif',
188 177 ],
189 178 'social_icons' => Localize::get_social_icons_data(),
190 179 'revision_limit' => RevisionController::YAYMAIL_TEMPLATE_REVISION_LIMIT,
191 - // Two compiled JS bundles still read global_headers_footers as a single
192 - // legacy { global_header_elements, global_footer_elements } object rather
193 - // than the per-language array Localize::get_global_headers_footers()
194 - // returns: (1) the "email-builder" (WP core mail) bundle -- confirmed
195 - // byte-identical to the free "yaymail" lite bundle, it never received the
196 - // multi-language upgrade -- and (2) the "yaymail" lite bundle itself when
197 - // YAYMAIL_LITE_LEGACY_GHF_SHAPE is set. The paid yaymail-pro /
198 - // email-customizer-for-woocommerce variants already expect the array.
199 - // Feeding the array shape to a legacy bundle leaves globalHeaderElements/
200 - // globalFooterElements undefined and crashes the customizer with "Cannot
201 - // read properties of undefined (reading 'find')"; feeding the legacy shape
202 - // to an array-expecting bundle breaks it with "global_headers_footers.find
203 - // is not a function". Keep both conditions -- don't collapse into version
204 - // checks, they gate an unrelated concern (see YAYWP_HOSTS_CORE above).
205 - 'global_headers_footers' => ( $current_platform && (
206 - 'email-builder' === $current_platform->key()
207 - || ( 'yaymail' === $current_platform->key() && defined( 'YAYMAIL_LITE_LEGACY_GHF_SHAPE' ) && YAYMAIL_LITE_LEGACY_GHF_SHAPE )
208 - ) )
209 - ? \YayMail\Models\TemplateModel::get_global_header_and_footer( '', $current_platform->ghf_option_key() )
210 - : Localize::get_global_headers_footers(
211 - $current_platform ? $current_platform->ghf_option_key() : 'yaymail_global_header_footer'
212 - ),
180 + 'global_headers_footers' => Localize::get_global_headers_footers(),
213 181 'section_templates' => SectionTemplateService::get_instance()->get_list_data(),
214 182 'patterns' => PatternService::get_instance()->get_list_data(),
215 183 ],
216 184 'colors' => [
217 - 'default_background_color' => YAYMAIL_COLOR_BACKGROUND_DEFAULT,
218 - 'default_text_link_color' => ( $current_platform && 'email-builder' === $current_platform->key() ) ? YAYMAIL_COLOR_WP_DEFAULT : YAYMAIL_COLOR_WC_DEFAULT,
219 - 'default_content_background_color' => YAYMAIL_COLOR_CONTENT_BACKGROUND_DEFAULT,
220 - 'default_content_text_color' => YAYMAIL_COLOR_CONTENT_TEXT_DEFAULT,
221 - 'default_title_color' => ( $current_platform && 'email-builder' === $current_platform->key() ) ? YAYMAIL_COLOR_WP_DEFAULT : YAYMAIL_COLOR_TITLE_DEFAULT,
185 + 'default_background_color' => YAYMAIL_COLOR_BACKGROUND_DEFAULT,
186 + 'default_text_link_color' => YAYMAIL_COLOR_WC_DEFAULT,
222 187 ],
223 188 'smtp' => [
224 189 'link_detail' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp&section=description&TB_iframe=true&width=600&height=800' ),
225 190 'setting' => admin_url( 'admin.php?page=yaysmtp' ),
@@ -224,9 +189,8 @@
224 189 'link_detail' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp&section=description&TB_iframe=true&width=600&height=800' ),
225 190 'setting' => admin_url( 'admin.php?page=yaysmtp' ),
226 191 'is_active' => Helpers::check_plugin_installed( 'yaysmtp/yay-smtp.php' ) || Helpers::check_plugin_installed( 'yaysmtp-pro/yay-smtp.php' ),
227 192 ],
228 - 'translate_integrations' => Localize::get_translate_integrations(),
229 193 'reviewed' => boolval( get_option( 'yaymail_review' ) ),
230 194 'ghf_tour' => get_option( 'yaymail_ghf_tour', 'initial' ),
231 195 'test_email_address' => get_option( 'yaymail_default_email_test', wp_get_current_user()->user_email ),
232 196 'site_title' => get_option( 'blogname' ),
@@ -235,11 +199,8 @@
235 199 'is_critical_migration_required' => MigrationModel::get_instance()->check_if_critical_migration_required(),
236 200 'supported_plugins' => SupportedPlugins::get_instance()->get_slug_name_supported_plugins(),
237 201 'show_multi_select_notice' => get_option( 'yaymail_show_multi_select_notice', 'yes' ),
238 202 'viewed_new_elements' => ! empty( get_option( 'yaymail_viewed_new_elements', [] ) ) ? get_option( 'yaymail_viewed_new_elements' ) : [],
239 - 'ghf_disallowed_element_types' => yaymail_get_ghf_disallowed_element_types(),
240 - 'platform' => $current_platform ? $current_platform->key() : 'yaymail',
241 - 'woocommerce_email_styles' => $this->get_scoped_woocommerce_email_styles(),
242 203 ],
243 204 apply_filters( 'yaymail_additional_localized_variables', [] )
244 205 )
245 206 );
@@ -244,15 +205,29 @@
244 205 )
245 206 );
246 207 }
247 208
248 - private function get_scoped_woocommerce_email_styles() {
249 - if ( ! function_exists( 'WC' ) ) {
250 - return '';
209 + /**
210 + * Add link to YayMail settings page & Go Pro in Plugin row
211 + */
212 + public function plugin_action_links( $links ) {
213 + $action_links = [
214 + 'settings' => '<a href="' . admin_url( 'admin.php?page=yaymail-settings' ) . '" aria-label="' . esc_attr__( 'View WooCommerce Email Builder', 'yaymail' ) . '">' . esc_html__( 'Start Customizing', 'yaymail' ) . '</a>',
215 + ];
216 + $links[] = '<a target="_blank" href="https://yaycommerce.com/yaymail-woocommerce-email-customizer/" style="color: #43B854; font-weight: bold">' . __( 'Go Pro', 'yaymail' ) . '</a>';
217 +
218 + return array_merge( $action_links, $links );
219 + }
220 +
221 + /**
222 + * Add extra plugin meta in Plugin row
223 + */
224 + public function add_support_and_docs_links( $plugin_meta, $plugin_file ) {
225 + if ( YAYMAIL_PLUGIN_BASENAME === $plugin_file ) {
226 + $plugin_meta[] = '<a target="_blank" href="https://docs.yaycommerce.com/yaymail/getting-started/introduction">' . esc_html__( 'Docs', 'yaymail' ) . '</a>';
227 + $plugin_meta[] = '<a target="_blank" href="https://yaycommerce.com/support/">' . esc_html__( 'Support', 'yaymail' ) . '</a>';
251 228 }
252 -
253 - $raw_styles = wp_unslash( wc_get_template_html( 'emails/email-styles.php' ) );
254 - return Helpers::scope_css_block( $raw_styles, '.yaymail-customizer-template-section' );
229 + return $plugin_meta;
255 230 }
256 231
257 232 /**
258 233 * Add new column to action column
@@ -290,9 +265,9 @@
290 265 if ( ! function_exists( 'get_current_screen' ) ) {
291 266 return;
292 267 }
293 268 $screen = get_current_screen();
294 - if ( in_array( $screen->id, [ $this->yaymail_hook_surfix, $this->yay_wp_hook_surfix ], true ) ) {
269 + if ( $this->yaymail_hook_surfix === $screen->id ) {
295 270 wp_dequeue_style( 'real-media-library-lite-rml' );
296 271 wp_dequeue_script( 'real-media-library-lite-rml' );
297 272 wp_dequeue_style( 'real-media-library-rml' );
298 273 wp_dequeue_script( 'real-media-library-rml' );