| @@ -18,8 +18,10 @@ | ||
| 18 | 18 | use SingletonTrait; |
| 19 | 19 | |
| 20 | 20 | private $yaymail_hook_surfix = null; |
| 21 | 21 | |
| 22 | + private $yay_wp_hook_surfix = null; | |
| 23 | + | |
| 22 | 24 | /** |
| 23 | 25 | * Constructor |
| 24 | 26 | */ |
| 25 | 27 | protected function __construct() { |
| @@ -29,14 +31,19 @@ | ||
| 29 | 31 | /** |
| 30 | 32 | * Initialize hooks when class init |
| 31 | 33 | */ |
| 32 | 34 | 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'; | |
| 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(); | |
| 36 | 41 | } |
| 37 | - | |
| 38 | - // Register Menu | |
| 42 | + $wp_platform = \YayMail\Platform\PlatformRegistry::get( 'yaymagic-email-builder' ); | |
| 43 | + if ( $wp_platform ) { | |
| 44 | + $this->yay_wp_hook_surfix = $wp_platform->hook_suffix(); | |
| 45 | + } | |
| 39 | 46 | add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ], 30 ); |
| 40 | 47 | add_filter( 'mce_external_plugins', [ $this, 'register_wp_editor_plugins_script' ] ); |
| 41 | 48 | |
| 42 | 49 | // Add Column YayMail Customizer on Setting email of WooCommerce (only when WC is active) |
| @@ -49,32 +56,38 @@ | ||
| 49 | 56 | add_action( 'admin_enqueue_scripts', [ $this, 'fix_conflict_plugins_styles' ], PHP_INT_MAX ); |
| 50 | 57 | } |
| 51 | 58 | |
| 52 | 59 | /** |
| 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 | 60 | * Enqueue scripts using in settings page |
| 61 | 61 | */ |
| 62 | 62 | 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 | + } | |
| 63 | 69 | |
| 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'; | |
| 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 | + } | |
| 71 | 76 | |
| 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 | + | |
| 72 | 85 | return $plugin_array; |
| 73 | 86 | } |
| 74 | 87 | |
| 75 | 88 | public function admin_enqueue_scripts( $hook_suffix ) { |
| 76 | - if ( in_array( $hook_suffix, [ $this->yaymail_hook_surfix ], true ) ) { | |
| 89 | + if ( in_array( $hook_suffix, [ $this->yaymail_hook_surfix, $this->yay_wp_hook_surfix ], true ) ) { | |
| 77 | 90 | do_action( 'yaymail_before_enqueue_settings_page_scripts' ); |
| 78 | 91 | // Enqueue script here |
| 79 | 92 | YayMailViteApp::get_instance()->enqueue_entry( 'yaymail-main.tsx', [ 'react', 'react-dom', 'wp-i18n' ] ); |
| 80 | 93 | add_action( 'yaymail_after_enqueue_scripts', [ $this, 'localize_js_vars' ] ); |
| @@ -89,9 +102,11 @@ | ||
| 89 | 102 | /** |
| 90 | 103 | * Register localize data |
| 91 | 104 | */ |
| 92 | 105 | public function localize_js_vars() { |
| 93 | - if ( yaymail_is_wc_installed() ) { | |
| 106 | + $screen = get_current_screen(); | |
| 107 | + $current_platform = \YayMail\Platform\PlatformRegistry::from_screen( $screen ); | |
| 108 | + if ( $screen->id === $this->yaymail_hook_surfix ) { | |
| 94 | 109 | $_wc_emails = wc()->mailer()->emails; |
| 95 | 110 | |
| 96 | 111 | // override template base for wc emails |
| 97 | 112 | foreach ( $_wc_emails as $email ) { |
| @@ -168,21 +183,43 @@ | ||
| 168 | 183 | '"Lucida Console", Monaco, monospace', |
| 169 | 184 | '"Outfit", "DM Sans", sans-serif', |
| 170 | 185 | '"Kodchasan", system-ui, sans-serif', |
| 171 | 186 | '"Fraunces", serif', |
| 187 | + '"Rethink Sans","Helvetica Neue",Helvetica,Roboto,Arial,sans-serif', | |
| 172 | 188 | ], |
| 173 | 189 | 'social_icons' => Localize::get_social_icons_data(), |
| 174 | 190 | 'revision_limit' => RevisionController::YAYMAIL_TEMPLATE_REVISION_LIMIT, |
| 175 | - 'global_headers_footers' => Localize::get_global_headers_footers(), | |
| 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 "yaymagic-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 | + 'yaymagic-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 | + ), | |
| 176 | 213 | 'section_templates' => SectionTemplateService::get_instance()->get_list_data(), |
| 177 | 214 | 'patterns' => PatternService::get_instance()->get_list_data(), |
| 178 | 215 | ], |
| 179 | 216 | 'colors' => [ |
| 180 | 217 | 'default_background_color' => YAYMAIL_COLOR_BACKGROUND_DEFAULT, |
| 181 | - 'default_text_link_color' => YAYMAIL_COLOR_WC_DEFAULT, | |
| 218 | + 'default_text_link_color' => ( $current_platform && 'yaymagic-email-builder' === $current_platform->key() ) ? YAYMAIL_COLOR_WP_DEFAULT : YAYMAIL_COLOR_WC_DEFAULT, | |
| 182 | 219 | 'default_content_background_color' => YAYMAIL_COLOR_CONTENT_BACKGROUND_DEFAULT, |
| 183 | 220 | 'default_content_text_color' => YAYMAIL_COLOR_CONTENT_TEXT_DEFAULT, |
| 184 | - 'default_title_color' => YAYMAIL_COLOR_TITLE_DEFAULT, | |
| 221 | + 'default_title_color' => ( $current_platform && 'yaymagic-email-builder' === $current_platform->key() ) ? YAYMAIL_COLOR_WP_DEFAULT : YAYMAIL_COLOR_TITLE_DEFAULT, | |
| 185 | 222 | ], |
| 186 | 223 | 'smtp' => [ |
| 187 | 224 | 'link_detail' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp§ion=description&TB_iframe=true&width=600&height=800' ), |
| 188 | 225 | 'setting' => admin_url( 'admin.php?page=yaysmtp' ), |
| @@ -187,8 +224,9 @@ | ||
| 187 | 224 | 'link_detail' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp§ion=description&TB_iframe=true&width=600&height=800' ), |
| 188 | 225 | 'setting' => admin_url( 'admin.php?page=yaysmtp' ), |
| 189 | 226 | 'is_active' => Helpers::check_plugin_installed( 'yaysmtp/yay-smtp.php' ) || Helpers::check_plugin_installed( 'yaysmtp-pro/yay-smtp.php' ), |
| 190 | 227 | ], |
| 228 | + 'translate_integrations' => Localize::get_translate_integrations(), | |
| 191 | 229 | 'reviewed' => boolval( get_option( 'yaymail_review' ) ), |
| 192 | 230 | 'ghf_tour' => get_option( 'yaymail_ghf_tour', 'initial' ), |
| 193 | 231 | 'test_email_address' => get_option( 'yaymail_default_email_test', wp_get_current_user()->user_email ), |
| 194 | 232 | 'site_title' => get_option( 'blogname' ), |
| @@ -197,13 +235,11 @@ | ||
| 197 | 235 | 'is_critical_migration_required' => MigrationModel::get_instance()->check_if_critical_migration_required(), |
| 198 | 236 | 'supported_plugins' => SupportedPlugins::get_instance()->get_slug_name_supported_plugins(), |
| 199 | 237 | 'show_multi_select_notice' => get_option( 'yaymail_show_multi_select_notice', 'yes' ), |
| 200 | 238 | '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 | - ], | |
| 239 | + 'ghf_disallowed_element_types' => yaymail_get_ghf_disallowed_element_types(), | |
| 240 | + 'platform' => $current_platform ? $current_platform->key() : 'yaymail', | |
| 241 | + 'version' => yaymail_version(), | |
| 206 | 242 | 'woocommerce_email_styles' => $this->get_scoped_woocommerce_email_styles(), |
| 207 | 243 | ], |
| 208 | 244 | apply_filters( 'yaymail_additional_localized_variables', [] ) |
| 209 | 245 | ) |
| @@ -255,9 +291,9 @@ | ||
| 255 | 291 | if ( ! function_exists( 'get_current_screen' ) ) { |
| 256 | 292 | return; |
| 257 | 293 | } |
| 258 | 294 | $screen = get_current_screen(); |
| 259 | - if ( $this->yaymail_hook_surfix === $screen->id ) { | |
| 295 | + if ( in_array( $screen->id, [ $this->yaymail_hook_surfix, $this->yay_wp_hook_surfix ], true ) ) { | |
| 260 | 296 | wp_dequeue_style( 'real-media-library-lite-rml' ); |
| 261 | 297 | wp_dequeue_script( 'real-media-library-lite-rml' ); |
| 262 | 298 | wp_dequeue_style( 'real-media-library-rml' ); |
| 263 | 299 | wp_dequeue_script( 'real-media-library-rml' ); |