wp/wp-includes/vars.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    14  *
    14  *
    15  * @package WordPress
    15  * @package WordPress
    16  */
    16  */
    17 
    17 
    18 global $pagenow,
    18 global $pagenow,
    19 	$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE,
    19 	$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge,
    20 	$is_apache, $is_IIS, $is_iis7, $is_nginx;
    20 	$is_apache, $is_IIS, $is_iis7, $is_nginx;
    21 
    21 
    22 // On which page are we ?
    22 // On which page are we ?
    23 if ( is_admin() ) {
    23 if ( is_admin() ) {
    24 	// wp-admin pages are checked more carefully
    24 	// wp-admin pages are checked more carefully
    46 		$pagenow = 'index.php';
    46 		$pagenow = 'index.php';
    47 }
    47 }
    48 unset($self_matches);
    48 unset($self_matches);
    49 
    49 
    50 // Simple browser detection
    50 // Simple browser detection
    51 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = false;
    51 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false;
    52 
    52 
    53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
    53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
    54 	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
    54 	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
    55 		$is_lynx = true;
    55 		$is_lynx = true;
       
    56 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
       
    57 		$is_edge = true;
    56 	} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
    58 	} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
    57 		if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
    59 		if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
    58 			$is_admin = is_admin();
    60 			$is_admin = is_admin();
    59 			/**
    61 			/**
    60 			 * Filter whether Google Chrome Frame should be used, if available.
    62 			 * Filters whether Google Chrome Frame should be used, if available.
    61 			 *
    63 			 *
    62 			 * @since 3.2.0
    64 			 * @since 3.2.0
    63 			 *
    65 			 *
    64 			 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
    66 			 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
    65 			 */
    67 			 */
   116 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
   118 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
   117 
   119 
   118 /**
   120 /**
   119  * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
   121  * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
   120  *
   122  *
   121  * @return bool true|false
   123  * @since 3.4.0
       
   124  * 
       
   125  * @return bool
   122  */
   126  */
   123 function wp_is_mobile() {
   127 function wp_is_mobile() {
   124 	static $is_mobile;
       
   125 
       
   126 	if ( isset($is_mobile) )
       
   127 		return $is_mobile;
       
   128 
       
   129 	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
   128 	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
   130 		$is_mobile = false;
   129 		$is_mobile = false;
   131 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
   130 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
   132 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
   131 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
   133 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
   132 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
   138 			$is_mobile = true;
   137 			$is_mobile = true;
   139 	} else {
   138 	} else {
   140 		$is_mobile = false;
   139 		$is_mobile = false;
   141 	}
   140 	}
   142 
   141 
   143 	return $is_mobile;
   142 	/**
       
   143 	 * Filters whether the request should be treated as coming from a mobile device or not.
       
   144 	 *
       
   145 	 * @since 4.9.0
       
   146 	 *
       
   147 	 * @param bool $is_mobile Whether the request is from a mobile device or not.
       
   148 	 */
       
   149 	return apply_filters( 'wp_is_mobile', $is_mobile );
   144 }
   150 }