author | ymh <ymh.work@gmail.com> |
Thu, 29 Sep 2022 08:06:27 +0200 | |
changeset 20 | 7b1b88e27a20 |
parent 19 | 3d72ae0968f4 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Creates common globals for the rest of WordPress |
|
4 |
* |
|
19 | 5 |
* Sets $pagenow global which is the filename of the current screen. |
6 |
* Checks for the browser to set which one is currently being used. |
|
0 | 7 |
* |
8 |
* Detects which user environment WordPress is being used on. |
|
5 | 9 |
* Only attempts to check for Apache, Nginx and IIS -- three web |
10 |
* servers with known pretty permalink capability. |
|
11 |
* |
|
12 |
* Note: Though Nginx is detected, WordPress does not currently |
|
16 | 13 |
* generate rewrite rules for it. See https://wordpress.org/support/article/nginx/ |
0 | 14 |
* |
15 |
* @package WordPress |
|
16 |
*/ |
|
17 |
||
18 |
global $pagenow, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge, |
5 | 20 |
$is_apache, $is_IIS, $is_iis7, $is_nginx; |
0 | 21 |
|
16 | 22 |
// On which page are we? |
0 | 23 |
if ( is_admin() ) { |
16 | 24 |
// wp-admin pages are checked more carefully. |
9 | 25 |
if ( is_network_admin() ) { |
26 |
preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
|
27 |
} elseif ( is_user_admin() ) { |
|
28 |
preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
|
29 |
} else { |
|
30 |
preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
|
31 |
} |
|
19 | 32 |
|
33 |
$pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : ''; |
|
9 | 34 |
$pagenow = trim( $pagenow, '/' ); |
35 |
$pagenow = preg_replace( '#\?.*?$#', '', $pagenow ); |
|
19 | 36 |
|
0 | 37 |
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) { |
38 |
$pagenow = 'index.php'; |
|
39 |
} else { |
|
9 | 40 |
preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches ); |
41 |
$pagenow = strtolower( $self_matches[1] ); |
|
42 |
if ( '.php' !== substr( $pagenow, -4, 4 ) ) { |
|
16 | 43 |
$pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried). |
9 | 44 |
} |
0 | 45 |
} |
46 |
} else { |
|
9 | 47 |
if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) { |
48 |
$pagenow = strtolower( $self_matches[1] ); |
|
49 |
} else { |
|
0 | 50 |
$pagenow = 'index.php'; |
9 | 51 |
} |
0 | 52 |
} |
9 | 53 |
unset( $self_matches ); |
0 | 54 |
|
16 | 55 |
// Simple browser detection. |
56 |
$is_lynx = false; |
|
57 |
$is_gecko = false; |
|
58 |
$is_winIE = false; |
|
59 |
$is_macIE = false; |
|
60 |
$is_opera = false; |
|
61 |
$is_NS4 = false; |
|
62 |
$is_safari = false; |
|
63 |
$is_chrome = false; |
|
64 |
$is_iphone = false; |
|
65 |
$is_edge = false; |
|
0 | 66 |
|
9 | 67 |
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { |
68 |
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) { |
|
0 | 69 |
$is_lynx = true; |
19 | 70 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) !== false ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
$is_edge = true; |
9 | 72 |
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) { |
0 | 73 |
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) { |
74 |
$is_admin = is_admin(); |
|
75 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
* Filters whether Google Chrome Frame should be used, if available. |
0 | 77 |
* |
78 |
* @since 3.2.0 |
|
79 |
* |
|
80 |
* @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin(). |
|
81 |
*/ |
|
16 | 82 |
$is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ); |
83 |
if ( $is_chrome ) { |
|
0 | 84 |
header( 'X-UA-Compatible: chrome=1' ); |
9 | 85 |
} |
0 | 86 |
$is_winIE = ! $is_chrome; |
87 |
} else { |
|
88 |
$is_chrome = true; |
|
89 |
} |
|
9 | 90 |
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) { |
0 | 91 |
$is_safari = true; |
9 | 92 |
} elseif ( ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) !== false ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Win' ) !== false ) { |
0 | 93 |
$is_winIE = true; |
9 | 94 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) !== false ) { |
0 | 95 |
$is_macIE = true; |
9 | 96 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) !== false ) { |
0 | 97 |
$is_gecko = true; |
9 | 98 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) !== false ) { |
0 | 99 |
$is_opera = true; |
9 | 100 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) !== false ) { |
0 | 101 |
$is_NS4 = true; |
102 |
} |
|
103 |
} |
|
104 |
||
9 | 105 |
if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) { |
0 | 106 |
$is_iphone = true; |
9 | 107 |
} |
0 | 108 |
|
109 |
$is_IE = ( $is_macIE || $is_winIE ); |
|
110 |
||
16 | 111 |
// Server detection. |
0 | 112 |
|
113 |
/** |
|
114 |
* Whether the server software is Apache or something else |
|
9 | 115 |
* |
0 | 116 |
* @global bool $is_apache |
117 |
*/ |
|
9 | 118 |
$is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false ); |
0 | 119 |
|
120 |
/** |
|
121 |
* Whether the server software is Nginx or something else |
|
9 | 122 |
* |
0 | 123 |
* @global bool $is_nginx |
124 |
*/ |
|
9 | 125 |
$is_nginx = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ); |
0 | 126 |
|
127 |
/** |
|
128 |
* Whether the server software is IIS or something else |
|
9 | 129 |
* |
0 | 130 |
* @global bool $is_IIS |
131 |
*/ |
|
9 | 132 |
$is_IIS = ! $is_apache && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false ); |
0 | 133 |
|
134 |
/** |
|
135 |
* Whether the server software is IIS 7.X or greater |
|
9 | 136 |
* |
0 | 137 |
* @global bool $is_iis7 |
138 |
*/ |
|
18 | 139 |
$is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) >= 7; |
0 | 140 |
|
141 |
/** |
|
142 |
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.) |
|
143 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* @since 3.4.0 |
9 | 145 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @return bool |
0 | 147 |
*/ |
148 |
function wp_is_mobile() { |
|
9 | 149 |
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
0 | 150 |
$is_mobile = false; |
16 | 151 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // Many mobile devices (all iPhone, iPad, etc.) |
9 | 152 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false |
153 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false |
|
154 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false |
|
155 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false |
|
156 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false |
|
157 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) { |
|
0 | 158 |
$is_mobile = true; |
159 |
} else { |
|
160 |
$is_mobile = false; |
|
161 |
} |
|
162 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* Filters whether the request should be treated as coming from a mobile device or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* @param bool $is_mobile Whether the request is from a mobile device or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
return apply_filters( 'wp_is_mobile', $is_mobile ); |
0 | 171 |
} |