From 0fdfa266afd314ae2d53ffff4079cc859b34a9d1 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 14 Sep 2022 22:17:53 +0000 Subject: [PATCH] Site health: - Add a check to `wp_check_php_version()` whether the current PHP version is lower than the next (desired) minimum version. - Set the next desired minimum PHP version to 7.2. - Use that check to update the warnings in the `wp_dashboard_php_nag()` widget, and on the Site Health screen. Props Clorith, SergeyBiryukov, ironprogrammer, azaozz. See #56199. git-svn-id: https://develop.svn.wordpress.org/trunk@54169 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/dashboard.css | 12 +-- .../includes/class-wp-site-health.php | 49 +++++++++--- src/wp-admin/includes/dashboard.php | 79 +++++++++++++------ src/wp-admin/includes/misc.php | 13 ++- 4 files changed, 113 insertions(+), 40 deletions(-) diff --git a/src/wp-admin/css/dashboard.css b/src/wp-admin/css/dashboard.css index 5a11e1273b..c9967c78e0 100644 --- a/src/wp-admin/css/dashboard.css +++ b/src/wp-admin/css/dashboard.css @@ -1186,7 +1186,8 @@ a.rsswidget { padding-right: 6px; } -#dashboard_php_nag.php-insecure .dashicons-warning { +#dashboard_php_nag.php-no-security-updates .dashicons-warning, +#dashboard_php_nag.php-version-lower-than-future-minimum .dashicons-warning { color: #d63638; } @@ -1198,14 +1199,15 @@ a.rsswidget { margin: 12px 0; } -#dashboard_php_nag h3 { - font-weight: 600; -} - #dashboard_php_nag .button .dashicons-external { line-height: 25px; } +.bigger-bolder-text { + font-weight: 600; + font-size: 14px; +} + /* =Media Queries -------------------------------------------------------------- */ diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 3c717cc659..141745c97a 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -741,7 +741,7 @@ class WP_Site_Health { '

%s

