| 1 |
<?php |
| 2 |
namespace YayMail; |
| 3 |
|
| 4 |
use YayMail\Utils\Helpers; |
| 5 |
use YayMail\Elements\ElementsLoader; |
| 6 |
use YayMail\Emails\EmailsLoader; |
| 7 |
use YayMail\Engine\ActDeact; |
| 8 |
use YayMail\Engine\Backend\SettingsPage; |
| 9 |
use YayMail\Engine\RestAPI; |
| 10 |
use YayMail\Integrations\IntegrationsLoader; |
| 11 |
use YayMail\PostTypes\TemplatePostType; |
| 12 |
use YayMail\Shortcodes\ShortcodesLoader; |
| 13 |
use YayMail\Utils\SingletonTrait; |
| 14 |
use YayMail\TemplatePatterns\PatternsLoader; |
| 15 |
use YayMail\TemplatePatterns\SectionTemplatesLoader; |
| 16 |
use YayMail\PreviewEmail\PreviewEmailsLoader; |
| 17 |
use YayMail\Notices\NoticeMain; |
| 18 |
use YayMail\SocialIcons\SocialIconEndpoint; |
| 19 |
use YayMail\TemplateLibrary\LibraryTemplateSchema; |
| 20 |
use YayMail\TemplateLibrary\TemplateLibraryLoader; |
| 21 |
/** |
| 22 |
* YayMail Plugin Initializer |
| 23 |
* |
| 24 |
* @method static Initialize get_instance() |
| 25 |
*/ |
| 26 |
class Initialize { |
| 27 |
|
| 28 |
use SingletonTrait; |
| 29 |
|
| 30 |
/** |
| 31 |
* The Constructor that load the engine classes |
| 32 |
*/ |
| 33 |
protected function __construct() { |
| 34 |
I18n::get_instance(); |
| 35 |
|
| 36 |
/** |
| 37 |
* Handle init core |
| 38 |
* Emails, Templates, Elements, Shortcodes, Integrations |
| 39 |
* $hook_name => $priority |
| 40 |
*/ |
| 41 |
$initialization_core_hooks = [ |
| 42 |
apply_filters( 'yaymail_temp_init_hook_name', 'init' ) => 10, |
| 43 |
// Integrate for Mastercard Gateway plugin |
| 44 |
'woocommerce_api_mastercard_gateway' => 10, |
| 45 |
]; |
| 46 |
foreach ( $initialization_core_hooks as $hook => $priority ) { |
| 47 |
add_action( $hook, [ $this, 'init_core' ], $priority ?? 10 ); |
| 48 |
} |
| 49 |
|
| 50 |
add_action( 'init', [ $this, 'init_modules' ] ); |
| 51 |
} |
| 52 |
|
| 53 |
public function init_core() { |
| 54 |
require_once Utils\Helpers::get_plugin_path() . 'src/Functions.php'; |
| 55 |
do_action( 'yaymail_init_start' ); |
| 56 |
|
| 57 |
/** |
| 58 |
* Core Integrations |
| 59 |
*/ |
| 60 |
IntegrationsLoader::get_instance(); |
| 61 |
|
| 62 |
EmailsLoader::get_instance(); |
| 63 |
ElementsLoader::get_instance(); |
| 64 |
ShortcodesLoader::get_instance(); |
| 65 |
} |
| 66 |
|
| 67 |
public function init_modules() { |
| 68 |
|
| 69 |
$version_current = yaymail_version(); |
| 70 |
$version_old = get_option( 'yaymail_version' ); |
| 71 |
$version_current_backup = get_option( 'yaymail_version_backup' ); |
| 72 |
|
| 73 |
if ( $version_current !== $version_old && yaymail_is_wc_installed() ) { |
| 74 |
if ( $version_current_backup !== $version_current ) { |
| 75 |
\YayMail\Migrations\MainMigration::get_instance()->migrate(); |
| 76 |
|
| 77 |
update_option( 'yaymail_version', $version_current ); |
| 78 |
update_option( 'yaymail_version_backup', $version_current ); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
ActDeact::get_instance(); |
| 83 |
|
| 84 |
if ( yaymail_is_wc_installed() ) { |
| 85 |
WooHandler::get_instance(); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Preview Email loader |
| 90 |
*/ |
| 91 |
|
| 92 |
PreviewEmailsLoader::get_instance(); |
| 93 |
|
| 94 |
/** |
| 95 |
* Supported templates |
| 96 |
*/ |
| 97 |
SupportedPlugins::get_instance(); |
| 98 |
|
| 99 |
/** |
| 100 |
* Core core filters |
| 101 |
*/ |
| 102 |
|
| 103 |
SectionTemplatesLoader::get_instance(); |
| 104 |
PatternsLoader::get_instance(); |
| 105 |
|
| 106 |
// Template Library only ships WooCommerce order-email designs (Completed, |
| 107 |
// RefundedOrder, NewOrder, ...). Skip its directory scan/class instantiation |
| 108 |
// (41 files, ~23k lines) and the per-request "SHOW TABLES" check when |
| 109 |
// WooCommerce isn't active -- it noticeably slows down every admin page load |
| 110 |
// on WP-only (email-builder) sites for a feature they can't use. |
| 111 |
if ( yaymail_is_wc_installed() ) { |
| 112 |
TemplateLibraryLoader::get_instance(); |
| 113 |
LibraryTemplateSchema::maybe_create_table(); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Initialize rest api |
| 118 |
*/ |
| 119 |
RestAPI::get_instance(); |
| 120 |
|
| 121 |
/** |
| 122 |
* Initialize pages |
| 123 |
*/ |
| 124 |
SettingsPage::get_instance(); |
| 125 |
|
| 126 |
TemplatePostType::get_instance(); |
| 127 |
Ajax::get_instance(); |
| 128 |
|
| 129 |
/** |
| 130 |
* Notices |
| 131 |
*/ |
| 132 |
NoticeMain::get_instance(); |
| 133 |
|
| 134 |
/** |
| 135 |
* Social icon dynamic tint endpoint |
| 136 |
*/ |
| 137 |
SocialIconEndpoint::get_instance(); |
| 138 |
|
| 139 |
do_action( 'yaymail_loaded' ); |
| 140 |
} |
| 141 |
|
| 142 |
public function current_yaymail_version() { |
| 143 |
$version = 'yaymail/yaymail.php'; |
| 144 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 145 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 146 |
} |
| 147 |
|
| 148 |
$yaymail_files = [ |
| 149 |
'yaymail/yaymail.php', |
| 150 |
'yaymail-pro/yaymail.php', |
| 151 |
'email-customizer-for-woocommerce/yaymail.php', |
| 152 |
]; |
| 153 |
|
| 154 |
foreach ( $yaymail_files as $file ) { |
| 155 |
if ( is_plugin_active( $file ) || is_plugin_active_for_network( $file ) ) { |
| 156 |
$version = $file; |
| 157 |
break; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
return $version; |
| 162 |
} |
| 163 |
} |
| 164 |
|