From 383c942fa750dccb2e5328a236b6db7557a557d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Soriano?= Date: Thu, 19 Jan 2023 22:30:01 +0100 Subject: [PATCH] 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> --- .../changelog/add-php-73-version-bump-notice | 4 ++ .../includes/admin/class-wc-admin-notices.php | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 plugins/woocommerce/changelog/add-php-73-version-bump-notice diff --git a/plugins/woocommerce/changelog/add-php-73-version-bump-notice b/plugins/woocommerce/changelog/add-php-73-version-bump-notice new file mode 100644 index 00000000000..09a544979f4 --- /dev/null +++ b/plugins/woocommerce/changelog/add-php-73-version-bump-notice @@ -0,0 +1,4 @@ +Significance: patch +Type: add + +Add an admin notice about the upcoming PHP version requirement change for PHP 7.2 users diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-notices.php b/plugins/woocommerce/includes/admin/class-wc-admin-notices.php index 1bb51f64c04..05f528fc04c 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-notices.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-notices.php @@ -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( + '

%s

', + esc_html__( 'PHP version requirements will change soon', 'woocommerce' ) + ), + sprintf( + // translators: Placeholder is a URL. + wpautop( wp_kses_data( __( 'WooCommerce 7.7, scheduled for May 2023, 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. Learn more about this change.', '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. *