wp_check_browser_version

Check if the user needs a browser update.

Description

(array|bool) wp_check_browser_version(); 

Returns (array|bool)

False on failure, array of browser data on success.


Usage

  1. if ( !function_exists( 'wp_check_browser_version' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_check_browser_version(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/dashboard.php  
  1. function wp_check_browser_version() { 
  2. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  3. return false; 
  4.  
  5. $key = md5( $_SERVER['HTTP_USER_AGENT'] ); 
  6.  
  7. if ( false === ($response = get_site_transient('browser_' . $key) ) ) { 
  8. $options = array( 
  9. 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),  
  10. 'user-agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . home_url() 
  11. ); 
  12.  
  13. $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options ); 
  14.  
  15. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) 
  16. return false; 
  17.  
  18. /** 
  19. * Response should be an array with: 
  20. * 'name' - string - A user friendly browser name 
  21. * 'version' - string - The version of the browser the user is using 
  22. * 'current_version' - string - The most recent version of the browser 
  23. * 'upgrade' - boolean - Whether the browser needs an upgrade 
  24. * 'insecure' - boolean - Whether the browser is deemed insecure 
  25. * 'upgrade_url' - string - The url to visit to upgrade 
  26. * 'img_src' - string - An image representing the browser 
  27. * 'img_src_ssl' - string - An image (over SSL) representing the browser 
  28. */ 
  29. $response = json_decode( wp_remote_retrieve_body( $response ), true ); 
  30.  
  31. if ( ! is_array( $response ) ) 
  32. return false; 
  33.  
  34. set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS ); 
  35.  
  36. return $response;