From 5f56921131043db31353f795c2123fbd4fa13671 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 12 Mar 2018 16:42:11 +0000 Subject: [PATCH] General: Introduce dashboard widget to inform administrators about outdated PHP versions. This new dashboard widget is shown on WordPress sites which are powered by a PHP version which WordPress considers outdated, in order to inform site owners about the resulting problems and to explain how to upgrade to a supported version. An education page for that purpose has been previously created that the widget links to. The link is translatable so that localized versions of the page can be referred to as they become available. The nag follows the example of the Browse Happy dashboard widget and is only visible for administrators, or network administrators when using multisite. To determine whether it needs to be displayed, a new wordpress.org API introduced prior is called that handles the version logic in a centralized location. Props flixos90, hedgefield, schlessera. Fixes #41191. git-svn-id: https://develop.svn.wordpress.org/trunk@42832 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/dashboard.css | 14 ++++ src/wp-admin/includes/dashboard.php | 96 ++++++++++++++++++++++- src/wp-includes/capabilities.php | 7 ++ tests/phpunit/tests/user/capabilities.php | 2 + 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/css/dashboard.css b/src/wp-admin/css/dashboard.css index f64cc92422..0353da78c1 100644 --- a/src/wp-admin/css/dashboard.css +++ b/src/wp-admin/css/dashboard.css @@ -1116,6 +1116,20 @@ a.rsswidget { font-size: 16px; } +/* PHP Nag */ +#dashboard_php_nag h2.hndle { + border-left: 4px solid #dc3232; +} + +#dashboard_php_nag h3 { + font-weight: 600; +} + +#dashboard_php_nag .button.button-hero { + display: block; + text-align: center; +} + /* =Media Queries -------------------------------------------------------------- */ diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 08d80baa88..fb7068ff11 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -35,6 +35,13 @@ function wp_dashboard_setup() { } } + // PHP Version + $response = wp_check_php_version(); + if ( $response && ! $response['is_acceptable'] && current_user_can( 'upgrade_php' ) ) { + $title = $response['is_secure'] ? __( 'Your site could be much faster!' ) : __( 'Your site could be much faster and more secure!' ); + wp_add_dashboard_widget( 'dashboard_php_nag', $title, 'wp_dashboard_php_nag' ); + } + // Right Now if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) { wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' ); @@ -178,8 +185,10 @@ function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_ $location = 'side'; } + $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' ); + $priority = 'core'; - if ( 'dashboard_browser_nag' === $widget_id ) { + if ( in_array( $widget_id, $high_priority_widgets, true ) ) { $priority = 'high'; } @@ -1599,6 +1608,91 @@ function wp_check_browser_version() { return $response; } +/** + * Displays the PHP upgrade nag. + * + * @since 5.0.0 + */ +function wp_dashboard_php_nag() { + $response = wp_check_php_version(); + + if ( ! $response ) { + return; + } + + $information_url = _x( 'https://wordpress.org/support/upgrade-php/', 'localized PHP upgrade information page' ); + + $msg = __( 'Hi, it’s your friends at WordPress here.' ); + if ( ! $response['is_secure'] ) { + $msg .= ' ' . __( 'We noticed that your site is running on an insecure version of PHP, which is why we’re showing you this notice.' ); + } else { + $msg .= ' ' . __( 'We noticed that your site is running on an outdated version of PHP, which is why we’re showing you this notice.' ); + } + + ?> +

+ +

+

+

+ +

+

+

+ +

+ +

+

+

+ array( 'administrator' ), 'update_languages' => array( 'administrator' ), 'deactivate_plugins' => array( 'administrator' ), + 'upgrade_php' => array( 'administrator' ), 'edit_categories' => array( 'administrator', 'editor' ), 'delete_categories' => array( 'administrator', 'editor' ), @@ -267,6 +268,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { 'install_languages' => array(), 'update_languages' => array(), 'deactivate_plugins' => array(), + 'upgrade_php' => array(), 'customize' => array( 'administrator' ), 'delete_site' => array( 'administrator' ),