wp_check_browser_version(): array|false
- Since
- 3.2.0
- Source
wp-admin/includes/dashboard.php:1808
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
- Scaling
- Constant
- Instructions
- 4–72
- Plugin surface
- None
- Called by
- 3
Reaches an outbound HTTP request via wp_remote_post().
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 75.
Nothing here hands control to plugin code.
3 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_post()called directly - serializeserialisation
json_decode()called directly - hookthird-party callbacks
apply_filters()one call below wp_check_browser_version() - cacheobject cache
wp_cache_get()one call below wp_check_browser_version() - optionnetwork option
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) | 4 | none |
!empty($value) && $response !== false | 17 | md5(), get_site_transient() |
!empty($value) && $response === false && !wp_http_supports() && is_wp_error() | 45 | md5(), 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() | 50 | md5(), 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() | 50 | md5(), 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() | 55 | md5(), 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) | 60 | md5(), 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) | 65 | md5(), 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) | 67 | md5(), 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) | 72 | md5(), 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
- get_site_transient()Retrieves the value of a site transient.
- wp_get_wp_version()Returns the current WordPress version.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- wp_http_supports()Determines if there is an HTTP Transport that can process this request.
- set_url_scheme()Sets the scheme for a URL.
- wp_remote_post()Performs an HTTP request using the POST 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.
Used by · 3
- dashboard_browser_nag_class()Adds an additional class to the browser nag if the current version is insecure.
- wp_dashboard_browser_nag()Displays the browser update nag.
- wp_dashboard_setup()Registers dashboard widgets.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.