Make WordPress Core

Ticket #41191: 41191.7.diff

File 41191.7.diff, 6.4 KB (added by flixos90, 7 years ago)
  • src/wp-admin/css/dashboard.css

     
    11161116        font-size: 16px;
    11171117}
    11181118
     1119/* PHP Nag */
     1120#dashboard_php_nag h2.hndle {
     1121        border-left: 4px solid #dc3232;
     1122}
     1123
     1124#dashboard_php_nag h3 {
     1125        font-weight: 600;
     1126}
     1127
     1128#dashboard_php_nag .button.button-hero {
     1129        display: block;
     1130        text-align: center;
     1131}
     1132
    11191133/* =Media Queries
    11201134-------------------------------------------------------------- */
    11211135
  • src/wp-admin/includes/dashboard.php

     
    3535                }
    3636        }
    3737
     38        // PHP Version
     39        $response = wp_check_php_version();
     40        if ( $response && ! $response['is_acceptable'] && current_user_can( 'upgrade_php' ) ) {
     41                $title = $response['is_secure'] ? __( 'Your site could be much faster!' ) : __( 'Your site could be much faster and more secure!' );
     42                wp_add_dashboard_widget( 'dashboard_php_nag', $title, 'wp_dashboard_php_nag' );
     43        }
     44
    3845        // Right Now
    3946        if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
    4047                wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
     
    178185                $location = 'side';
    179186        }
    180187
     188        $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
     189
    181190        $priority = 'core';
    182         if ( 'dashboard_browser_nag' === $widget_id ) {
     191        if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
    183192                $priority = 'high';
    184193        }
    185194
     
    16001609}
    16011610
    16021611/**
     1612 * Displays the PHP upgrade nag.
     1613 *
     1614 * @since 5.0.0
     1615 */
     1616function wp_dashboard_php_nag() {
     1617        $response = wp_check_php_version();
     1618
     1619        if ( ! $response ) {
     1620                return;
     1621        }
     1622
     1623        $information_url = _x( 'https://wordpress.org/support/upgrade-php/', 'localized PHP upgrade information page' );
     1624
     1625        $msg = __( 'Hi, it’s your friends at WordPress here.' );
     1626        if ( ! $response['is_secure'] ) {
     1627                $msg .= ' ' . __( 'We noticed that your site is running on an insecure version of PHP, which is why we’re showing you this notice.' );
     1628        } else {
     1629                $msg .= ' ' . __( 'We noticed that your site is running on an outdated version of PHP, which is why we’re showing you this notice.' );
     1630        }
     1631
     1632        ?>
     1633        <p><?php echo $msg; ?></p>
     1634
     1635        <h3><?php _e( 'What is PHP and why should I care?' ); ?></h3>
     1636        <p><?php _e( 'PHP is the programming language that WordPress is built on. Newer versions of PHP are both faster and more secure, so upgrading is better for your site, and better for the people who are building WordPress.' ); ?></p>
     1637        <p><?php _e( 'If you want to know exactly how PHP works and why it is important, continue reading.' ); ?></p>
     1638
     1639        <h3><?php _e( 'Okay, how do I update?' ); ?></h3>
     1640        <p><?php _e( 'The button below will take you to a page with more details on what PHP is, how to upgrade your PHP version, and what to do if it turns out you can&#8217;t.' ); ?></p>
     1641        <p>
     1642                <a class="button button-primary button-hero" href="<?php echo esc_url( $information_url ); ?>"><?php _e( 'Show me how to upgrade my PHP' ); ?></a>
     1643        </p>
     1644
     1645        <h3><?php _e( 'Thank you for taking the time to read this!' ); ?></h3>
     1646        <p><?php _e( 'If you carefully follow the instructions we&#8217;ve provided, upgrading shouldn&#8217;t take more than a few minutes, and it is generally very safe to do.' ); ?></p>
     1647        <p><?php _e( 'Good luck and happy blogging!' ); ?></p>
     1648        <?php
     1649}
     1650
     1651/**
     1652 * Checks if the user needs to upgrade PHP.
     1653 *
     1654 * @since 5.0.0
     1655 *
     1656 * @return array Array of PHP version data.
     1657 */
     1658function wp_check_php_version() {
     1659        $version = phpversion();
     1660        $key     = md5( $version );
     1661
     1662        $response = get_site_transient( 'php_check_' . $key );
     1663        if ( false === $response ) {
     1664                $url = 'http://api.wordpress.org/core/serve-happy/1.0/';
     1665                if ( wp_http_supports( array( 'ssl' ) ) ) {
     1666                        $url = set_url_scheme( $url, 'https' );
     1667                }
     1668
     1669                $url = add_query_arg( 'php_version', $version, $url );
     1670
     1671                $response = wp_remote_get( $url );
     1672
     1673                if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     1674                        return false;
     1675                }
     1676
     1677                /**
     1678                 * Response should be an array with:
     1679                 *  'recommended_version' - string - The PHP version recommended by WordPress
     1680                 *  'is_supported' - boolean - Whether the PHP version is actively supported
     1681                 *  'is_secure' - boolean - Whether the PHP version receives security updates
     1682                 *  'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress
     1683                 */
     1684                $response = json_decode( wp_remote_retrieve_body( $response ), true );
     1685
     1686                if ( ! is_array( $response ) ) {
     1687                        return false;
     1688                }
     1689
     1690                set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS );
     1691        }
     1692
     1693        return $response;
     1694}
     1695
     1696/**
    16031697 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
    16041698 */
    16051699function wp_dashboard_empty() {}
  • src/wp-includes/capabilities.php

     
    548548                                $caps[] = 'manage_options';
    549549                        }
    550550                        break;
     551                case 'upgrade_php':
     552                        if ( is_multisite() && ! is_super_admin( $user_id ) ) {
     553                                $caps[] = 'do_not_allow';
     554                        } else {
     555                                $caps[] = 'update_core';
     556                        }
     557                        break;
    551558                default:
    552559                        // Handle meta capabilities for custom post types.
    553560                        global $post_type_meta_caps;
  • tests/phpunit/tests/user/capabilities.php

     
    236236                        'install_languages'      => array( 'administrator' ),
    237237                        'update_languages'       => array( 'administrator' ),
    238238                        'deactivate_plugins'     => array( 'administrator' ),
     239                        'upgrade_php'            => array( 'administrator' ),
    239240
    240241                        'edit_categories'        => array( 'administrator', 'editor' ),
    241242                        'delete_categories'      => array( 'administrator', 'editor' ),
     
    267268                        'install_languages'      => array(),
    268269                        'update_languages'       => array(),
    269270                        'deactivate_plugins'     => array(),
     271                        'upgrade_php'            => array(),
    270272
    271273                        'customize'              => array( 'administrator' ),
    272274                        'delete_site'            => array( 'administrator' ),