wppaste
WordPress

wp_check_browser_version(): array|false

Since
3.2.0
Source
wp-admin/includes/dashboard.php:1804
Checks if the user needs a browser update.

Compatibility

WordPress
since 3.2.0
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 browser data on success, false on failure.

Performance profile

How much work a call to wp_check_browser_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_post().

Scaling
Constant

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

Instructions
4–72

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

3 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_post()called directly
  • serializeserialisationjson_decode()called directly
  • hookthird-party callbacksapply_filters()one call below wp_check_browser_version()
  • cacheobject cachewp_cache_get()one call below wp_check_browser_version()
  • optionnetwork optionget_site_option()one call below wp_check_browser_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 · 10 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_check_browser_version() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($value)4none
!empty($value) && $response !== false17md5(), get_site_transient()
!empty($value) && $response === false && !wp_http_supports() && is_wp_error()45md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), wp_remote_post(), is_wp_error()
!empty($value) && $response === false && !wp_http_supports() && !is_wp_error()50md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code()
!empty($value) && $response === false && wp_http_supports() && is_wp_error()50md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), set_url_scheme(), wp_remote_post(), is_wp_error()
!empty($value) && $response === false && wp_http_supports() && !is_wp_error()55md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), set_url_scheme(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code()
!empty($value) && $response === false && !wp_http_supports() && !is_wp_error() && !is_array($response)60md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode()
!empty($value) && $response === false && wp_http_supports() && !is_wp_error() && !is_array($response)65md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), set_url_scheme(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode()
!empty($value) && $response === false && !wp_http_supports() && !is_wp_error() && is_array($response)67md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode(), set_site_transient()
!empty($value) && $response === false && wp_http_supports() && !is_wp_error() && is_array($response)72md5(), get_site_transient(), wp_get_wp_version(), home_url(), wp_http_supports(), set_url_scheme(), wp_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), json_decode(), set_site_transient()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 75 instructions, 4–72 executed per call, 6 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.

Uses · 10

Used by · 3

Source code

function wp_check_browser_version() {	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {		return false;	} 	$key = md5( $_SERVER['HTTP_USER_AGENT'] ); 	$response = get_site_transient( 'browser_' . $key ); 	if ( false === $response ) {		$url     = 'http://api.wordpress.org/core/browse-happy/1.1/';		$options = array(			'body'       => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),			'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),		); 		if ( wp_http_supports( array( 'ssl' ) ) ) {			$url = set_url_scheme( $url, 'https' );		} 		$response = wp_remote_post( $url, $options ); 		if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {			return false;		} 		/**		 * Response should be an array with:		 *  'platform' - string - A user-friendly platform name, if it can be determined		 *  'name' - string - A user-friendly browser name		 *  'version' - string - The version of the browser the user is using		 *  'current_version' - string - The most recent version of the browser		 *  'upgrade' - boolean - Whether the browser needs an upgrade		 *  'insecure' - boolean - Whether the browser is deemed insecure		 *  'update_url' - string - The url to visit to upgrade		 *  'img_src' - string - An image representing the browser		 *  'img_src_ssl' - string - An image (over SSL) representing the browser		 */		$response = json_decode( wp_remote_retrieve_body( $response ), true ); 		if ( ! is_array( $response ) ) {			return false;		} 		set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );	} 	return $response;}

Changelog

Introduced in 3.2.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.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-admin/includes/dashboard.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.