From 16b35340f4e0493ce877c8d205683f3cbe0e5341 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 26 Jun 2020 00:27:09 +0000 Subject: [PATCH] Site Health: Improve the error message displayed when activating a plugin that requires a higher version of PHP or WordPress. This adds some extra details to the message: * The current PHP or WordPress version. * The plugin's minimum required PHP or WordPress version. * A link to the support documentation on how to update PHP. Props stuffradio, johnbillion, garrett-eclipse, sabernhardt, williampatton, SergeyBiryukov. Fixes #48245. Built from https://develop.svn.wordpress.org/trunk@48172 git-svn-id: http://core.svn.wordpress.org/trunk@47941 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 50 +++++++++++++++++++++---------- wp-admin/includes/update-core.php | 7 ++++- wp-admin/install.php | 38 ++++++++++++++++++----- wp-admin/update-core.php | 1 + wp-admin/upgrade.php | 6 +++- wp-includes/version.php | 2 +- 6 files changed, 79 insertions(+), 25 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 3220c8182f..914ef15df2 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -1148,32 +1148,52 @@ function validate_plugin_requirements( $plugin ) { $compatible_wp = is_wp_version_compatible( $requirements['requires'] ); $compatible_php = is_php_version_compatible( $requirements['requires_php'] ); + /* translators: %s: URL to Update PHP page. */ + $php_update_message = '

' . sprintf( + __( 'Learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) + ); + + $annotation = wp_get_update_php_annotation(); + + if ( $annotation ) { + $php_update_message .= '

' . $annotation . ''; + } + if ( ! $compatible_wp && ! $compatible_php ) { return new WP_Error( 'plugin_wp_php_incompatible', - sprintf( - /* translators: %s: Plugin name. */ - _x( 'Error: Current WordPress and PHP versions do not meet minimum requirements for %s.', 'plugin' ), - $plugin_headers['Name'] - ) + '

' . sprintf( + /* translators: 1: Current WordPress version, 2: Current PHP version, 3: Plugin name, 4: Required WordPress version, 5: Required PHP version. */ + _x( 'Error: Current versions of WordPress (%1$s) and PHP (%2$s) do not meet minimum requirements for %3$s. The plugin requires WordPress %4$s and PHP %5$s.', 'plugin' ), + get_bloginfo( 'version' ), + phpversion(), + $plugin_headers['Name'], + $requirements['requires'], + $requirements['requires_php'] + ) . $php_update_message . '

' ); } elseif ( ! $compatible_php ) { return new WP_Error( 'plugin_php_incompatible', - sprintf( - /* translators: %s: Plugin name. */ - _x( 'Error: Current PHP version does not meet minimum requirements for %s.', 'plugin' ), - $plugin_headers['Name'] - ) + '

' . sprintf( + /* translators: 1: Current PHP version, 2: Plugin name, 3: Required PHP version. */ + _x( 'Error: Current PHP version (%1$s) does not meet minimum requirements for %2$s. The plugin requires PHP %3$s.', 'plugin' ), + phpversion(), + $plugin_headers['Name'], + $requirements['requires_php'] + ) . $php_update_message . '

' ); } elseif ( ! $compatible_wp ) { return new WP_Error( 'plugin_wp_incompatible', - sprintf( - /* translators: %s: Plugin name. */ - _x( 'Error: Current WordPress version does not meet minimum requirements for %s.', 'plugin' ), - $plugin_headers['Name'] - ) + '

' . sprintf( + /* translators: 1: Current WordPress version, 2: Plugin name, 3: Required WordPress version. */ + _x( 'Error: Current WordPress version (%1$s) does not meet minimum requirements for %2$s. The plugin requires WordPress %3$s.', 'plugin' ), + get_bloginfo( 'version' ), + $plugin_headers['Name'], + $requirements['requires'] + ) . '

' ); } diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index 240d6be4ee..731ddbc511 100644 --- a/wp-admin/includes/update-core.php +++ b/wp-admin/includes/update-core.php @@ -961,12 +961,17 @@ function update_core( $from, $to ) { } $php_update_message = ''; + if ( function_exists( 'wp_get_update_php_url' ) ) { /* translators: %s: URL to Update PHP page. */ - $php_update_message = '

' . sprintf( __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); + $php_update_message = '

' . sprintf( + __( 'Learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) + ); if ( function_exists( 'wp_get_update_php_annotation' ) ) { $annotation = wp_get_update_php_annotation(); + if ( $annotation ) { $php_update_message .= '

' . $annotation . ''; } diff --git a/wp-admin/install.php b/wp-admin/install.php index 8e09f1b0d5..411f29534b 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -240,22 +240,46 @@ $version_url = sprintf( ); /* translators: %s: URL to Update PHP page. */ -$php_update_message = '

' . sprintf( __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); +$php_update_message = '

' . sprintf( + __( 'Learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) +); $annotation = wp_get_update_php_annotation(); + if ( $annotation ) { $php_update_message .= '

' . $annotation . ''; } if ( ! $mysql_compat && ! $php_compat ) { - /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */ - $compat = sprintf( __( 'You cannot install because WordPress %2$s requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ), $version_url, $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) . $php_update_message; + $compat = sprintf( + /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */ + __( 'You cannot install because WordPress %2$s requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ), + $version_url, + $wp_version, + $required_php_version, + $required_mysql_version, + $php_version, + $mysql_version + ) . $php_update_message; } elseif ( ! $php_compat ) { - /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */ - $compat = sprintf( __( 'You cannot install because WordPress %2$s requires PHP version %3$s or higher. You are running version %4$s.' ), $version_url, $wp_version, $required_php_version, $php_version ) . $php_update_message; + $compat = sprintf( + /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */ + __( 'You cannot install because WordPress %2$s requires PHP version %3$s or higher. You are running version %4$s.' ), + $version_url, + $wp_version, + $required_php_version, + $php_version + ) . $php_update_message; } elseif ( ! $mysql_compat ) { - /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */ - $compat = sprintf( __( 'You cannot install because WordPress %2$s requires MySQL version %3$s or higher. You are running version %4$s.' ), $version_url, $wp_version, $required_mysql_version, $mysql_version ); + $compat = sprintf( + /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */ + __( 'You cannot install because WordPress %2$s requires MySQL version %3$s or higher. You are running version %4$s.' ), + $version_url, + $wp_version, + $required_mysql_version, + $mysql_version + ); } if ( ! $mysql_compat || ! $php_compat ) { diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index 0c4391ea01..84547f9ed2 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -88,6 +88,7 @@ function list_core_update( $update ) { ); $annotation = wp_get_update_php_annotation(); + if ( $annotation ) { $php_update_message .= '

' . $annotation . ''; } diff --git a/wp-admin/upgrade.php b/wp-admin/upgrade.php index 0045bf77c8..cf3991e897 100644 --- a/wp-admin/upgrade.php +++ b/wp-admin/upgrade.php @@ -82,9 +82,13 @@ elseif ( ! $php_compat || ! $mysql_compat ) : ); /* translators: %s: URL to Update PHP page. */ - $php_update_message = '

' . sprintf( __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); + $php_update_message = '

' . sprintf( + __( 'Learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) + ); $annotation = wp_get_update_php_annotation(); + if ( $annotation ) { $php_update_message .= '

' . $annotation . ''; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 477577b996..9d945ed203 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48171'; +$wp_version = '5.5-alpha-48172'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.