Handle exceptions during initialization better [MAILPOET-966]
This commit is contained in:
committed by
pavel-mailpoet
parent
a4282b6a3e
commit
d3db755489
@ -193,8 +193,16 @@ class Initializer {
|
||||
}
|
||||
|
||||
function setupHooks() {
|
||||
$hooks = new Hooks();
|
||||
$hooks->init();
|
||||
if(!$this->plugin_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$hooks = new Hooks();
|
||||
$hooks->init();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
}
|
||||
|
||||
function setupJSONAPI() {
|
||||
@ -224,6 +232,7 @@ class Initializer {
|
||||
}
|
||||
|
||||
function handleFailedInitialization($message) {
|
||||
Menu::addErrorPage();
|
||||
return WPNotice::displayError($message);
|
||||
}
|
||||
}
|
@ -576,6 +576,34 @@ class Menu {
|
||||
return (stripos($screen_id, 'mailpoet-') !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This error page is used when the initialization is failed
|
||||
* to display admin notices only
|
||||
*/
|
||||
static function addErrorPage() {
|
||||
if(!self::isOnMailPoetAdminPage()) {
|
||||
return false;
|
||||
}
|
||||
// Check if page already exists
|
||||
if(get_plugin_page_hook($_REQUEST['page'], '')
|
||||
|| get_plugin_page_hook($_REQUEST['page'], 'mailpoet-newsletters')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
add_submenu_page(
|
||||
true,
|
||||
'MailPoet',
|
||||
'MailPoet',
|
||||
Env::$required_permission,
|
||||
$_REQUEST['page'],
|
||||
array(__CLASS__, 'errorPageCallback')
|
||||
);
|
||||
}
|
||||
|
||||
static function errorPageCallback() {
|
||||
// Used for displaying admin notices only
|
||||
}
|
||||
|
||||
function checkMailPoetAPIKey(ServicesChecker $checker = null) {
|
||||
if(self::isOnMailPoetAdminPage()) {
|
||||
$show_notices = isset($_REQUEST['page'])
|
||||
|
Reference in New Issue
Block a user