Display warning on Email pages

[PREMIUM-28]
This commit is contained in:
Pavel Dohnal
2017-08-28 16:43:54 +02:00
parent 7463e0d1f1
commit b74be8777a
3 changed files with 17 additions and 10 deletions

View File

@ -671,10 +671,8 @@ class Menu {
function checkPremiumKey(ServicesChecker $checker = null) {
if(self::isOnMailPoetAdminPage()) {
$show_notices = isset($_REQUEST['page'])
&& stripos($_REQUEST['page'], self::MAIN_PAGE_SLUG) === false;
$checker = $checker ?: new ServicesChecker();
$this->premium_key_valid = $checker->isPremiumKeyValid($show_notices);
$this->premium_key_valid = $checker->isPremiumKeyValid($show_notices = true);
}
}

View File

@ -70,9 +70,9 @@ class ServicesChecker {
|| $premium_key['state'] === Bridge::KEY_ALREADY_USED
) {
if($display_error_notice) {
$errorString = __('[link1]Register[/link1] your copy of the MailPoet Premium plugin to receive access to automatic upgrades and support. Need a license key? [link2]Purchase one now.[/link2]', 'mailpoet');
$error_string = __('[link1]Register[/link1] your copy of the MailPoet Premium plugin to receive access to automatic upgrades and support. Need a license key? [link2]Purchase one now.[/link2]', 'mailpoet');
$error = Helpers::replaceLinkTags(
$errorString,
$error_string,
'admin.php?page=mailpoet-settings#premium',
array(),
'link1'
@ -83,7 +83,7 @@ class ServicesChecker {
array(),
'link2'
);
WPNotice::displayWarning($error);
WPNotice::displayInlineWarning($error);
}
return false;
} elseif($premium_key['state'] === Bridge::KEY_EXPIRING
@ -98,7 +98,7 @@ class ServicesChecker {
array('target' => '_blank')
);
$error = sprintf($error, $date);
WPNotice::displayWarning($error);
WPNotice::displayInlineWarning($error);
}
return true;
} elseif($premium_key['state'] === Bridge::KEY_VALID) {

View File

@ -10,10 +10,12 @@ class Notice {
private $type;
private $message;
private $display_inline;
function __construct($type, $message) {
function __construct($type, $message, $display_inline) {
$this->type = $type;
$this->message = $message;
$this->display_inline = $display_inline;
}
static function displayError($message) {
@ -29,6 +31,10 @@ class Notice {
self::createNotice(self::TYPE_WARNING, $message);
}
static function displayInlineWarning($message) {
self::createNotice(self::TYPE_WARNING, $message, true);
}
static function displaySuccess($message) {
self::createNotice(self::TYPE_SUCCESS, $message);
}
@ -37,13 +43,16 @@ class Notice {
self::createNotice(self::TYPE_INFO, $message);
}
protected static function createNotice($type, $message) {
$notice = new Notice($type, $message);
protected static function createNotice($type, $message, $display_inline = false) {
$notice = new Notice($type, $message, $display_inline);
add_action('admin_notices', array($notice, 'displayWPNotice'));
}
function displayWPNotice() {
$class = sprintf('notice notice-%s mailpoet_notice_server', $this->type);
if($this->display_inline) {
$class .= ' inline';
}
$message = nl2br($this->message);
printf('<div class="%1$s"><p>%2$s</p></div>', $class, $message);