wppaste
WordPress

wp_check_php_version(): array|false

Since
5.1.0, 5.1.1
Source
wp-admin/includes/misc.php:1581
Checks if the user needs to update PHP.

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_versionstring

    The PHP version recommended by WordPress.
  • $minimum_versionstring

    The minimum required PHP version.
  • $is_supportedbool

    Whether the PHP version is actively supported.
  • $is_securebool

    Whether the PHP version receives security updates.
  • $is_acceptablebool

    Whether 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

Reaches an outbound HTTP request via wp_remote_get().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
23–83

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 85.

Plugin surface
1 hook

Third-party callbacks on 'wp_is_php_version_acceptable' run inside this call, and their cost is not bounded by anything here.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • transienttransientget_site_transient()called directly
  • httpoutbound HTTP requestwp_remote_get()called directly
  • hookthird-party callbacksapply_filters()called directly
  • serializeserialisationjson_decode()called directly
  • cacheobject cachewp_cache_get()one call below wp_check_php_version()
  • optionnetwork optionget_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.

WhenInstructionsCalls it makes
$response !== false23–29md5(), get_site_transient(), version_compare()
$response === false && !wp_http_supports() && is_wp_error()32md5(), get_site_transient(), wp_http_supports(), add_query_arg(), wp_remote_get(), is_wp_error()
$response !== false && isset($response) && $response33–37md5(), get_site_transient(), apply_filters(), version_compare()
$response === false && !wp_http_supports() && !is_wp_error()37md5(), 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()37md5(), 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()42md5(), 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)47md5(), 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)52md5(), 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–70md5(), 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–75md5(), 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) && $response74–78md5(), 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) && $response79–83md5(), 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:

  1. 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

Used by · 4

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.1.1
Added the 'wp_is_php_version_acceptable' filter.from the docblock
5.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.