| @@ -1,10 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace YayMail; |
| 3 | 3 | |
| 4 | -use YayMail\Elements\ElementsLoader; | |
| 4 | +use YayMail\Utils\Helpers; | |
| 5 | 5 | use YayMail\Emails\EmailsLoader; |
| 6 | -use YayMail\Engine\ActDeact; | |
| 7 | 6 | use YayMail\Engine\Backend\SettingsPage; |
| 8 | 7 | use YayMail\Engine\RestAPI; |
| 9 | 8 | use YayMail\Integrations\IntegrationsLoader; |
| 10 | 9 | use YayMail\PostTypes\TemplatePostType; |
| @@ -13,8 +12,9 @@ | ||
| 13 | 12 | use YayMail\TemplatePatterns\PatternsLoader; |
| 14 | 13 | use YayMail\TemplatePatterns\SectionTemplatesLoader; |
| 15 | 14 | use YayMail\PreviewEmail\PreviewEmailsLoader; |
| 16 | 15 | use YayMail\Notices\NoticeMain; |
| 16 | +use YayMail\SocialIcons\SocialIconEndpoint; | |
| 17 | 17 | use YayMail\TemplateLibrary\LibraryTemplateSchema; |
| 18 | 18 | use YayMail\TemplateLibrary\TemplateLibraryLoader; |
| 19 | 19 | /** |
| 20 | 20 | * YayMail Plugin Initializer |
| @@ -28,8 +28,13 @@ | ||
| 28 | 28 | /** |
| 29 | 29 | * The Constructor that load the engine classes |
| 30 | 30 | */ |
| 31 | 31 | protected function __construct() { |
| 32 | + // Procedural helpers (yaymail_version(), yaymail_is_wc_installed(), ...) are used by | |
| 33 | + // every hook callback below, so load them here rather than inside init_core(), whose | |
| 34 | + // hook is filterable and may run after init_modules(). | |
| 35 | + require_once Helpers::get_plugin_path() . 'src/Functions.php'; | |
| 36 | + | |
| 32 | 37 | I18n::get_instance(); |
| 33 | 38 | |
| 34 | 39 | /** |
| 35 | 40 | * Handle init core |
| @@ -48,9 +53,8 @@ | ||
| 48 | 53 | add_action( 'init', [ $this, 'init_modules' ] ); |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | 56 | public function init_core() { |
| 52 | - require_once YAYMAIL_PLUGIN_PATH . 'src/Functions.php'; | |
| 53 | 57 | do_action( 'yaymail_init_start' ); |
| 54 | 58 | |
| 55 | 59 | /** |
| 56 | 60 | * Core Integrations |
| @@ -57,9 +61,8 @@ | ||
| 57 | 61 | */ |
| 58 | 62 | IntegrationsLoader::get_instance(); |
| 59 | 63 | |
| 60 | 64 | EmailsLoader::get_instance(); |
| 61 | - ElementsLoader::get_instance(); | |
| 62 | 65 | ShortcodesLoader::get_instance(); |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | 68 | public function init_modules() { |
| @@ -76,10 +79,8 @@ | ||
| 76 | 79 | update_option( 'yaymail_version_backup', $version_current ); |
| 77 | 80 | } |
| 78 | 81 | } |
| 79 | 82 | |
| 80 | - ActDeact::get_instance(); | |
| 81 | - | |
| 82 | 83 | if ( yaymail_is_wc_installed() ) { |
| 83 | 84 | WooHandler::get_instance(); |
| 84 | 85 | } |
| 85 | 86 | |
| @@ -89,21 +90,24 @@ | ||
| 89 | 90 | |
| 90 | 91 | PreviewEmailsLoader::get_instance(); |
| 91 | 92 | |
| 92 | 93 | /** |
| 93 | - * Supported templates | |
| 94 | - */ | |
| 95 | - SupportedPlugins::get_instance(); | |
| 96 | - | |
| 97 | - /** | |
| 98 | 94 | * Core core filters |
| 99 | 95 | */ |
| 100 | 96 | |
| 101 | 97 | SectionTemplatesLoader::get_instance(); |
| 102 | 98 | PatternsLoader::get_instance(); |
| 103 | - TemplateLibraryLoader::get_instance(); | |
| 104 | - LibraryTemplateSchema::maybe_create_table(); | |
| 105 | 99 | |
| 100 | + // Template Library only ships WooCommerce order-email designs (Completed, | |
| 101 | + // RefundedOrder, NewOrder, ...). Skip its directory scan/class instantiation | |
| 102 | + // (41 files, ~23k lines) and the per-request "SHOW TABLES" check when | |
| 103 | + // WooCommerce isn't active -- it noticeably slows down every admin page load | |
| 104 | + // on WP-only (yaymagic-email-builder) sites for a feature they can't use. | |
| 105 | + if ( yaymail_is_wc_installed() ) { | |
| 106 | + TemplateLibraryLoader::get_instance(); | |
| 107 | + LibraryTemplateSchema::maybe_create_table(); | |
| 108 | + } | |
| 109 | + | |
| 106 | 110 | /** |
| 107 | 111 | * Initialize rest api |
| 108 | 112 | */ |
| 109 | 113 | RestAPI::get_instance(); |
| @@ -120,7 +124,34 @@ | ||
| 120 | 124 | * Notices |
| 121 | 125 | */ |
| 122 | 126 | NoticeMain::get_instance(); |
| 123 | 127 | |
| 128 | + /** | |
| 129 | + * Social icon dynamic tint endpoint | |
| 130 | + */ | |
| 131 | + SocialIconEndpoint::get_instance(); | |
| 132 | + | |
| 124 | 133 | do_action( 'yaymail_loaded' ); |
| 125 | 134 | } |
| 126 | -} | |
| 135 | + | |
| 136 | + public function current_yaymail_version() { | |
| 137 | + $version = 'yaymail/yaymail.php'; | |
| 138 | + if ( ! function_exists( 'is_plugin_active' ) ) { | |
| 139 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 140 | + } | |
| 141 | + | |
| 142 | + $yaymail_files = [ | |
| 143 | + 'yaymail/yaymail.php', | |
| 144 | + 'yaymail-pro/yaymail.php', | |
| 145 | + 'email-customizer-for-woocommerce/yaymail.php', | |
| 146 | + ]; | |
| 147 | + | |
| 148 | + foreach ( $yaymail_files as $file ) { | |
| 149 | + if ( is_plugin_active( $file ) || is_plugin_active_for_network( $file ) ) { | |
| 150 | + $version = $file; | |
| 151 | + break; | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + return $version; | |
| 156 | + } | |
| 157 | +} | |