Requires PHP 5.5 or newer.

This commit is contained in:
Vlad
2018-08-06 21:55:42 -04:00
committed by pavel-mailpoet
parent 659f748dc9
commit 51c89d5aa1
3 changed files with 19 additions and 41 deletions

View File

@@ -15,36 +15,19 @@ class PHPVersionWarnings {
));
$error = null;
if (!$is_enabled) return $error;
if (is_null($error)) $error = $this->checkPHP54Version($php_version);
if (is_null($error)) $error = $this->checkPHP55Version($php_version);
if (is_null($error)) $error = $this->checkPHP70Version($php_version);
return $error;
}
function checkPHP54Version($php_version) {
function checkPHP70Version($php_version) {
$error_string = null;
if(version_compare($php_version, '5.5', '<')) {
$error_string = __('MailPoet requires PHP version 7 or newer. Please read our [link]instructions[/link] on how to upgrade your site.', 'mailpoet');
$error = Helpers::replaceLinkTags($error_string, 'https://beta.docs.mailpoet.com/article/251-upgrading-the-websites-php-version', array('target' => '_blank'));
return $this->displayWPNotice($error, false);
}
}
function checkPHP55Version($php_version) {
$error_string = null;
if(version_compare($php_version, '5.6', '<')) {
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'));
return $this->displayWPNotice($error, true);
}
}
$class = 'notice notice-error notice-php-warning mailpoet_notice_server is-dismissible';
private function displayWPNotice($message, $dismissible = false) {
$class = 'notice notice-error notice-php-warning mailpoet_notice_server';
if($dismissible) $class .= ' is-dismissible';
if(!get_transient('dismissed-php-version-outdated-notice')) {
return sprintf('<div class="%1$s" data-notice="php-version-outdated"><p>%2$s</p></div>', $class, $message);
return sprintf('<div class="%1$s" data-notice="php-version-outdated"><p>%2$s</p></div>', $class, $error);
}
}

View File

@@ -41,7 +41,7 @@ if(version_compare(get_bloginfo('version'), '4.6', '<')) {
}
// Check for minimum supported PHP version
if(version_compare(phpversion(), '5.4.0', '<')) {
if(version_compare(phpversion(), '5.5.0', '<')) {
add_action('admin_notices', 'mailpoet_php_version_notice');
// deactivate the plugin
add_action('admin_init', 'mailpoet_deactivate_plugin');
@@ -64,7 +64,7 @@ function mailpoet_php_version_notice() {
$notice = str_replace(
'[link]',
'<a href="//beta.docs.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#php_version" target="_blank">',
__('MailPoet plugin requires PHP version 5.4.0 or newer. Please read our [link]instructions[/link] on how to resolve this issue.', 'mailpoet')
__('MailPoet requires PHP version 7 or newer. Please read our [link]instructions[/link] on how to upgrade your site.', 'mailpoet')
);
$notice = str_replace('[/link]', '</a>', $notice);
printf('<div class="error"><p>%1$s</p></div>', $notice);

View File

@@ -16,38 +16,33 @@ class PHPVersionWarningsTest extends \MailPoetTest {
delete_transient('dismissed-php-version-outdated-notice');
}
function testItPrintsWarningFor53() {
$warning = $this->phpVersionWarning->init('5.3.2', true);
expect($warning)->contains('MailPoet requires PHP version 7 or newer.');
expect($warning)->notContains('is-dismissible');
}
function testItPrintsWarningFor54() {
$warning = $this->phpVersionWarning->init('5.4.1', true);
expect($warning)->contains('MailPoet requires PHP version 7 or newer.');
expect($warning)->notContains('is-dismissible');
}
function testItPrintsWarningFor55() {
$warning = $this->phpVersionWarning->init('5.5.3', true);
expect($warning)->contains('Your website is running on PHP 5.5.3');
expect($warning)->contains('is-dismissible');
expect($warning)->contains('MailPoet will require version 7');
}
function testItPrintsNoWarningFor56() {
function testItPrintsWarningFor56() {
$warning = $this->phpVersionWarning->init('5.6.3', true);
expect($warning)->contains('Your website is running on PHP 5.6');
expect($warning)->contains('MailPoet will require version 7');
}
function testItPrintsNoWarningFor70() {
$warning = $this->phpVersionWarning->init('7.0', true);
expect($warning)->null();
}
function testItPrintsNoWarningWhenDisabled() {
$warning = $this->phpVersionWarning->init('5.3.2', false);
$warning = $this->phpVersionWarning->init('5.5.3', false);
expect($warning)->null();
}
function testItPrintsNoWarningWhenDismised() {
$this->phpVersionWarning->init('5.3.2', true);
$this->phpVersionWarning->init('5.5.3', true);
do_action('wp_ajax_dismissed_notice_handler');
$warning = $this->phpVersionWarning->init('5.3.2', true);
$warning = $this->phpVersionWarning->init('5.5.3', true);
expect($warning)->null();
}