Breaks plugin initialization into 3 stages: preInit, init and postInit
This commit is contained in:
@ -45,9 +45,6 @@ class Initializer {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure renderer
|
|
||||||
$this->setupRenderer();
|
|
||||||
|
|
||||||
// activation function
|
// activation function
|
||||||
register_activation_hook(
|
register_activation_hook(
|
||||||
Env::$file,
|
Env::$file,
|
||||||
@ -64,17 +61,17 @@ class Initializer {
|
|||||||
|
|
||||||
add_action('init', array(
|
add_action('init', array(
|
||||||
$this,
|
$this,
|
||||||
'onInit'
|
'preInitialize'
|
||||||
));
|
), 0);
|
||||||
|
|
||||||
add_action('widgets_init', array(
|
add_action('init', array(
|
||||||
$this,
|
$this,
|
||||||
'setupWidget'
|
'initialize'
|
||||||
));
|
));
|
||||||
|
|
||||||
add_action('wp_loaded', array(
|
add_action('wp_loaded', array(
|
||||||
$this,
|
$this,
|
||||||
'setupHooks'
|
'postInitialize'
|
||||||
));
|
));
|
||||||
|
|
||||||
add_action('admin_init', array(
|
add_action('admin_init', array(
|
||||||
@ -98,7 +95,27 @@ class Initializer {
|
|||||||
$database->init();
|
$database->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInit() {
|
function preInitialize() {
|
||||||
|
try {
|
||||||
|
$this->setupRenderer();
|
||||||
|
$this->setupWidget();
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$this->handleFailedInitialization($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupRenderer() {
|
||||||
|
$caching = !WP_DEBUG;
|
||||||
|
$debugging = WP_DEBUG;
|
||||||
|
$this->renderer = new Renderer($caching, $debugging);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupWidget() {
|
||||||
|
$widget = new Widget($this->renderer);
|
||||||
|
$widget->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
try {
|
try {
|
||||||
$this->setupAccessControl();
|
$this->setupAccessControl();
|
||||||
|
|
||||||
@ -115,8 +132,6 @@ class Initializer {
|
|||||||
$this->setupCronTrigger();
|
$this->setupCronTrigger();
|
||||||
$this->setupConflictResolver();
|
$this->setupConflictResolver();
|
||||||
|
|
||||||
$this->setupJSONAPI();
|
|
||||||
$this->setupRouter();
|
|
||||||
$this->setupPages();
|
$this->setupPages();
|
||||||
|
|
||||||
do_action('mailpoet_initialized', MAILPOET_VERSION);
|
do_action('mailpoet_initialized', MAILPOET_VERSION);
|
||||||
@ -164,17 +179,6 @@ class Initializer {
|
|||||||
$updater->init();
|
$updater->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupRenderer() {
|
|
||||||
$caching = !WP_DEBUG;
|
|
||||||
$debugging = WP_DEBUG;
|
|
||||||
$this->renderer = new Renderer($caching, $debugging);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupWidget() {
|
|
||||||
$widget = new Widget($this->renderer);
|
|
||||||
$widget->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupLocalizer() {
|
function setupLocalizer() {
|
||||||
$localizer = new Localizer();
|
$localizer = new Localizer();
|
||||||
$localizer->init();
|
$localizer->init();
|
||||||
@ -212,6 +216,17 @@ class Initializer {
|
|||||||
$conflict_resolver->init();
|
$conflict_resolver->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postInitialize() {
|
||||||
|
try {
|
||||||
|
if(!defined(self::INITIALIZED)) return;
|
||||||
|
$this->setupHooks();
|
||||||
|
$this->setupJSONAPI();
|
||||||
|
$this->setupRouter();
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$this->handleFailedInitialization($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setupJSONAPI() {
|
function setupJSONAPI() {
|
||||||
$json_api = API\API::JSON($this->access_control);
|
$json_api = API\API::JSON($this->access_control);
|
||||||
$json_api->init();
|
$json_api->init();
|
||||||
@ -228,13 +243,8 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupHooks() {
|
function setupHooks() {
|
||||||
if(!defined(self::INITIALIZED)) return;
|
$hooks = new Hooks();
|
||||||
try {
|
$hooks->init();
|
||||||
$hooks = new Hooks();
|
|
||||||
$hooks->init();
|
|
||||||
} catch(\Exception $e) {
|
|
||||||
$this->handleFailedInitialization($e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFailedInitialization($exception) {
|
function handleFailedInitialization($exception) {
|
||||||
|
Reference in New Issue
Block a user