wp_check_php_version(): array|false
- Since
- 5.1.0, 5.1.1
- Source
wp-admin/includes/misc.php:1581
Compatibility
- WordPress
- since 5.1.1
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
array|false- Array of PHP version data. False on failure.
$recommended_versionstringThe PHP version recommended by WordPress.$minimum_versionstringThe minimum required PHP version.$is_supportedboolWhether the PHP version is actively supported.$is_secureboolWhether the PHP version receives security updates.$is_acceptableboolWhether the PHP version is still acceptable or warnings should be shown and an update recommended.
Performance profile
How much work a call to wp_check_php_version() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Expensive
- Scaling
- Constant
- Instructions
- 23–83
- Plugin surface
- 1 hook
- Called by
- 4
Reaches an outbound HTTP request via wp_remote_get().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 85.
Third-party callbacks on 'wp_is_php_version_acceptable' run inside this call, and their cost is not bounded by anything here.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- transienttransient
get_site_transient()called directly - httpoutbound HTTP request
wp_remote_get()called directly - hookthird-party callbacks
apply_filters()called directly - serializeserialisation
json_decode()called directly - cacheobject cache
wp_cache_get()one call below wp_check_php_version() - optionnetwork option
get_site_option()one call below wp_check_php_version()
Further down the call graph this can also reach query. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_check_php_version() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$response !== false | 23–29 | md5(), get_site_transient(), version_compare() |
$response === false && !wp_http_supports() && is_wp_error() | 32 | md5(), get_site_transient(), wp_http_supports(), add_query_arg(), wp_remote_get(), is_wp_error() |
$response !== false && isset($response) && $response | 33–37 | md5(), get_site_transient(), apply_filters(), version_compare() |
$response === false && !wp_http_supports() && !is_wp_error() | 37 | md5(), get_site_transient(), wp_http_supports(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code() |
$response === false && wp_http_supports() && is_wp_error() | 37 | md5(), get_site_transient(), wp_http_supports(), set_url_scheme(), add_query_arg(), wp_remote_get(), is_wp_error() |
$response === false && wp_http_supports() && !is_wp_error() | 42 | md5(), get_site_transient(), wp_http_supports(), set_url_scheme(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code() |
$response === false && !wp_http_supports() && !is_wp_error() && !is_array($response) | 47 | md5(), get_site_transient(), wp_http_supports(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode() |
$response === false && wp_http_supports() && !is_wp_error() && !is_array($response) | 52 | md5(), get_site_transient(), wp_http_supports(), set_url_scheme(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode() |
$response === false && !wp_http_supports() && !is_wp_error() && is_array($response) | 64–70 | md5(), get_site_transient(), wp_http_supports(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode(), set_site_transient(), version_compare() |
$response === false && wp_http_supports() && !is_wp_error() && is_array($response) | 69–75 | md5(), get_site_transient(), wp_http_supports(), set_url_scheme(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode(), set_site_transient(), version_compare() |
$response === false && !wp_http_supports() && !is_wp_error() && is_array($response) && isset($response) && $response | 74–78 | md5(), get_site_transient(), wp_http_supports(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode(), set_site_transient(), apply_filters(), version_compare() |
$response === false && wp_http_supports() && !is_wp_error() && is_array($response) && isset($response) && $response | 79–83 | md5(), get_site_transient(), wp_http_supports(), set_url_scheme(), add_query_arg(), wp_remote_get(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode(), set_site_transient(), apply_filters(), version_compare() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 85 instructions, 23–83 executed per call, 8 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_check_php_version() runs, in this order:
- apply_filters( wp_is_php_version_acceptable )filterline 1625 (+44 into the body)
Filters whether the active PHP version is considered acceptable by WordPress.
Uses · 10
- get_site_transient()Retrieves the value of a site transient.
- wp_http_supports()Determines if there is an HTTP Transport that can process this request.
- set_url_scheme()Sets the scheme for a URL.
- add_query_arg()Retrieves a modified URL query string.
- wp_remote_get()Performs an HTTP request using the GET method and returns its response.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_remote_retrieve_response_code()Retrieves only the response code from the raw response.
- wp_remote_retrieve_body()Retrieves only the body from the raw response.
- set_site_transient()Sets/updates the value of a site transient.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 4
- WP_Site_Health::get_test_php_version()Tests if the supplied PHP version is supported.
- dashboard_php_nag_class()Adds an additional class to the PHP nag if the current version is insecure.
- wp_dashboard_php_nag()Displays the PHP update nag.
- wp_dashboard_setup()Registers dashboard widgets.
Source code
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 at least 8.0 in the future. Check if the current version is lower. if ( version_compare( $version, '8.0', '<' ) ) { $response['is_lower_than_future_minimum'] = true; // Force showing of warnings. $response['is_acceptable'] = false; } return $response;}Changelog
Introduced in 5.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-admin/includes/misc.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.