Add an admin notice about the upcoming change in PHP requirements (PHP 7.3) (#36444)

* Add an admin notice about the upcoming change in PHP requirements

The minimum required PHP version will be 7.3 as of WooCommerce 7.7.
This adds a dismissable admin notice to PHP 7.2 users.

* Add changelog file

* Disable PHPCS warnings for TODO items (required by GitHub CI)

* Reformat the PHP 7.3 requirement notice to be more translators-friendly

* Add a translators note to pass linting

Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com>
This commit is contained in:
Néstor Soriano 2023-01-19 22:30:01 +01:00 committed by GitHub
parent 395f3b3eb5
commit 383c942fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Add an admin notice about the upcoming PHP version requirement change for PHP 7.2 users

View File

@ -8,6 +8,7 @@
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Utilities\Users;
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
defined( 'ABSPATH' ) || exit;
@ -16,6 +17,8 @@ defined( 'ABSPATH' ) || exit;
*/
class WC_Admin_Notices {
use AccessiblePrivateMethods;
/**
* Stores notices.
*
@ -54,6 +57,7 @@ class WC_Admin_Notices {
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
add_action( 'wp_loaded', array( __CLASS__, 'add_redirect_download_method_notice' ) );
add_action( 'admin_init', array( __CLASS__, 'hide_notices' ), 20 );
self::add_action( 'admin_init', array( __CLASS__, 'maybe_remove_php73_required_notice' ) );
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
@ -116,8 +120,53 @@ class WC_Admin_Notices {
self::add_notice( 'template_files' );
self::add_min_version_notice();
self::add_maxmind_missing_license_key_notice();
self::maybe_add_php73_required_notice();
}
// phpcs:disable Generic.Commenting.Todo.TaskFound
/**
* Add an admin notice about the bump of the required PHP version in WooCommerce 7.7
* if the current PHP version is too old.
*
* TODO: Remove this method in WooCommerce 7.7.
*/
private static function maybe_add_php73_required_notice() {
if ( version_compare( phpversion(), '7.3', '>=' ) ) {
return;
}
self::add_custom_notice(
'php73_required_in_woo_77',
sprintf(
'%s%s',
sprintf(
'<h4>%s</h4>',
esc_html__( 'PHP version requirements will change soon', 'woocommerce' )
),
sprintf(
// translators: Placeholder is a URL.
wpautop( wp_kses_data( __( 'WooCommerce 7.7, scheduled for <b>May 2023</b>, will require PHP 7.3 or newer to work. Your server is currently running an older version of PHP, so this change will impact your store. Upgrading to at least PHP 8.0 is recommended. <b><a href="%s">Learn more about this change.</a></b>', 'woocommerce' ) ) ),
'https://developer.woocommerce.com/2023/01/10/new-requirement-for-woocommerce-7-7-php-7-3/'
)
)
);
}
/**
* Remove the admin notice about the bump of the required PHP version in WooCommerce 7.7
* if the current PHP version is good.
*
* TODO: Remove this method in WooCommerce 7.7.
*/
private static function maybe_remove_php73_required_notice() {
if ( version_compare( phpversion(), '7.3', '>=' ) && self::has_notice( 'php73_required_in_woo_77' ) ) {
self::remove_notice( 'php73_required_in_woo_77' );
}
}
// phpcs:enable Generic.Commenting.Todo.TaskFound
/**
* Show a notice.
*