From 94fb16f03f7b5f2bcbbbf3ce2a2d4ce0e53c12f0 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 16 Jan 2019 17:07:00 +0000 Subject: [PATCH] Plugins: Use centralized API to display information about updating PHP when a plugin requires a higher version. This changeset uses the API functions introduced in [44476] to link to the resource about updating PHP when highlighting a plugin's required PHP version is not met. It furthermore expands them, introducing a new `wp_update_php_annotation()` function that prints the markup to indicate that the default URL has been altered by the web host, allowing it to be reused universally. Furthermore, this changeset adds missing `update_php` capability checks before displaying the information about updating PHP. Props afragen. Fixes #45986. See #43986, #45686. Built from https://develop.svn.wordpress.org/trunk@44627 git-svn-id: http://core.svn.wordpress.org/trunk@44458 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-plugin-install-list-table.php | 35 ++++++++++++------- wp-admin/includes/dashboard.php | 19 ++-------- wp-admin/includes/plugin-install.php | 19 ++++++---- wp-includes/functions.php | 25 +++++++++++++ wp-includes/version.php | 2 +- 5 files changed, 64 insertions(+), 36 deletions(-) diff --git a/wp-admin/includes/class-wp-plugin-install-list-table.php b/wp-admin/includes/class-wp-plugin-install-list-table.php index 7cc37c056f..03c7e81c47 100644 --- a/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -635,19 +635,27 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { echo '

'; if ( ! $compatible_php && ! $compatible_wp ) { _e( 'This plugin doesn’t work with your versions of WordPress and PHP. ' ); - if ( current_user_can( 'update_core' ) ) { + if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { printf( - /* translators: 1: "Update WordPress" screen URL, 2: "Updating PHP" page URL */ + /* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */ __( 'Please update WordPress, and then learn more about updating PHP.' ), self_admin_url( 'update-core.php' ), - esc_url( __( 'https://wordpress.org/support/update-php/' ) ) + esc_url( wp_get_update_php_url() ) ); - } else { + wp_update_php_annotation(); + } elseif ( current_user_can( 'update_core' ) ) { printf( - /* translators: %s: "Updating PHP" page URL */ - __( 'Learn more about updating PHP.' ), - esc_url( __( 'https://wordpress.org/support/update-php/' ) ) + /* translators: %s: "Update WordPress" screen URL */ + __( 'Please update WordPress.' ), + self_admin_url( 'update-core.php' ) ); + } elseif ( current_user_can( 'update_php' ) ) { + printf( + /* translators: %s: "Update PHP" page URL */ + __( 'Learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) + ); + wp_update_php_annotation(); } } elseif ( ! $compatible_wp ) { _e( 'This plugin doesn’t work with your version of WordPress. ' ); @@ -660,11 +668,14 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { } } elseif ( ! $compatible_php ) { _e( 'This plugin doesn’t work with your version of PHP. ' ); - printf( - /* translators: %s: "Updating PHP" page URL */ - __( 'Learn more about updating PHP.' ), - esc_url( __( 'https://wordpress.org/support/update-php/' ) ) - ); + if ( current_user_can( 'update_php' ) ) { + printf( + /* translators: %s: "Update PHP" page URL */ + __( 'Learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) + ); + wp_update_php_annotation(); + } } echo '

'; } diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index e8a0004617..6456c4756a 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -1626,9 +1626,6 @@ function wp_dashboard_php_nag() { $msg = __( 'WordPress has detected that your site is running on an outdated version of PHP.' ); } - $update_url = wp_get_update_php_url(); - $default_url = wp_get_default_update_php_url(); - ?>

@@ -1639,7 +1636,7 @@ function wp_dashboard_php_nag() { %2$s %3$s', - esc_url( $update_url ), + esc_url( wp_get_update_php_url() ), __( 'Learn more about updating PHP' ), /* translators: accessibility text */ __( '(opens in a new tab)' ) @@ -1648,19 +1645,7 @@ function wp_dashboard_php_nag() {

-

- see the official WordPress documentation.' ), - esc_url( $default_url ) - ); - ?> -

-

'; - printf( - /* translators: "Updating PHP" page URL */ - __( 'Error: This plugin requires a newer version of PHP, so unfortunately you cannot install it. Click here to learn more about updating PHP.' ), - esc_url( __( 'https://wordpress.org/support/update-php/' ) ) - ); - echo '

'; + _e( 'Error: This plugin requires a newer version of PHP.' ); + if ( current_user_can( 'update_php' ) ) { + printf( + /* translators: %s: "Update PHP" page URL */ + ' ' . __( 'Click here to learn more about updating PHP.' ), + esc_url( wp_get_update_php_url() ) + ); + echo '

'; + wp_update_php_annotation(); + } else { + echo '

'; + } + echo ''; } if ( ! $tested_wp ) { diff --git a/wp-includes/functions.php b/wp-includes/functions.php index ca91c53e00..9552455d05 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -6716,3 +6716,28 @@ function wp_get_update_php_url() { function wp_get_default_update_php_url() { return _x( 'https://wordpress.org/support/update-php/', 'localized PHP upgrade information page' ); } + +/** + * Prints the default annotation for the web host altering the "Update PHP" page URL. + * + * This function is to be used after {@see wp_get_update_php_url()} to display a consistent + * annotation if the web host has altered the default "Update PHP" page URL. + * + * @since 5.1.0 + */ +function wp_update_php_annotation() { + $update_url = wp_get_update_php_url(); + $default_url = wp_get_default_update_php_url(); + + if ( $update_url === $default_url ) { + return; + } + + echo '

'; + printf( + /* translators: %s: default Update PHP page URL */ + __( 'This resource is provided by your web host, and is specific to your site. For more information, see the official WordPress documentation.' ), + esc_url( $default_url ) + ); + echo'

'; +} diff --git a/wp-includes/version.php b/wp-includes/version.php index 098883f6db..885e75fea6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta1-44626'; +$wp_version = '5.1-beta1-44627'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.