On this page
wp_check_browser_version(): array|false
Checks if the user needs a browser update.
Return
array|false Array of browser data on success, false on failure.
Source
File: wp-admin/includes/dashboard.php. View all references
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 ) {
// Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php';
$url = 'http://api.wordpress.org/core/browse-happy/1.1/';
$options = array(
'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
'user-agent' => 'WordPress/' . $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;
}
Related
Uses
| Uses | Description |
|---|---|
| set_url_scheme() wp-includes/link-template.php | Sets the scheme for a URL. |
| wp_http_supports() wp-includes/http.php | Determines if there is an HTTP Transport that can process this request. |
| wp_remote_post() wp-includes/http.php | Performs an HTTP request using the POST method and returns its response. |
| wp_remote_retrieve_response_code() wp-includes/http.php | Retrieve only the response code from the raw response. |
| wp_remote_retrieve_body() wp-includes/http.php | Retrieve only the body from the raw response. |
| set_site_transient() wp-includes/option.php | Sets/updates the value of a site transient. |
| get_site_transient() wp-includes/option.php | Retrieves the value of a site transient. |
| home_url() wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| dashboard_browser_nag_class() wp-admin/includes/dashboard.php | Adds an additional class to the browser nag if the current version is insecure. |
| wp_dashboard_browser_nag() wp-admin/includes/dashboard.php | Displays the browser update nag. |
| wp_dashboard_setup() wp-admin/includes/dashboard.php | Registers dashboard widgets. |
Changelog
| Version | Description |
|---|---|
| 3.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_check_browser_version