wp_check_php_version

The timeline below displays how wordpress function wp_check_php_version has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Checks if the user needs to update PHP.
 *
 * @since 5.1.0
 * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter.
 *
 * @return array|false {
 *     Array of PHP version data. False on failure.
 *
 *     @type string $recommended_version The PHP version recommended by WordPress.
 *     @type string $minimum_version     The minimum required PHP version.
 *     @type bool   $is_supported        Whether the PHP version is actively supported.
 *     @type bool   $is_secure           Whether the PHP version receives security updates.
 *     @type bool   $is_acceptable       Whether the PHP version is still acceptable or warnings
 *                                       should be shown and an update recommended.
 * }
 */
function wp_check_php_version()
{
    $version = PHP_VERSION;
    $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 = json_decode(wp_remote_retrieve_body($response), true);
        if (!is_array($response)) {
            return false;
        }
        set_site_transient('php_check_' . $key, $response, WEEK_IN_SECONDS);
    }
    if (isset($response['is_acceptable']) && $response['is_acceptable']) {
        /**
         * Filters whether the active PHP version is considered acceptable by WordPress.
         *
         * Returning false will trigger a PHP version warning to show up in the admin dashboard to administrators.
         *
         * This filter is only run if the wordpress.org Serve Happy API considers the PHP version acceptable, ensuring
         * that this filter can only make this check stricter, but not loosen it.
         *
         * @since 5.1.1
         *
         * @param bool   $is_acceptable Whether the PHP version is considered acceptable. Default true.
         * @param string $version       PHP version checked.
         */
        $response['is_acceptable'] = (bool) apply_filters('wp_is_php_version_acceptable', true, $version);
    }
    $response['is_lower_than_future_minimum'] = false;
    // The minimum supported PHP version will be updated to 7.2. Check if the current version is lower.
    if (version_compare($version, '7.2', '<')) {
        $response['is_lower_than_future_minimum'] = true;
        // Force showing of warnings.
        $response['is_acceptable'] = false;
    }
    return $response;
}

WordPress Version: 6.1

/**
 * Checks if the user needs to update PHP.
 *
 * @since 5.1.0
 * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter.
 *
 * @return array|false Array of PHP version data. False on failure.
 */
function wp_check_php_version()
{
    $version = PHP_VERSION;
    $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 or warnings
         *                              should be shown and an update recommended.
         */
        $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);
    }
    if (isset($response['is_acceptable']) && $response['is_acceptable']) {
        /**
         * Filters whether the active PHP version is considered acceptable by WordPress.
         *
         * Returning false will trigger a PHP version warning to show up in the admin dashboard to administrators.
         *
         * This filter is only run if the wordpress.org Serve Happy API considers the PHP version acceptable, ensuring
         * that this filter can only make this check stricter, but not loosen it.
         *
         * @since 5.1.1
         *
         * @param bool   $is_acceptable Whether the PHP version is considered acceptable. Default true.
         * @param string $version       PHP version checked.
         */
        $response['is_acceptable'] = (bool) apply_filters('wp_is_php_version_acceptable', true, $version);
    }
    $response['is_lower_than_future_minimum'] = false;
    // The minimum supported PHP version will be updated to 7.2. Check if the current version is lower.
    if (version_compare($version, '7.2', '<')) {
        $response['is_lower_than_future_minimum'] = true;
        // Force showing of warnings.
        $response['is_acceptable'] = false;
    }
    return $response;
}

WordPress Version: 5.5

/**
 * Checks if the user needs to update PHP.
 *
 * @since 5.1.0
 * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter.
 *
 * @return array|false 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);
    }
    if (isset($response['is_acceptable']) && $response['is_acceptable']) {
        /**
         * Filters whether the active PHP version is considered acceptable by WordPress.
         *
         * Returning false will trigger a PHP version warning to show up in the admin dashboard to administrators.
         *
         * This filter is only run if the wordpress.org Serve Happy API considers the PHP version acceptable, ensuring
         * that this filter can only make this check stricter, but not loosen it.
         *
         * @since 5.1.1
         *
         * @param bool   $is_acceptable Whether the PHP version is considered acceptable. Default true.
         * @param string $version       PHP version checked.
         */
        $response['is_acceptable'] = (bool) apply_filters('wp_is_php_version_acceptable', true, $version);
    }
    return $response;
}

WordPress Version: 1.1

/**
 * Checks if the user needs to update PHP.
 *
 * @since 5.1.0
 * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter.
 *
 * @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);
    }
    if (isset($response['is_acceptable']) && $response['is_acceptable']) {
        /**
         * Filters whether the active PHP version is considered acceptable by WordPress.
         *
         * Returning false will trigger a PHP version warning to show up in the admin dashboard to administrators.
         *
         * This filter is only run if the wordpress.org Serve Happy API considers the PHP version acceptable, ensuring
         * that this filter can only make this check stricter, but not loosen it.
         *
         * @since 5.1.1
         *
         * @param bool   $is_acceptable Whether the PHP version is considered acceptable. Default true.
         * @param string $version       PHP version checked.
         */
        $response['is_acceptable'] = (bool) apply_filters('wp_is_php_version_acceptable', true, $version);
    }
    return $response;
}

WordPress Version: 5.1

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