WordPress.org

Make WordPress Core

Ticket #41191: 41191.4.diff

File 41191.4.diff, 6.3 KB (added by flixos90, 4 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 .notice-upgrade-button-wrap {
     1129        text-align: center;
     1130}
     1131
     1132#dashboard_php_nag .button.button-hero.notice-upgrade-button {
     1133        display: block;
     1134        margin-bottom: 1em;
     1135        text-align: center;
     1136}
     1137
    11191138/* =Media Queries
    11201139-------------------------------------------------------------- */
    11211140
  • src/wp-admin/includes/dashboard.php

     
    3535                }
    3636        }
    3737
     38        // PHP Version
     39        $response = wp_check_php_version();
     40        if ( $response && $response['out_of_date'] && current_user_can( 'upgrade_php' ) ) {
     41                $title = ! $response['receiving_security_updates'] ? __( 'Your site could be much faster and more secure!' ) : __( 'Your site could be much faster!' );
     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' );
     
    16001607}
    16011608
    16021609/**
     1610 * Displays the PHP upgrade nag.
     1611 *
     1612 * @since 5.0.0
     1613 */
     1614function wp_dashboard_php_nag() {
     1615        $response = wp_check_php_version();
     1616
     1617        if ( ! $response ) {
     1618                return;
     1619        }
     1620
     1621        $information_url = _x( 'https://wordpress.org/support/upgrade-php/', 'localized PHP upgrade information page' );
     1622        $update_url      = $response['update_url'];
     1623
     1624        /**
     1625         * Filters the URL to environment-specific instructions on how to upgrade the PHP version.
     1626         *
     1627         * This can also be an empty string, if no such URL is available.
     1628         *
     1629         * @since 5.0.0
     1630         *
     1631         * @param string $update_url PHP version upgrade URL.
     1632         */
     1633        $update_url = apply_filters( 'php_update_url', $update_url );
     1634
     1635        $msg = __( 'Hi, it's your friends at WordPress here.' );
     1636        if ( ! $response['receiving_security_updates'] ) {
     1637                $msg .= ' ' . __( 'We noticed that your site is running on an insecure version of PHP, which is why we're showing you this notice.' );
     1638        } else {
     1639                $msg .= ' ' . __( 'We noticed that your site is running on an outdated version of PHP, which is why we're showing you this notice.' );
     1640        }
     1641
     1642        ?>
     1643        <p><?php echo $msg; ?></p>
     1644
     1645        <h3><?php _e( 'What is PHP and why should I care?' ); ?></h3>
     1646        <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>
     1647        <p><?php _e( 'If you want to know exactly how PHP works and why it is important, continue reading.' ); ?></p>
     1648
     1649        <h3><?php _e( 'Okay, how do I update?' ); ?></h3>
     1650        <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&apos;t.' ); ?></p>
     1651        <p class="notice-upgrade-button-wrap">
     1652                <?php if ( ! empty( $update_url ) ) : ?>
     1653                        <a class="notice-upgrade-button button button-primary button-hero" href="<?php echo esc_url( $information_url ); ?>"><?php _e( 'Learn more about upgrading PHP' ); ?></a>
     1654                        <a href="<?php echo esc_url( $update_url ); ?>"><?php _e( 'or upgrade right away' ); ?></a>
     1655                <?php else : ?>
     1656                        <a class="notice-upgrade-button button button-primary button-hero" href="<?php echo esc_url( $information_url ); ?>"><?php _e( 'Show me how to upgrade my PHP' ); ?></a>
     1657                <?php endif; ?>
     1658        </p>
     1659
     1660        <h3><?php _e( 'Thank you for taking the time to read this!' ); ?></h3>
     1661        <p><?php _e( 'If you follow the instructions we&apos;ve provided to the letter, upgrading shouldn&apos;t take more than a few minutes, and it is generally very safe to do.' ); ?></p>
     1662        <p><?php _e( 'Good luck and happy blogging!' ); ?></p>
     1663        <?php
     1664}
     1665
     1666/**
     1667 * Checks if the user needs to upgrade PHP.
     1668 *
     1669 * @since 5.0.0
     1670 *
     1671 * @return array Array of PHP version data.
     1672 */
     1673function wp_check_php_version() {
     1674        $version = phpversion();
     1675        $key     = md5( $version );
     1676
     1677        $response = get_site_transient( 'php_check_' . $key );
     1678        if ( false === $response ) {
     1679                $url = 'http://api.wordpress.org/core/serve-happy/1.0/';
     1680                if ( wp_http_supports( array( 'ssl' ) ) ) {
     1681                        $url = set_url_scheme( $url, 'https' );
     1682                }
     1683
     1684                $url = add_query_arg( 'php_version', $version, $url );
     1685
     1686                $response = wp_remote_get( $url );
     1687
     1688                if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     1689                        return false;
     1690                }
     1691
     1692                /**
     1693                 * Response should be an array with:
     1694                 *  'php_version' - string - The PHP version the site is using
     1695                 *  'recommended_php' - string - The PHP version recommended by WordPress
     1696                 *  'secure_php' - string - The minimum PHP version considered secure
     1697                 *  'status' - string - Either 'ok', 'out_of_date' or 'no_security_updates'
     1698                 *  'update_url' - string - Provider-specific URL if available, or empty string
     1699                 *  'out_of_date' - boolean - Whether the PHP version needs to be upgraded
     1700                 *  'receiving_security_updates' - boolean - Whether the PHP version receives security updates
     1701                 */
     1702                $response = json_decode( wp_remote_retrieve_body( $response ), true );
     1703
     1704                if ( ! is_array( $response ) ) {
     1705                        return false;
     1706                }
     1707
     1708                set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS );
     1709        }
     1710
     1711        return $response;
     1712}
     1713
     1714/**
    16031715 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
    16041716 */
    16051717function wp_dashboard_empty() {}
  • src/wp-includes/capabilities.php

     
    550550                                $caps[] = 'manage_options';
    551551                        }
    552552                        break;
     553                case 'upgrade_php':
     554                        if ( is_multisite() && ! is_super_admin( $user_id ) ) {
     555                                $caps[] = 'do_not_allow';
     556                        } else {
     557                                $caps[] = 'update_core';
     558                        }
     559                        break;
    553560                default:
    554561                        // Handle meta capabilities for custom post types.
    555562                        global $post_type_meta_caps;