Merge pull request #1094 from mailpoet/initializer_update
Updates plugin initialization logic [MAILPOET-1097]
This commit is contained in:
@ -62,12 +62,17 @@ class Initializer {
|
|||||||
|
|
||||||
add_action('init', array(
|
add_action('init', array(
|
||||||
$this,
|
$this,
|
||||||
'onInit'
|
'preInitialize'
|
||||||
), 0);
|
), 0);
|
||||||
|
|
||||||
|
add_action('init', array(
|
||||||
|
$this,
|
||||||
|
'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(
|
||||||
@ -91,7 +96,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();
|
||||||
|
|
||||||
@ -99,8 +124,6 @@ class Initializer {
|
|||||||
$this->setupInstaller();
|
$this->setupInstaller();
|
||||||
$this->setupUpdater();
|
$this->setupUpdater();
|
||||||
|
|
||||||
$this->setupRenderer();
|
|
||||||
$this->setupWidget();
|
|
||||||
$this->setupLocalizer();
|
$this->setupLocalizer();
|
||||||
$this->setupMenu();
|
$this->setupMenu();
|
||||||
$this->setupShortcodes();
|
$this->setupShortcodes();
|
||||||
@ -110,8 +133,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);
|
||||||
@ -163,17 +184,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();
|
||||||
@ -211,6 +221,17 @@ class Initializer {
|
|||||||
$conflict_resolver->init();
|
$conflict_resolver->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postInitialize() {
|
||||||
|
if(!defined(self::INITIALIZED)) return;
|
||||||
|
try {
|
||||||
|
$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();
|
||||||
@ -227,13 +248,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) {
|
||||||
|
@ -7,7 +7,7 @@ class InitializerTest extends \MailPoetTest {
|
|||||||
$is_hooked = false;
|
$is_hooked = false;
|
||||||
// mailpoet should hook to 'wp_loaded' with priority of 10
|
// mailpoet should hook to 'wp_loaded' with priority of 10
|
||||||
foreach($wp_filter['wp_loaded'][10] as $name => $hook) {
|
foreach($wp_filter['wp_loaded'][10] as $name => $hook) {
|
||||||
if(preg_match('/setupHooks/', $name)) $is_hooked = true;
|
if(preg_match('/postInitialize/', $name)) $is_hooked = true;
|
||||||
}
|
}
|
||||||
expect($is_hooked)->true();
|
expect($is_hooked)->true();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user