返回介绍

wp_check_browser_version()

发布于 2017-09-11 11:40:33 字数 3032 浏览 955 评论 0 收藏 0

wp_check_browser_version()

Check if the user needs a browser update


description


返回值

(array|bool) False on failure, array of browser data on success.


源代码

File: wp-admin/includes/dashboard.php

function wp_check_browser_version() {
	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
		return false;

	$key = md5( $_SERVER['HTTP_USER_AGENT'] );

	if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
		$options = array(
			'body'			=> array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
			'user-agent'	=> 'WordPress/' . get_bloginfo( 'version' ) . '; ' . home_url()
		);

		$response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $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;
}

更新日志

Versiondescription
3.2.0Introduced.

相关函数

Uses

  • wp-includes/compat.php: json_decode()
  • wp-includes/general-template.php: get_bloginfo()
  • wp-includes/link-template.php: home_url()
  • wp-includes/http.php: wp_remote_post()
  • wp-includes/http.php: wp_remote_retrieve_response_code()
  • wp-includes/http.php: wp_remote_retrieve_body()
  • wp-includes/option.php: set_site_transient()
  • wp-includes/option.php: get_site_transient()
  • wp-includes/load.php: is_wp_error()
  • Show 4 more uses Hide more uses

Used By

  • wp-admin/includes/dashboard.php: dashboard_browser_nag_class()
  • wp-admin/includes/dashboard.php: wp_dashboard_browser_nag()
  • wp-admin/includes/dashboard.php: wp_dashboard_setup()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文