Display PHP version warning via notice filter instead of stdout

This commit is contained in:
Tautvidas Sipavičius
2018-08-23 15:06:21 +03:00
parent ac73b4ee0a
commit c68f58a7c0
4 changed files with 60 additions and 28 deletions

View File

@@ -3,6 +3,7 @@
namespace MailPoet\Config;
use MailPoet\Util\Helpers;
use MailPoet\WP\Notice as WPNotice;
class PHPVersionWarnings {
@@ -13,22 +14,24 @@ class PHPVersionWarnings {
$this,
'ajaxDismissNoticeHandler'
));
$error = null;
if (!$is_enabled) return $error;
if (is_null($error)) $error = $this->checkPHP70Version($php_version);
return $error;
if ($is_enabled && $this->isOutdatedPHPVersion($php_version)) {
return $this->displayError($php_version);
}
}
function checkPHP70Version($php_version) {
$error_string = null;
if(version_compare($php_version, '7.0', '<') && !get_transient('dismissed-php-version-outdated-notice')) {
$error_string = __('Your website is running on PHP %s. MailPoet will require version 7 by the end of the year. Please consider upgrading your site\'s PHP version. [link]Your host can help you.[/link]', 'mailpoet');
$error_string = sprintf($error_string, $php_version);
$error = Helpers::replaceLinkTags($error_string, 'https://beta.docs.mailpoet.com/article/251-upgrading-the-websites-php-version', array('target' => '_blank'));
$class = 'notice notice-error notice-php-warning mailpoet_notice_server is-dismissible';
function isOutdatedPHPVersion($php_version) {
return version_compare($php_version, '7.0', '<') && !get_transient('dismissed-php-version-outdated-notice');
}
return sprintf('<div class="%1$s" data-notice="php-version-outdated"><p>%2$s</p></div>', $class, $error);
}
function displayError($php_version) {
$error_string = __('Your website is running on PHP %s. MailPoet will require version 7 by the end of the year. Please consider upgrading your site\'s PHP version. [link]Your host can help you.[/link]', 'mailpoet');
$error_string = sprintf($error_string, $php_version);
$error = Helpers::replaceLinkTags($error_string, 'https://beta.docs.mailpoet.com/article/251-upgrading-the-websites-php-version', array('target' => '_blank'));
$classes = 'notice-php-warning is-dismissible';
$transient = 'php-version-outdated';
return WPNotice::displayError($error, $classes, $transient);
}
function ajaxDismissNoticeHandler() {