8 * Detects which user environment WordPress is being used on. |
8 * Detects which user environment WordPress is being used on. |
9 * Only attempts to check for Apache, Nginx and IIS -- three web |
9 * Only attempts to check for Apache, Nginx and IIS -- three web |
10 * servers with known pretty permalink capability. |
10 * servers with known pretty permalink capability. |
11 * |
11 * |
12 * Note: Though Nginx is detected, WordPress does not currently |
12 * Note: Though Nginx is detected, WordPress does not currently |
13 * generate rewrite rules for it. See https://codex.wordpress.org/Nginx |
13 * generate rewrite rules for it. See https://wordpress.org/support/article/nginx/ |
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, $is_edge, |
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. |
25 if ( is_network_admin() ) { |
25 if ( is_network_admin() ) { |
26 preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
26 preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
27 } elseif ( is_user_admin() ) { |
27 } elseif ( is_user_admin() ) { |
28 preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
28 preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
29 } else { |
29 } else { |
36 $pagenow = 'index.php'; |
36 $pagenow = 'index.php'; |
37 } else { |
37 } else { |
38 preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches ); |
38 preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches ); |
39 $pagenow = strtolower( $self_matches[1] ); |
39 $pagenow = strtolower( $self_matches[1] ); |
40 if ( '.php' !== substr( $pagenow, -4, 4 ) ) { |
40 if ( '.php' !== substr( $pagenow, -4, 4 ) ) { |
41 $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried) |
41 $pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried). |
42 } |
42 } |
43 } |
43 } |
44 } else { |
44 } else { |
45 if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) { |
45 if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) { |
46 $pagenow = strtolower( $self_matches[1] ); |
46 $pagenow = strtolower( $self_matches[1] ); |
48 $pagenow = 'index.php'; |
48 $pagenow = 'index.php'; |
49 } |
49 } |
50 } |
50 } |
51 unset( $self_matches ); |
51 unset( $self_matches ); |
52 |
52 |
53 // Simple browser detection |
53 // Simple browser detection. |
54 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false; |
54 $is_lynx = false; |
|
55 $is_gecko = false; |
|
56 $is_winIE = false; |
|
57 $is_macIE = false; |
|
58 $is_opera = false; |
|
59 $is_NS4 = false; |
|
60 $is_safari = false; |
|
61 $is_chrome = false; |
|
62 $is_iphone = false; |
|
63 $is_edge = false; |
55 |
64 |
56 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { |
65 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { |
57 if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) { |
66 if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) { |
58 $is_lynx = true; |
67 $is_lynx = true; |
59 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) { |
68 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) { |
66 * |
75 * |
67 * @since 3.2.0 |
76 * @since 3.2.0 |
68 * |
77 * |
69 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin(). |
78 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin(). |
70 */ |
79 */ |
71 if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) ) { |
80 $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ); |
|
81 if ( $is_chrome ) { |
72 header( 'X-UA-Compatible: chrome=1' ); |
82 header( 'X-UA-Compatible: chrome=1' ); |
73 } |
83 } |
74 $is_winIE = ! $is_chrome; |
84 $is_winIE = ! $is_chrome; |
75 } else { |
85 } else { |
76 $is_chrome = true; |
86 $is_chrome = true; |
134 * @return bool |
144 * @return bool |
135 */ |
145 */ |
136 function wp_is_mobile() { |
146 function wp_is_mobile() { |
137 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
147 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
138 $is_mobile = false; |
148 $is_mobile = false; |
139 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.) |
149 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // Many mobile devices (all iPhone, iPad, etc.) |
140 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false |
150 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false |
141 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false |
151 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false |
142 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false |
152 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false |
143 || strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false |
153 || strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false |
144 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false |
154 || strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false |