Admin: Improve logic of PHP version check on about page.
Props noisysocks, peterwilsoncc. See #46161. Built from https://develop.svn.wordpress.org/trunk@44735 git-svn-id: http://core.svn.wordpress.org/trunk@44567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e24bf1c278
commit
729c8e875f
|
@ -88,7 +88,10 @@ include( ABSPATH . 'wp-admin/admin-header.php' );
|
||||||
|
|
||||||
|
|
||||||
<div class="feature-section one-col cta">
|
<div class="feature-section one-col cta">
|
||||||
<?php if ( true ) : ?>
|
<?php
|
||||||
|
$response = wp_check_php_version();
|
||||||
|
if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] && current_user_can( 'update_php' ) ) :
|
||||||
|
?>
|
||||||
<p><em><?php _e( 'WordPress has detected your site is running an outdated version of PHP. You will see this notice on your dashboard with instructions for contacting your host.' ); ?></em></p>
|
<p><em><?php _e( 'WordPress has detected your site is running an outdated version of PHP. You will see this notice on your dashboard with instructions for contacting your host.' ); ?></em></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
|
@ -1666,51 +1666,6 @@ function dashboard_php_nag_class( $classes ) {
|
||||||
return $classes;
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the user needs to update PHP.
|
|
||||||
*
|
|
||||||
* @since 5.1.0
|
|
||||||
*
|
|
||||||
* @return array|false $response Array of PHP version data. False on failure.
|
|
||||||
*/
|
|
||||||
function wp_check_php_version() {
|
|
||||||
$version = phpversion();
|
|
||||||
$key = md5( $version );
|
|
||||||
|
|
||||||
$response = get_site_transient( 'php_check_' . $key );
|
|
||||||
if ( false === $response ) {
|
|
||||||
$url = 'http://api.wordpress.org/core/serve-happy/1.0/';
|
|
||||||
if ( wp_http_supports( array( 'ssl' ) ) ) {
|
|
||||||
$url = set_url_scheme( $url, 'https' );
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = add_query_arg( 'php_version', $version, $url );
|
|
||||||
|
|
||||||
$response = wp_remote_get( $url );
|
|
||||||
|
|
||||||
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Response should be an array with:
|
|
||||||
* 'recommended_version' - string - The PHP version recommended by WordPress.
|
|
||||||
* 'is_supported' - boolean - Whether the PHP version is actively supported.
|
|
||||||
* 'is_secure' - boolean - Whether the PHP version receives security updates.
|
|
||||||
* 'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress.
|
|
||||||
*/
|
|
||||||
$response = json_decode( wp_remote_retrieve_body( $response ), true );
|
|
||||||
|
|
||||||
if ( ! is_array( $response ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
|
* Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2011,3 +2011,48 @@ final class WP_Privacy_Policy_Content {
|
||||||
wp_add_privacy_policy_content( __( 'WordPress' ), $content );
|
wp_add_privacy_policy_content( __( 'WordPress' ), $content );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user needs to update PHP.
|
||||||
|
*
|
||||||
|
* @since 5.1.0
|
||||||
|
*
|
||||||
|
* @return array|false $response Array of PHP version data. False on failure.
|
||||||
|
*/
|
||||||
|
function wp_check_php_version() {
|
||||||
|
$version = phpversion();
|
||||||
|
$key = md5( $version );
|
||||||
|
|
||||||
|
$response = get_site_transient( 'php_check_' . $key );
|
||||||
|
if ( false === $response ) {
|
||||||
|
$url = 'http://api.wordpress.org/core/serve-happy/1.0/';
|
||||||
|
if ( wp_http_supports( array( 'ssl' ) ) ) {
|
||||||
|
$url = set_url_scheme( $url, 'https' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = add_query_arg( 'php_version', $version, $url );
|
||||||
|
|
||||||
|
$response = wp_remote_get( $url );
|
||||||
|
|
||||||
|
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response should be an array with:
|
||||||
|
* 'recommended_version' - string - The PHP version recommended by WordPress.
|
||||||
|
* 'is_supported' - boolean - Whether the PHP version is actively supported.
|
||||||
|
* 'is_secure' - boolean - Whether the PHP version receives security updates.
|
||||||
|
* 'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress.
|
||||||
|
*/
|
||||||
|
$response = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||||
|
|
||||||
|
if ( ! is_array( $response ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.1-beta3-44734';
|
$wp_version = '5.1-beta3-44735';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue