PluginProbe ʕ •ᴥ•ʔ
MailPoet – Newsletters, Email Marketing, and Automation / 5.34.2
MailPoet – Newsletters, Email Marketing, and Automation v5.34.2
5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 4.44.0 4.44.1 4.45.0 4.46.0 4.47.0 4.48.0 4.48.1 4.48.2 4.49.0 4.49.1 4.5.0 4.5.1 4.5.2 4.50.0 4.50.1 4.51.0 4.51.1 4.51.2 4.52.0 4.53.0 4.54.0 4.55.0 4.56.0 4.57.0 4.58.0 4.58.1 4.58.2 4.6.0 4.6.1 4.6.2 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 5.0.0 5.0.1 5.0.2 5.1.0 5.1.1 5.10.0 5.10.1 5.11.0 5.12.0 5.12.1 5.12.10 5.12.11 5.12.12 5.12.13 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13.0 5.13.1 5.13.2 5.14.0 5.14.1 5.14.2 5.14.3 5.15.0 5.15.1 5.16.0 5.16.1 5.16.2 5.16.3 5.16.4 5.17.0 5.17.1 5.17.2 5.17.3 5.17.4 5.17.5 5.17.6 5.18.0 5.19.0 5.2.0 5.2.1 5.2.2 5.2.3 5.20.0 5.21.0 5.21.1 5.21.2 5.21.3 5.22.0 5.22.1 5.22.2 5.22.3 5.22.4 5.23.0 5.23.1 5.23.2 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.7.0 5.7.1 5.8.0 5.8.1 5.9.0 3.0.0-beta.15 3.7.1 3.0.0-beta.16 3.7.2 3.0.0-beta.17 3.7.3 3.0.0-beta.18 3.7.4 3.0.0-beta.19 3.7.5 3.0.0-beta.2 3.7.6 3.0.0-beta.20 3.7.8 3.0.0-beta.21 3.70.0 3.0.0-beta.22 3.71.0 3.0.0-beta.23 3.71.1 3.0.0-beta.23.1 3.71.2 3.0.0-beta.23.2 3.71.3 3.0.0-beta.24 3.72.0 3.0.0-beta.25 3.73.0 3.0.0-beta.26 3.73.1 3.0.0-beta.27 3.73.2 3.0.0-beta.28 3.74.0 3.0.0-beta.29 3.74.1 3.0.0-beta.3 3.74.2 3.0.0-beta.30 3.74.3 3.0.0-beta.31 3.75.0 3.0.0-beta.32 3.75.1 3.0.0-beta.33 3.76.0 3.0.0-beta.33.1 3.77.0 3.0.0-beta.34.0.0 3.77.1 3.0.0-beta.36.0.0 3.78.0 3.0.0-beta.36.0.1 3.79.0 3.0.0-beta.36.2.0 3.8 3.0.0-beta.36.3.0 3.8.1 3.0.0-beta.36.3.1 3.8.2 3.0.0-beta.37.0.0 3.8.3 3.0.0-beta.4 3.8.4 3.0.0-beta.5 3.8.5 3.0.0-beta.6 3.8.6 3.0.0-beta.7 3.80.0 3.0.0-beta.7.1 3.81.0 3.0.0-beta.8 3.82.0 3.0.0-beta.9 3.83.0 3.0.0-rc.1.0.0 3.84.0 3.0.0-rc.1.0.1 3.84.1 3.0.0-rc.1.0.2 3.85.0 3.0.0-rc.1.0.3 3.85.1 3.0.0-rc.1.0.4 3.86.0 3.0.0-rc.2.0.0 3.87.0 3.0.0-rc.2.0.1 3.87.1 3.0.0-rc.2.0.2 3.87.2 3.0.0-rc.2.0.3 3.88.0 3.0.1 3.88.1 3.0.2 3.88.2 3.0.3 3.89.0 3.0.4 3.89.1 3.0.5 3.89.2 3.0.6 3.89.3 3.0.7 3.89.4 3.0.8 3.9.0 3.0.9 3.9.1 3.1.0 3.90.0 3.10 3.90.1 3.10.1 3.90.2 3.100.0 3.91.0 3.100.1 3.91.1 3.100.2 3.92.0 3.101.0 3.92.1 3.101.1 3.93.0 3.102.0 3.93.1 3.102.1 3.94.0 3.103.0 3.95.0 3.103.1 3.95.1 3.11.0 3.96.0 3.11.1 3.96.1 3.11.2 3.97.0 3.11.3 3.98.0 3.11.4 3.98.1 3.11.5 3.99.0 3.12.0 3.99.1 3.12.1 4.0.0 3.13.0 4.0.1 3.14.0 4.1.0 3.14.1 4.1.1 3.15.0 4.10.0 3.16.0 4.11.0 3.16.1 4.11.1 3.16.2 4.12.0 3.16.3 4.12.1 3.17.0 4.12.2 3.17.1 4.13.0 3.17.2 4.14.0 3.18.0 4.15.0 3.18.1 4.16.0 3.18.2 4.17.0 3.19.0 4.17.1 3.19.1 4.18.0 3.19.2 4.18.1 3.19.3 4.19.0 3.2.0 4.2.0 3.2.1 4.20.0 3.2.2 4.20.1 3.2.3 4.20.2 3.2.4 4.21.0 3.2.5 4.22.0 3.20.0 4.22.1 3.21.0 4.22.2 3.21.1 4.23.0 3.22.0 4.24.0 3.23.0 4.25.0 3.23.1 4.26.0 3.23.2 4.26.1 3.24.0 4.27.0 3.25.0 4.28.0 3.25.1 4.29.0 3.26.0 4.3.0 3.26.1 4.3.1 3.27.0 4.30.0 3.28.0 4.31.0 3.29.0 4.31.1 3.3.0 4.32.0 3.3.1 4.33.0 3.3.2 4.34.0 3.3.3 4.35.0 3.3.4 4.35.1 3.3.5 4.36.0 3.3.6 4.37.0 3.30.0 4.38.0 3.31.0 4.39.0 3.31.1 4.4.0 3.32.0 4.40.0 3.32.1 4.41.0 3.32.2 4.41.1 3.33.0 4.41.2 3.34.0 4.41.3 3.34.1 4.42.0 3.34.2 4.42.1 3.34.3 3.34.4 3.35.0 3.35.1 3.35.3 3.35.4 3.36.0 3.37.0 3.37.1 3.37.2 3.37.3 3.38.0 3.38.1 3.39.0 3.39.1 3.39.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.40.0 3.40.1 3.41.0 3.41.1 3.41.2 3.42.0 3.42.1 3.42.2 3.42.3 3.43.0 3.43.1 3.44.0 3.45.0 3.45.1 3.46.0 3.46.1 3.46.10 3.46.11 3.46.12 3.46.13 3.46.14 3.46.2 3.46.3 3.46.4 3.46.5 3.46.6 3.46.7 3.46.8 3.46.9 3.47.0 3.47.1 3.47.10 3.47.11 3.47.2 3.47.3 3.47.5 3.47.6 3.47.7 3.47.9 3.48.0 3.48.1 3.49.0 3.49.1 3.5.0 3.5.1 3.50.0 3.51.0 3.51.1 3.51.2 3.52.0 3.53.0 3.54.0 3.54.1 3.54.2 3.54.3 3.55.0 3.55.1 3.56.0 3.56.1 3.56.2 3.57.0 3.57.1 3.58.0 3.59.0 3.59.1 3.59.2 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.60.0 3.60.1 3.60.10 3.60.11 3.60.12 3.60.2 3.60.3 3.60.4 3.60.6 3.60.7 3.60.8 3.60.9 3.61.0 3.62.0 3.62.1 3.63.0 3.64.0 3.64.1 3.64.2 3.64.3 3.65.0 trunk 3.65.1 3.0.0 3.66.0 3.0.0-beta.1 3.67.0 3.0.0-beta.10 3.67.1 3.0.0-beta.11 3.68.0 3.0.0-beta.12 3.69.0 3.0.0-beta.13 3.69.1 3.0.0-beta.14 3.7.0
mailpoet / lib / Config / Initializer.php
mailpoet / lib / Config Last commit date
PopulatorData 2 months ago AccessControl.php 2 years ago Activator.php 2 months ago AssetsLoader.php 2 weeks ago Capabilities.php 2 months ago Changelog.php 2 months ago DeactivationPoll.php 3 years ago DeferredAdminNotices.php 2 months ago Env.php 6 months ago Hooks.php 1 month ago HooksWooCommerce.php 1 month ago Initializer.php 1 month ago Installer.php 10 months ago Localizer.php 3 years ago Menu.php 1 month ago PersonalDataErasers.php 1 month ago PersonalDataExporters.php 1 month ago PluginActivatedHook.php 3 years ago Populator.php 2 weeks ago PrivacyPolicy.php 1 month ago Renderer.php 1 year ago RendererFactory.php 3 years ago RequirementsChecker.php 2 months ago Router.php 2 months ago ServicesChecker.php 3 years ago Shortcodes.php 1 month ago SilentUpgraderSkin.php 3 years ago SubscriberChangesNotifier.php 2 months ago TranslationUpdater.php 3 months ago TwigEnvironment.php 1 year ago TwigFileSystemCache.php 3 years ago Updater.php 5 days ago index.php 3 years ago
Initializer.php
682 lines
1 <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
2
3 namespace MailPoet\Config;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use Automattic\WooCommerce\EmailEditor\Bootstrap as EmailEditorBootstrap;
9 use Automattic\WooCommerce\EmailEditor\Email_Editor_Container;
10 use Automattic\WooCommerce\EmailEditor\Engine\Logger\Email_Editor_Logger;
11 use MailPoet\Abilities\Abilities;
12 use MailPoet\API\JSON\API;
13 use MailPoet\API\REST\API as RestApi;
14 use MailPoet\AutomaticEmails\AutomaticEmails;
15 use MailPoet\Automation\Engine\Engine;
16 use MailPoet\Automation\Engine\Hooks as AutomationHooks;
17 use MailPoet\Automation\Integrations\MailPoet\MailPoetIntegration;
18 use MailPoet\Automation\Integrations\WooCommerce\WooCommerceIntegration;
19 use MailPoet\Cron\CliCommands\Cli as CronCli;
20 use MailPoet\Cron\CronTrigger;
21 use MailPoet\Cron\DaemonActionSchedulerRunner;
22 use MailPoet\CustomFields\RestApi\Api as CustomFieldsRestApi;
23 use MailPoet\EmailEditor\Integrations\MailPoet\Blocks\BlockTypesController;
24 use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor as MailpoetEmailEditorIntegration;
25 use MailPoet\EmailEditor\Integrations\MailPoet\Logger;
26 use MailPoet\Form\RestApi\Api as FormsRestApi;
27 use MailPoet\InvalidStateException;
28 use MailPoet\Logging\LogsDownload;
29 use MailPoet\Logging\RestApi\Api as LogsRestApi;
30 use MailPoet\Migrator\Cli as MigratorCli;
31 use MailPoet\Newsletter\RestApi\Api as NewslettersRestApi;
32 use MailPoet\Newsletter\Sharing\PublicEmailRoute;
33 use MailPoet\PostEditorBlocks\PostEditorBlock;
34 use MailPoet\PostEditorBlocks\WooCommerceBlocksIntegration;
35 use MailPoet\Router;
36 use MailPoet\Segments\RestApi\Api as SegmentsRestApi;
37 use MailPoet\Settings\SettingsController;
38 use MailPoet\Statistics\Track\SubscriberActivityTracker;
39 use MailPoet\Subscribers\ImportExport\Import\Cli as ImportCli;
40 use MailPoet\Subscribers\RestApi\Api as SubscribersRestApi;
41 use MailPoet\Tags\RestApi\Api as TagsRestApi;
42 use MailPoet\Util\ConflictResolver;
43 use MailPoet\Util\LegacyDatabase;
44 use MailPoet\Util\Notices\PermanentNotices;
45 use MailPoet\Util\Url;
46 use MailPoet\WooCommerce\Helper as WooCommerceHelper;
47 use MailPoet\WooCommerce\TransactionalEmailHooks as WCTransactionalEmails;
48 use MailPoet\WP\Functions as WPFunctions;
49 use MailPoet\WP\Notice as WPNotice;
50
51 class Initializer {
52 /** @var AccessControl */
53 private $accessControl;
54
55 /** @var Renderer */
56 private $renderer;
57
58 /** @var RendererFactory */
59 private $rendererFactory;
60
61 /** @var API */
62 private $api;
63
64 /** @var RestApi */
65 private $restApi;
66
67 /** @var Activator */
68 private $activator;
69
70 /** @var SettingsController */
71 private $settings;
72
73 /** @var MigratorCli */
74 private $migratorCli;
75
76 /** @var ImportCli */
77 private $importCli;
78
79 /** @var CronCli */
80 private $cronCli;
81
82 /** @var Router\Router */
83 private $router;
84
85 /** @var Hooks */
86 private $hooks;
87
88 /** @var Changelog */
89 private $changelog;
90
91 /** @var PublicEmailRoute */
92 private $publicEmailRoute;
93
94 /** @var Menu */
95 private $menu;
96
97 /** @var CronTrigger */
98 private $cronTrigger;
99
100 /** @var PermanentNotices */
101 private $permanentNotices;
102
103 /** @var Shortcodes */
104 private $shortcodes;
105
106 /** @var WCTransactionalEmails */
107 private $wcTransactionalEmails;
108
109 /** @var WooCommerceHelper */
110 private $wcHelper;
111
112 /** @var \MailPoet\PostEditorBlocks\PostEditorBlock */
113 private $postEditorBlock;
114
115 /** @var \MailPoet\PostEditorBlocks\WooCommerceBlocksIntegration */
116 private $woocommerceBlocksIntegration;
117
118 /** @var Localizer */
119 private $localizer;
120
121 /** @var AutomaticEmails */
122 private $automaticEmails;
123
124 /** @var WPFunctions */
125 private $wpFunctions;
126
127 /** @var AssetsLoader */
128 private $assetsLoader;
129
130 /** @var SubscriberActivityTracker */
131 private $subscriberActivityTracker;
132
133 /** @var Engine */
134 private $automationEngine;
135
136 /** @var TagsRestApi */
137 private $tagsRestApi;
138
139 /** @var CustomFieldsRestApi */
140 private $customFieldsRestApi;
141
142 /** @var FormsRestApi */
143 private $formsRestApi;
144
145 /** @var SegmentsRestApi */
146 private $segmentsRestApi;
147
148 /** @var LogsRestApi */
149 private $logsRestApi;
150
151 /** @var SubscribersRestApi */
152 private $subscribersRestApi;
153
154 /** @var NewslettersRestApi */
155 private $newslettersRestApi;
156
157 /** @var LogsDownload */
158 private $logsDownload;
159
160 /** @var MailPoetIntegration */
161 private $automationMailPoetIntegration;
162
163 /** @var WooCommerceIntegration */
164 private $woocommerceIntegration;
165
166 /** @var PersonalDataExporters */
167 private $personalDataExporters;
168
169 /** @var DaemonActionSchedulerRunner */
170 private $actionSchedulerRunner;
171
172 /** @var MailpoetEmailEditorIntegration */
173 private $mailpoetEmailEditorIntegration;
174
175 /** @var BlockTypesController */
176 private $blockTypesController;
177
178 /** @var Url */
179 private $urlHelper;
180
181 private EmailEditorBootstrap $emailEditorBootstrap;
182
183 private Email_Editor_Logger $emailEditorLogger;
184
185 const INITIALIZED = 'MAILPOET_INITIALIZED';
186
187 const PLUGIN_ACTIVATED = 'mailpoet_plugin_activated';
188
189 public function __construct(
190 RendererFactory $rendererFactory,
191 AccessControl $accessControl,
192 API $api,
193 RestApi $restApi,
194 Activator $activator,
195 SettingsController $settings,
196 MigratorCli $migratorCli,
197 ImportCli $importCli,
198 CronCli $cronCli,
199 Router\Router $router,
200 Hooks $hooks,
201 Changelog $changelog,
202 Menu $menu,
203 CronTrigger $cronTrigger,
204 PermanentNotices $permanentNotices,
205 Shortcodes $shortcodes,
206 WCTransactionalEmails $wcTransactionalEmails,
207 PostEditorBlock $postEditorBlock,
208 WooCommerceBlocksIntegration $woocommerceBlocksIntegration,
209 WooCommerceHelper $wcHelper,
210 Localizer $localizer,
211 AutomaticEmails $automaticEmails,
212 SubscriberActivityTracker $subscriberActivityTracker,
213 WPFunctions $wpFunctions,
214 AssetsLoader $assetsLoader,
215 Engine $automationEngine,
216 MailPoetIntegration $automationMailPoetIntegration,
217 WooCommerceIntegration $woocommerceIntegration,
218 PersonalDataExporters $personalDataExporters,
219 DaemonActionSchedulerRunner $actionSchedulerRunner,
220 BlockTypesController $blockTypesController,
221 MailpoetEmailEditorIntegration $mailpoetEmailEditorIntegration,
222 Url $urlHelper,
223 TagsRestApi $tagsRestApi,
224 CustomFieldsRestApi $customFieldsRestApi,
225 FormsRestApi $formsRestApi,
226 SegmentsRestApi $segmentsRestApi,
227 LogsRestApi $logsRestApi,
228 SubscribersRestApi $subscribersRestApi,
229 NewslettersRestApi $newslettersRestApi,
230 LogsDownload $logsDownload,
231 PublicEmailRoute $publicEmailRoute
232 ) {
233 $this->rendererFactory = $rendererFactory;
234 $this->accessControl = $accessControl;
235 $this->api = $api;
236 $this->restApi = $restApi;
237 $this->activator = $activator;
238 $this->settings = $settings;
239 $this->migratorCli = $migratorCli;
240 $this->importCli = $importCli;
241 $this->cronCli = $cronCli;
242 $this->router = $router;
243 $this->hooks = $hooks;
244 $this->changelog = $changelog;
245 $this->menu = $menu;
246 $this->cronTrigger = $cronTrigger;
247 $this->permanentNotices = $permanentNotices;
248 $this->shortcodes = $shortcodes;
249 $this->wcTransactionalEmails = $wcTransactionalEmails;
250 $this->wcHelper = $wcHelper;
251 $this->postEditorBlock = $postEditorBlock;
252 $this->woocommerceBlocksIntegration = $woocommerceBlocksIntegration;
253 $this->localizer = $localizer;
254 $this->automaticEmails = $automaticEmails;
255 $this->subscriberActivityTracker = $subscriberActivityTracker;
256 $this->wpFunctions = $wpFunctions;
257 $this->assetsLoader = $assetsLoader;
258 $this->automationEngine = $automationEngine;
259 $this->automationMailPoetIntegration = $automationMailPoetIntegration;
260 $this->woocommerceIntegration = $woocommerceIntegration;
261 $this->personalDataExporters = $personalDataExporters;
262 $this->actionSchedulerRunner = $actionSchedulerRunner;
263 $this->mailpoetEmailEditorIntegration = $mailpoetEmailEditorIntegration;
264 $this->blockTypesController = $blockTypesController;
265 $this->urlHelper = $urlHelper;
266 $this->tagsRestApi = $tagsRestApi;
267 $this->customFieldsRestApi = $customFieldsRestApi;
268 $this->formsRestApi = $formsRestApi;
269 $this->segmentsRestApi = $segmentsRestApi;
270 $this->logsRestApi = $logsRestApi;
271 $this->subscribersRestApi = $subscribersRestApi;
272 $this->newslettersRestApi = $newslettersRestApi;
273 $this->logsDownload = $logsDownload;
274 $this->publicEmailRoute = $publicEmailRoute;
275
276 $emailEditorContainer = Email_Editor_Container::container();
277 $this->emailEditorBootstrap = $emailEditorContainer->get(EmailEditorBootstrap::class);
278 $this->emailEditorLogger = $emailEditorContainer->get(Email_Editor_Logger::class);
279 }
280
281 public function init() {
282 // Initialize Action Scheduler. It needs to be called early because it hooks into `plugins_loaded`.
283 require_once __DIR__ . '/../../vendor/woocommerce/action-scheduler/action-scheduler.php';
284
285 // define legacy constants for DB tables - for back compatibility
286 LegacyDatabase::defineTableConstants();
287
288 // load translations and setup translations update/download
289 $this->setupLocalizer();
290
291 // activation function
292 $this->wpFunctions->registerActivationHook(
293 Env::$file,
294 [
295 $this,
296 'runActivator',
297 ]
298 );
299
300 // deactivation function
301 $this->wpFunctions->registerDeactivationHook(
302 Env::$file,
303 [
304 $this,
305 'runDeactivation',
306 ]
307 );
308
309 $this->emailEditorBootstrap->init();
310 $this->setupAbilities();
311
312 $this->wpFunctions->addAction('activated_plugin', [
313 new PluginActivatedHook(new DeferredAdminNotices),
314 'action',
315 ], 10, 2);
316
317 $this->wpFunctions->addAction('plugins_loaded', [
318 $this,
319 'pluginsLoaded',
320 ], 0);
321
322 $this->wpFunctions->addAction('init', [
323 $this,
324 'preInitialize',
325 ], 0);
326
327 $this->wpFunctions->addAction('init', [
328 $this,
329 'initialize',
330 ]);
331
332 $this->wpFunctions->addAction(
333 'init',
334 [$this, 'maybeRunActivator'],
335 PHP_INT_MIN
336 );
337
338 $this->wpFunctions->addAction('admin_init', [
339 $this,
340 'setupPrivacyPolicy',
341 ]);
342
343 $this->wpFunctions->addAction('wp_loaded', [
344 $this,
345 'postInitialize',
346 ]);
347
348 $this->wpFunctions->addAction('admin_init', [
349 new DeferredAdminNotices,
350 'printAndClean',
351 ]);
352
353 $this->wpFunctions->addFilter('wpmu_drop_tables', [
354 $this,
355 'multisiteDropTables',
356 ]);
357
358 $this->wpFunctions->addFilter('woocommerce_email_editor_initialized', [
359 $this,
360 'setupEmailEditorIntegrations',
361 ]);
362
363 $this->wpFunctions->addAction('woocommerce_init', [
364 $this,
365 'setupMarketingConfirmationEmail',
366 ]);
367
368 WPFunctions::get()->addAction(AutomationHooks::INITIALIZE, [
369 $this->automationMailPoetIntegration,
370 'register',
371 ]);
372 WPFunctions::get()->addAction(AutomationHooks::INITIALIZE, [
373 $this->woocommerceIntegration,
374 'register',
375 ]);
376
377 WPFunctions::get()->addAction('admin_init', [
378 $this,
379 'afterPluginActivation',
380 ]);
381
382 $this->hooks->initEarlyHooks();
383 }
384
385 private function setupAbilities(): void {
386 require_once __DIR__ . '/../Abilities/Abilities.php';
387 Abilities::init();
388 }
389
390 public function runActivator() {
391 try {
392 $this->wpFunctions->addOption(self::PLUGIN_ACTIVATED, true); // used in afterPluginActivation
393 $this->activator->activate();
394 } catch (InvalidStateException $e) {
395 return $this->handleRunningMigration($e);
396 } catch (\Exception $e) {
397 return $this->handleFailedInitialization($e);
398 }
399 }
400
401 public function pluginsLoaded() {
402 $this->hooks->init();
403 $this->publicEmailRoute->init();
404 }
405
406 public function preInitialize() {
407 try {
408 $this->renderer = $this->rendererFactory->getRenderer();
409 $this->setupWidget();
410 $this->setupWoocommerceTransactionalEmails();
411 $this->assetsLoader->loadStyles();
412 $this->emailEditorLogger->set_logger(new Logger());
413 } catch (\Exception $e) {
414 $this->handleFailedInitialization($e);
415 }
416 }
417
418 public function setupWidget() {
419 $this->wpFunctions->registerWidget('\MailPoet\Form\Widget');
420 }
421
422 public function initialize() {
423 try {
424 $this->migratorCli->initialize();
425 $this->importCli->initialize();
426 $this->cronCli->initialize();
427 $this->setupInstaller();
428 $this->setupUpdater();
429
430 $this->setupCapabilities();
431 $this->menu->init();
432 $this->setupShortcodes();
433 $this->setupImages();
434 $this->setupPersonalDataExporters();
435 $this->setupPersonalDataErasers();
436
437 $this->changelog->init();
438 $this->setupCronTrigger();
439 $this->setupConflictResolver();
440
441 $this->setupPages();
442
443 $this->setupPermanentNotices();
444 $this->setupAutomaticEmails();
445 $this->setupWoocommerceBlocksIntegration();
446 $this->setupDeactivationPoll();
447 $this->subscriberActivityTracker->trackActivity();
448 $this->postEditorBlock->init();
449 $this->automationEngine->initialize();
450 $this->tagsRestApi->initialize();
451 $this->customFieldsRestApi->initialize();
452 $this->formsRestApi->initialize();
453 $this->segmentsRestApi->initialize();
454 $this->logsRestApi->initialize();
455 $this->subscribersRestApi->initialize();
456 $this->newslettersRestApi->initialize();
457 $this->logsDownload->initialize();
458 $this->blockTypesController->initialize();
459 $this->wpFunctions->doAction('mailpoet_initialized', MAILPOET_VERSION);
460 } catch (InvalidStateException $e) {
461 return $this->handleRunningMigration($e);
462 } catch (\Exception $e) {
463 return $this->handleFailedInitialization($e);
464 }
465
466 define(self::INITIALIZED, true);
467 }
468
469 /**
470 * Walk around for getting this to work correctly
471 *
472 * Read more here: https://developer.wordpress.org/reference/functions/register_activation_hook/
473 * and https://github.com/mailpoet/mailpoet/pull/4620#discussion_r1058210174
474 * @return void
475 */
476 public function afterPluginActivation() {
477 if (!$this->wpFunctions->isAdmin() || !defined(self::INITIALIZED) || !$this->wpFunctions->getOption(self::PLUGIN_ACTIVATED)) return;
478
479 $currentUrl = $this->urlHelper->getCurrentUrl();
480
481 // wp automatically redirect to `wp-admin/plugins.php?activate=true&...` after plugin activation
482 $activatedByWpAdmin = !empty(strpos($currentUrl, 'plugins.php')) && isset($_GET['activate']) && (bool)$_GET['activate'];
483
484 // We want to run this only once immediately after activation.
485 // Delete the flag to prevent triggering on subsequent page loads.
486 $this->wpFunctions->deleteOption(self::PLUGIN_ACTIVATED);
487
488 // If not activated by wp. Do not redirect e.g WooCommerce NUX
489 if ($activatedByWpAdmin) {
490 $this->changelog->redirectToLandingPage();
491 }
492 }
493
494 /**
495 * Checks if the plugin was updated and runs the activator if needed. The activator
496 * will run the database migrations and update the db version among a few other things.
497 *
498 * @return void
499 * @throws InvalidStateException
500 */
501 public function maybeRunActivator() {
502 try {
503 $currentDbVersion = $this->settings->get('db_version');
504 } catch (\Exception $e) {
505 $currentDbVersion = null;
506 }
507
508 if (version_compare((string)$currentDbVersion, Env::$version) === 0) {
509 return;
510 }
511
512 // if current db version and plugin version differ
513 try {
514 $this->activator->activate();
515 } catch (InvalidStateException $e) {
516 $this->handleRunningMigration($e);
517 } catch (\Exception $e) {
518 $this->handleFailedInitialization($e);
519 }
520 }
521
522 public function setupInstaller() {
523 $installer = new Installer(
524 Installer::PREMIUM_PLUGIN_SLUG
525 );
526 $installer->init();
527 }
528
529 public function setupUpdater() {
530 $premiumSlug = Installer::PREMIUM_PLUGIN_SLUG;
531 $premiumPluginFile = Installer::getPluginFile($premiumSlug);
532 $premiumVersion = defined('MAILPOET_PREMIUM_VERSION') ? MAILPOET_PREMIUM_VERSION : null;
533
534 if (empty($premiumPluginFile) || !$premiumVersion) {
535 return false;
536 }
537 $updater = new Updater(
538 $premiumPluginFile,
539 $premiumSlug,
540 MAILPOET_PREMIUM_VERSION
541 );
542 $updater->init();
543 }
544
545 public function setupLocalizer() {
546 $this->localizer->init($this->wpFunctions);
547 }
548
549 public function setupCapabilities() {
550 $caps = new Capabilities($this->renderer);
551 $caps->init();
552 }
553
554 public function setupShortcodes() {
555 $this->shortcodes->init();
556 }
557
558 public function setupImages() {
559 $this->wpFunctions->addImageSize('mailpoet_newsletter_max', Env::NEWSLETTER_CONTENT_WIDTH);
560 }
561
562 public function setupCronTrigger() {
563 $this->cronTrigger->init((string)php_sapi_name());
564 }
565
566 public function setupConflictResolver() {
567 $conflictResolver = new ConflictResolver();
568 $conflictResolver->init();
569 }
570
571 public function postInitialize() {
572 if (!defined(self::INITIALIZED)) return;
573 try {
574 $this->api->init();
575 $this->restApi->init();
576 $this->router->init();
577 $this->setupUserLocale();
578 } catch (\Exception $e) {
579 $this->handleFailedInitialization($e);
580 }
581 }
582
583 public function setupUserLocale() {
584 if (get_user_locale() === $this->wpFunctions->getLocale()) return;
585 $this->wpFunctions->unloadTextdomain(Env::$pluginName);
586 $this->localizer->init($this->wpFunctions);
587 }
588
589 public function setupPages() {
590 $pages = new \MailPoet\Settings\Pages();
591 $pages->init();
592 }
593
594 public function setupPrivacyPolicy() {
595 $privacyPolicy = new PrivacyPolicy();
596 $privacyPolicy->init();
597 }
598
599 public function setupPersonalDataExporters() {
600 $this->personalDataExporters->init();
601 }
602
603 public function setupPersonalDataErasers() {
604 $erasers = new PersonalDataErasers();
605 $erasers->init();
606 }
607
608 public function setupPermanentNotices() {
609 $this->permanentNotices->init();
610 }
611
612 public function handleFailedInitialization($exception) {
613 // check if we are able to add pages at this point
614 if (function_exists('wp_get_current_user')) {
615 Menu::addErrorPage($this->accessControl);
616 }
617 return WPNotice::displayError($exception);
618 }
619
620 private function handleRunningMigration(InvalidStateException $exception) {
621 if (function_exists('wp_get_current_user')) {
622 Menu::addErrorPage($this->accessControl);
623 }
624 return WPNotice::displayWarning($exception->getMessage());
625 }
626
627 public function setupAutomaticEmails() {
628 $this->automaticEmails->init();
629 $this->automaticEmails->getAutomaticEmails();
630 }
631
632 public function multisiteDropTables($tables) {
633 global $wpdb;
634 $tablePrefix = $wpdb->prefix . Env::$pluginPrefix;
635 $mailpoetTables = $wpdb->get_col(
636 $wpdb->prepare(
637 "SHOW TABLES LIKE %s",
638 $wpdb->esc_like($tablePrefix) . '%'
639 )
640 );
641 return array_merge($tables, $mailpoetTables);
642 }
643
644 public function setupEmailEditorIntegrations() {
645 $this->mailpoetEmailEditorIntegration->initialize();
646 }
647
648 public function runDeactivation() {
649 $this->actionSchedulerRunner->deactivate();
650 }
651
652 private function setupWoocommerceTransactionalEmails() {
653 $wcEnabled = $this->wcHelper->isWooCommerceActive();
654 $optInEnabled = $this->settings->get('woocommerce.use_mailpoet_editor', false);
655 if ($wcEnabled && $optInEnabled) {
656 $this->wcTransactionalEmails->overrideStylesForWooEmails();
657 $this->wcTransactionalEmails->useTemplateForWoocommerceEmails();
658 }
659 }
660
661 public function setupMarketingConfirmationEmail() {
662 $wcEnabled = $this->wcHelper->isWooCommerceActive();
663 if ($wcEnabled) {
664 $emails = new \MailPoet\WooCommerce\Emails();
665 $emails->init();
666 }
667 }
668
669 private function setupWoocommerceBlocksIntegration() {
670 $wcEnabled = $this->wcHelper->isWooCommerceActive();
671 $wcBlocksEnabled = $this->wcHelper->isWooCommerceBlocksActive('8.0.0');
672 if ($wcEnabled && $wcBlocksEnabled) {
673 $this->woocommerceBlocksIntegration->init();
674 }
675 }
676
677 private function setupDeactivationPoll(): void {
678 $deactivationPoll = new DeactivationPoll($this->wpFunctions, $this->renderer);
679 $deactivationPoll->init();
680 }
681 }
682