Moves setup actions from plugins_loaded hook to init hook
Rearranges class methods to follow the order by which they are called
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\API;
|
||||
@@ -16,7 +17,6 @@ class Initializer {
|
||||
const UNABLE_TO_CONNECT = '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.';
|
||||
const SOLVE_DB_ISSUE_URL = 'http://beta.docs.mailpoet.com/article/200-solving-database-connection-issues';
|
||||
|
||||
protected $plugin_initialized = false;
|
||||
private $access_control;
|
||||
|
||||
function __construct($params = array(
|
||||
@@ -50,8 +50,8 @@ class Initializer {
|
||||
register_activation_hook(
|
||||
Env::$file,
|
||||
array(
|
||||
'MailPoet\Config\Activator',
|
||||
'activate'
|
||||
$this,
|
||||
'runActivator'
|
||||
)
|
||||
);
|
||||
|
||||
@@ -60,27 +60,20 @@ class Initializer {
|
||||
'action'
|
||||
), 10, 2);
|
||||
|
||||
add_action('admin_init', array(
|
||||
new DeferredAdminNotices,
|
||||
'printAndClean'
|
||||
));
|
||||
|
||||
add_action('plugins_loaded', array(
|
||||
$this,
|
||||
'setup'
|
||||
));
|
||||
add_action('init', array(
|
||||
$this,
|
||||
'onInit'
|
||||
));
|
||||
add_action('widgets_init', array(
|
||||
$this,
|
||||
'setupWidget'
|
||||
));
|
||||
|
||||
add_action('wp_loaded', array(
|
||||
$this,
|
||||
'setupHooks'
|
||||
));
|
||||
|
||||
add_action('admin_init', array(
|
||||
new DeferredAdminNotices,
|
||||
'printAndClean'
|
||||
));
|
||||
}
|
||||
|
||||
function checkRequirements() {
|
||||
@@ -88,44 +81,43 @@ class Initializer {
|
||||
return $requirements->checkAllRequirements();
|
||||
}
|
||||
|
||||
function runActivator() {
|
||||
$activator = new Activator();
|
||||
return $activator->activate();
|
||||
}
|
||||
|
||||
function setupDB() {
|
||||
$database = new Database();
|
||||
$database->init();
|
||||
}
|
||||
|
||||
function setup() {
|
||||
function onInit() {
|
||||
try {
|
||||
$this->maybeDbUpdate();
|
||||
$this->setupRenderer();
|
||||
$this->setupInstaller();
|
||||
$this->setupUpdater();
|
||||
|
||||
$this->setupRenderer();
|
||||
$this->setupWidget();
|
||||
$this->setupLocalizer();
|
||||
$this->setupMenu();
|
||||
$this->setupChangelog();
|
||||
$this->setupShortcodes();
|
||||
$this->setupImages();
|
||||
|
||||
$this->setupChangelog();
|
||||
$this->setupCronTrigger();
|
||||
$this->setupConflictResolver();
|
||||
|
||||
$this->plugin_initialized = true;
|
||||
do_action('mailpoet_initialized', MAILPOET_VERSION);
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
}
|
||||
|
||||
function onInit() {
|
||||
if(!$this->plugin_initialized) {
|
||||
define('MAILPOET_INITIALIZED', false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->setupJSONAPI();
|
||||
$this->setupRouter();
|
||||
$this->setupPages();
|
||||
|
||||
do_action('mailpoet_initialized', MAILPOET_VERSION);
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
define('MAILPOET_INITIALIZED', false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
define('MAILPOET_INITIALIZED', true);
|
||||
@@ -139,30 +131,10 @@ class Initializer {
|
||||
if(!$this->access_control->validatePermission(AccessControl::PERMISSION_UPDATE_PLUGIN)) {
|
||||
throw new \Exception(__('You do not have permission to activate/deactivate MailPoet plugin.', 'mailpoet'));
|
||||
}
|
||||
$activator = new Activator();
|
||||
$activator->activate();
|
||||
$this->runActivator();
|
||||
}
|
||||
}
|
||||
|
||||
function setupWidget() {
|
||||
if(!$this->plugin_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$widget = new Widget($this->renderer);
|
||||
$widget->init();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
}
|
||||
|
||||
function setupRenderer() {
|
||||
$caching = !WP_DEBUG;
|
||||
$debugging = WP_DEBUG;
|
||||
$this->renderer = new Renderer($caching, $debugging);
|
||||
}
|
||||
|
||||
function setupInstaller() {
|
||||
$installer = new Installer(
|
||||
Installer::PREMIUM_PLUGIN_SLUG
|
||||
@@ -184,6 +156,21 @@ class Initializer {
|
||||
$updater->init();
|
||||
}
|
||||
|
||||
function setupRenderer() {
|
||||
$caching = !WP_DEBUG;
|
||||
$debugging = WP_DEBUG;
|
||||
$this->renderer = new Renderer($caching, $debugging);
|
||||
}
|
||||
|
||||
function setupWidget() {
|
||||
try {
|
||||
$widget = new Widget($this->renderer);
|
||||
$widget->init();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
}
|
||||
|
||||
function setupLocalizer() {
|
||||
$localizer = new Localizer($this->renderer);
|
||||
$localizer->init();
|
||||
@@ -194,41 +181,18 @@ class Initializer {
|
||||
$menu->init();
|
||||
}
|
||||
|
||||
function setupChangelog() {
|
||||
$changelog = new Changelog();
|
||||
$changelog->init();
|
||||
}
|
||||
|
||||
function setupPages() {
|
||||
$pages = new \MailPoet\Settings\Pages();
|
||||
$pages->init();
|
||||
}
|
||||
|
||||
function setupShortcodes() {
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
}
|
||||
|
||||
function setupHooks() {
|
||||
if(!$this->plugin_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$hooks = new Hooks();
|
||||
$hooks->init();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
function setupImages() {
|
||||
add_image_size('mailpoet_newsletter_max', 1320);
|
||||
}
|
||||
|
||||
function setupJSONAPI() {
|
||||
API\API::JSON($this->access_control)->init();
|
||||
}
|
||||
|
||||
function setupRouter() {
|
||||
$router = new Router\Router($this->access_control);
|
||||
$router->init();
|
||||
function setupChangelog() {
|
||||
$changelog = new Changelog();
|
||||
$changelog->init();
|
||||
}
|
||||
|
||||
function setupCronTrigger() {
|
||||
@@ -239,17 +203,37 @@ class Initializer {
|
||||
}
|
||||
}
|
||||
|
||||
function setupImages() {
|
||||
add_image_size('mailpoet_newsletter_max', 1320);
|
||||
}
|
||||
|
||||
function setupConflictResolver() {
|
||||
$conflict_resolver = new ConflictResolver();
|
||||
$conflict_resolver->init();
|
||||
}
|
||||
|
||||
function setupJSONAPI() {
|
||||
API\API::JSON($this->access_control)
|
||||
->init();
|
||||
}
|
||||
|
||||
function setupRouter() {
|
||||
$router = new Router\Router($this->access_control);
|
||||
$router->init();
|
||||
}
|
||||
|
||||
function setupPages() {
|
||||
$pages = new \MailPoet\Settings\Pages();
|
||||
$pages->init();
|
||||
}
|
||||
|
||||
function setupHooks() {
|
||||
try {
|
||||
$hooks = new Hooks();
|
||||
$hooks->init();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
}
|
||||
|
||||
function handleFailedInitialization($exception) {
|
||||
// Check if we are able to add pages at this point
|
||||
// check if we are able to add pages at this point
|
||||
if(function_exists('wp_get_current_user')) {
|
||||
Menu::addErrorPage($this->access_control);
|
||||
}
|
||||
|
Reference in New Issue
Block a user