A WordPress-centric search engine for devs and theme authors



wp_check_php_version ›

Since5.0.0
Deprecatedn/a
wp_check_php_version ( No parameters )
Returns:
  • (array|false) $response Array of PHP version data. False on failure.
Defined at:
Codex:

Checks if the user needs to upgrade PHP.



Source

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;
}