', sprintf( /* translators: %s: The minimum recommended PHP version. */ - __( 'PHP is the programming language used to build and maintain WordPress. Newer versions of PHP are created with increased performance in mind, so you may see a positive effect on your site’s performance. The minimum recommended version of PHP is %s.' ), + __( 'PHP is one of the programming languages used to build WordPress. Newer versions of PHP receive regular security updates and may increase your site’s performance. The minimum recommended version of PHP is %s.' ), $response ? $response['recommended_version'] : '' ) ), @@ -764,7 +764,7 @@ class WP_Site_Health { if ( $response['is_supported'] ) { $result['label'] = sprintf( /* translators: %s: The server PHP version. */ - __( 'Your site is running an older version of PHP (%s)' ), + __( 'Your site is running on an older version of PHP (%s)' ), PHP_VERSION ); $result['status'] = 'recommended'; @@ -772,11 +772,28 @@ class WP_Site_Health { return $result; } + // The PHP version is still receiving security fixes, but is lower than + // the expected minimum version that will be required by WordPress in the near future. + if ( $response['is_secure'] && $response['is_lower_than_future_minimum'] ) { + // The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates. + + $result['label'] = sprintf( + /* translators: %s: The server PHP version. */ + __( 'Your site is running on an outdated version of PHP (%s), which soon will not be supported by WordPress.' ), + PHP_VERSION + ); + + $result['status'] = 'critical'; + $result['badge']['label'] = __( 'Requirements' ); + + return $result; + } + // The PHP version is only receiving security fixes. if ( $response['is_secure'] ) { $result['label'] = sprintf( /* translators: %s: The server PHP version. */ - __( 'Your site is running an older version of PHP (%s), which should be updated' ), + __( 'Your site is running on an older version of PHP (%s), which should be updated' ), PHP_VERSION ); $result['status'] = 'recommended'; @@ -784,13 +801,25 @@ class WP_Site_Health { return $result; } - // Anything no longer secure must be updated. - $result['label'] = sprintf( - /* translators: %s: The server PHP version. */ - __( 'Your site is running an outdated version of PHP (%s), which requires an update' ), - PHP_VERSION - ); - $result['status'] = 'critical'; + // No more security updates for the PHP version, and lower than the expected minimum version required by WordPress. + if ( $response['is_lower_than_future_minimum'] ) { + $message = sprintf( + /* translators: %s: The server PHP version. */ + __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates and soon will not be supported by WordPress.' ), + PHP_VERSION + ); + } else { + // No more security updates for the PHP version, must be updated. + $message = sprintf( + /* translators: %s: The server PHP version. */ + __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ), + PHP_VERSION + ); + } + + $result['label'] = $message; + $result['status'] = 'critical'; + $result['badge']['label'] = __( 'Security' ); return $result; diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index d3dcfceaae..20759e7c9d 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -20,17 +20,18 @@ function wp_dashboard_setup() { global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; - $wp_dashboard_control_callbacks = array(); - $screen = get_current_screen(); + $screen = get_current_screen(); /* Register Widgets and Controls */ + $wp_dashboard_control_callbacks = array(); - $response = wp_check_browser_version(); + // Browser version + $check_browser = wp_check_browser_version(); - if ( $response && $response['upgrade'] ) { + if ( $check_browser && $check_browser['upgrade'] ) { add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' ); - if ( $response['insecure'] ) { + if ( $check_browser['insecure'] ) { wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); } else { wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' ); @@ -38,14 +39,19 @@ function wp_dashboard_setup() { } // PHP Version. - $response = wp_check_php_version(); + $check_php = wp_check_php_version(); - if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] - && current_user_can( 'update_php' ) - ) { - add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' ); + if ( $check_php && current_user_can( 'update_php' ) ) { + // If "not acceptable" the widget will be shown. + if ( isset( $check_php['is_acceptable'] ) && ! $check_php['is_acceptable'] ) { + add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' ); - wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' ); + if ( $check_php['is_lower_than_future_minimum'] ) { + wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' ); + } else { + wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' ); + } + } } // Site Health. @@ -1825,29 +1831,48 @@ function wp_dashboard_php_nag() { } if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) { - $msg = sprintf( + // The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates. + + if ( $response['is_lower_than_future_minimum'] ) { + $message = sprintf( + /* translators: %s: The server PHP version. */ + __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates and soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ), + PHP_VERSION + ); + } else { + $message = sprintf( + /* translators: %s: The server PHP version. */ + __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ), + PHP_VERSION + ); + } + } elseif ( $response['is_lower_than_future_minimum'] ) { + $message = sprintf( /* translators: %s: The server PHP version. */ - __( 'Your site is running an insecure version of PHP (%s), which should be updated.' ), + __( 'Your site is running on an outdated version of PHP (%s), which soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ), PHP_VERSION ); } else { - $msg = sprintf( + $message = sprintf( /* translators: %s: The server PHP version. */ - __( 'Your site is running an outdated version of PHP (%s), which should be updated.' ), + __( 'Your site is running on an outdated version of PHP (%s), which should be updated.' ), PHP_VERSION ); } ?> -

+

-

+

+

@@ -1879,8 +1904,14 @@ function wp_dashboard_php_nag() { function dashboard_php_nag_class( $classes ) { $response = wp_check_php_version(); - if ( $response && isset( $response['is_secure'] ) && ! $response['is_secure'] ) { - $classes[] = 'php-insecure'; + if ( ! $response ) { + return $classes; + } + + if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) { + $classes[] = 'php-no-security-updates'; + } elseif ( $response['is_lower_than_future_minimum'] ) { + $classes[] = 'php-version-lower-than-future-minimum'; } return $classes; diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index 65cf69ab31..78c1aab1c8 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/wp-admin/includes/misc.php @@ -1585,7 +1585,8 @@ function wp_check_php_version() { * 'recommended_version' - string - The PHP version recommended by WordPress. * 'is_supported' - boolean - Whether the PHP version is actively supported. * 'is_secure' - boolean - Whether the PHP version receives security updates. - * 'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress. + * 'is_acceptable' - boolean - Whether the PHP version is still acceptable or warnings + * should be shown and an update recommended. */ $response = json_decode( wp_remote_retrieve_body( $response ), true ); @@ -1613,5 +1614,15 @@ function wp_check_php_version() { $response['is_acceptable'] = (bool) apply_filters( 'wp_is_php_version_acceptable', true, $version ); } + $response['is_lower_than_future_minimum'] = false; + + // The minimum supported PHP version will be updated to 7.2. Check if the current version is lower. + if ( version_compare( $version, '7.2', '<' ) ) { + $response['is_lower_than_future_minimum'] = true; + + // Force showing of warnings. + $response['is_acceptable'] = false; + } + return $response; }