Revert "Remove static usage of WP functions"

This reverts commit 1c10add392.
This commit is contained in:
Rostislav Wolný
2022-02-16 11:41:52 +01:00
committed by Veljko V
parent 164a6880bf
commit 2beac94aa9

View File

@@ -80,9 +80,6 @@ class Initializer {
/** @var AutomaticEmails */ /** @var AutomaticEmails */
private $automaticEmails; private $automaticEmails;
/** @var WPFunctions */
private $wpFunctions;
/** @var AssetsLoader */ /** @var AssetsLoader */
private $assetsLoader; private $assetsLoader;
@@ -112,7 +109,6 @@ class Initializer {
Localizer $localizer, Localizer $localizer,
AutomaticEmails $automaticEmails, AutomaticEmails $automaticEmails,
SubscriberActivityTracker $subscriberActivityTracker, SubscriberActivityTracker $subscriberActivityTracker,
WPFunctions $wpFunctions,
AssetsLoader $assetsLoader AssetsLoader $assetsLoader
) { ) {
$this->rendererFactory = $rendererFactory; $this->rendererFactory = $rendererFactory;
@@ -135,7 +131,6 @@ class Initializer {
$this->localizer = $localizer; $this->localizer = $localizer;
$this->automaticEmails = $automaticEmails; $this->automaticEmails = $automaticEmails;
$this->subscriberActivityTracker = $subscriberActivityTracker; $this->subscriberActivityTracker = $subscriberActivityTracker;
$this->wpFunctions = $wpFunctions;
$this->assetsLoader = $assetsLoader; $this->assetsLoader = $assetsLoader;
} }
@@ -147,7 +142,7 @@ class Initializer {
$this->databaseInitializer->initializeConnection(); $this->databaseInitializer->initializeConnection();
} catch (\Exception $e) { } catch (\Exception $e) {
return WPNotice::displayError(Helpers::replaceLinkTags( return WPNotice::displayError(Helpers::replaceLinkTags(
__('Unable to connect to the database (the database is unable to open a file or folder), the connection is likely not configured correctly. Please read our [link] Knowledge Base article [/link] for steps how to resolve it.', 'mailpoet'), WPFunctions::get()->__('Unable to connect to the database (the database is unable to open a file or folder), the connection is likely not configured correctly. Please read our [link] Knowledge Base article [/link] for steps how to resolve it.', 'mailpoet'),
'https://kb.mailpoet.com/article/200-solving-database-connection-issues', 'https://kb.mailpoet.com/article/200-solving-database-connection-issues',
[ [
'target' => '_blank', 'target' => '_blank',
@@ -157,7 +152,7 @@ class Initializer {
} }
// activation function // activation function
$this->wpFunctions->registerActivationHook( WPFunctions::get()->registerActivationHook(
Env::$file, Env::$file,
[ [
$this, $this,
@@ -165,37 +160,37 @@ class Initializer {
] ]
); );
$this->wpFunctions->addAction('activated_plugin', [ WPFunctions::get()->addAction('activated_plugin', [
new PluginActivatedHook(new DeferredAdminNotices), new PluginActivatedHook(new DeferredAdminNotices),
'action', 'action',
], 10, 2); ], 10, 2);
$this->wpFunctions->addAction('init', [ WPFunctions::get()->addAction('init', [
$this, $this,
'preInitialize', 'preInitialize',
], 0); ], 0);
$this->wpFunctions->addAction('init', [ WPFunctions::get()->addAction('init', [
$this, $this,
'initialize', 'initialize',
]); ]);
$this->wpFunctions->addAction('admin_init', [ WPFunctions::get()->addAction('admin_init', [
$this, $this,
'setupPrivacyPolicy', 'setupPrivacyPolicy',
]); ]);
$this->wpFunctions->addAction('wp_loaded', [ WPFunctions::get()->addAction('wp_loaded', [
$this, $this,
'postInitialize', 'postInitialize',
]); ]);
$this->wpFunctions->addAction('admin_init', [ WPFunctions::get()->addAction('admin_init', [
new DeferredAdminNotices, new DeferredAdminNotices,
'printAndClean', 'printAndClean',
]); ]);
$this->wpFunctions->addFilter('wpmu_drop_tables', [ WPFunctions::get()->addFilter('wpmu_drop_tables', [
$this, $this,
'multisiteDropTables', 'multisiteDropTables',
]); ]);
@@ -226,7 +221,7 @@ class Initializer {
} }
public function setupWidget() { public function setupWidget() {
$this->wpFunctions->registerWidget('\MailPoet\Form\Widget'); WPFunctions::get()->registerWidget('\MailPoet\Form\Widget');
} }
public function initialize() { public function initialize() {
@@ -254,7 +249,7 @@ class Initializer {
$this->subscriberActivityTracker->trackActivity(); $this->subscriberActivityTracker->trackActivity();
$this->postEditorBlock->init(); $this->postEditorBlock->init();
$this->wpFunctions->doAction('mailpoet_initialized', MAILPOET_VERSION); WPFunctions::get()->doAction('mailpoet_initialized', MAILPOET_VERSION);
} catch (InvalidStateException $e) { } catch (InvalidStateException $e) {
return $this->handleRunningMigration($e); return $this->handleRunningMigration($e);
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -312,7 +307,7 @@ class Initializer {
} }
public function setupImages() { public function setupImages() {
$this->wpFunctions->addImageSize('mailpoet_newsletter_max', Env::NEWSLETTER_CONTENT_WIDTH); WPFunctions::get()->addImageSize('mailpoet_newsletter_max', Env::NEWSLETTER_CONTENT_WIDTH);
} }
public function setupCronTrigger() { public function setupCronTrigger() {
@@ -339,8 +334,8 @@ class Initializer {
} }
public function setupUserLocale() { public function setupUserLocale() {
if (get_user_locale() === $this->wpFunctions->getLocale()) return; if (get_user_locale() === WPFunctions::get()->getLocale()) return;
$this->wpFunctions->unloadTextdomain(Env::$pluginName); WPFunctions::get()->unloadTextdomain(Env::$pluginName);
$this->localizer->init(); $this->localizer->init();
} }