Make WordPress Core


Ignore:
Timestamp:
02/08/2019 01:52:17 AM (7 years ago)
Author:
peterwilsoncc
Message:

Admin: Improve logic of PHP version check on about page.

Props noisysocks, peterwilsoncc.
See #46161.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/misc.php

    r44667 r44735  
    20122012    }
    20132013}
     2014
     2015/**
     2016 * Checks if the user needs to update PHP.
     2017 *
     2018 * @since 5.1.0
     2019 *
     2020 * @return array|false $response Array of PHP version data. False on failure.
     2021 */
     2022function wp_check_php_version() {
     2023    $version = phpversion();
     2024    $key     = md5( $version );
     2025
     2026    $response = get_site_transient( 'php_check_' . $key );
     2027    if ( false === $response ) {
     2028        $url = 'http://api.wordpress.org/core/serve-happy/1.0/';
     2029        if ( wp_http_supports( array( 'ssl' ) ) ) {
     2030            $url = set_url_scheme( $url, 'https' );
     2031        }
     2032
     2033        $url = add_query_arg( 'php_version', $version, $url );
     2034
     2035        $response = wp_remote_get( $url );
     2036
     2037        if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
     2038            return false;
     2039        }
     2040
     2041        /**
     2042         * Response should be an array with:
     2043         *  'recommended_version' - string - The PHP version recommended by WordPress.
     2044         *  'is_supported' - boolean - Whether the PHP version is actively supported.
     2045         *  'is_secure' - boolean - Whether the PHP version receives security updates.
     2046         *  'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress.
     2047         */
     2048        $response = json_decode( wp_remote_retrieve_body( $response ), true );
     2049
     2050        if ( ! is_array( $response ) ) {
     2051            return false;
     2052        }
     2053
     2054        set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS );
     2055    }
     2056
     2057    return $response;
     2058}
Note: See TracChangeset for help on using the changeset viewer.