Show warning only on plugins page

[PREMIUM-28]
This commit is contained in:
Pavel Dohnal
2017-08-29 11:22:39 +02:00
parent b74be8777a
commit c75b6bd7eb
3 changed files with 9 additions and 18 deletions

View File

@ -670,10 +670,10 @@ class Menu {
} }
function checkPremiumKey(ServicesChecker $checker = null) { function checkPremiumKey(ServicesChecker $checker = null) {
if(self::isOnMailPoetAdminPage()) { $show_notices = isset($_SERVER['SCRIPT_NAME'])
$checker = $checker ?: new ServicesChecker(); && stripos($_SERVER['SCRIPT_NAME'], 'plugins.php') !== false;
$this->premium_key_valid = $checker->isPremiumKeyValid($show_notices = true); $checker = $checker ?: new ServicesChecker();
} $this->premium_key_valid = $checker->isPremiumKeyValid($show_notices);
} }
private function getLimitPerPage($model = null) { private function getLimitPerPage($model = null) {

View File

@ -83,7 +83,7 @@ class ServicesChecker {
array(), array(),
'link2' 'link2'
); );
WPNotice::displayInlineWarning($error); WPNotice::displayWarning($error);
} }
return false; return false;
} elseif($premium_key['state'] === Bridge::KEY_EXPIRING } elseif($premium_key['state'] === Bridge::KEY_EXPIRING
@ -98,7 +98,7 @@ class ServicesChecker {
array('target' => '_blank') array('target' => '_blank')
); );
$error = sprintf($error, $date); $error = sprintf($error, $date);
WPNotice::displayInlineWarning($error); WPNotice::displayWarning($error);
} }
return true; return true;
} elseif($premium_key['state'] === Bridge::KEY_VALID) { } elseif($premium_key['state'] === Bridge::KEY_VALID) {

View File

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