author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
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 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
13 |
* generate rewrite rules for it. See https://developer.wordpress.org/advanced-administration/server/web-server/nginx/ |
0 | 14 |
* |
15 |
* @package WordPress |
|
16 |
*/ |
|
17 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
18 |
// Don't load directly. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
19 |
if ( ! defined( 'ABSPATH' ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
20 |
die( '-1' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
21 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
22 |
|
0 | 23 |
global $pagenow, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
$is_apache, $is_IIS, $is_iis7, $is_nginx, $is_caddy; |
0 | 26 |
|
16 | 27 |
// On which page are we? |
0 | 28 |
if ( is_admin() ) { |
16 | 29 |
// wp-admin pages are checked more carefully. |
9 | 30 |
if ( is_network_admin() ) { |
31 |
preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
|
32 |
} elseif ( is_user_admin() ) { |
|
33 |
preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
|
34 |
} else { |
|
35 |
preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches ); |
|
36 |
} |
|
19 | 37 |
|
38 |
$pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : ''; |
|
9 | 39 |
$pagenow = trim( $pagenow, '/' ); |
40 |
$pagenow = preg_replace( '#\?.*?$#', '', $pagenow ); |
|
19 | 41 |
|
0 | 42 |
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) { |
43 |
$pagenow = 'index.php'; |
|
44 |
} else { |
|
9 | 45 |
preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches ); |
46 |
$pagenow = strtolower( $self_matches[1] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
if ( ! str_ends_with( $pagenow, '.php' ) ) { |
16 | 48 |
$pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried). |
9 | 49 |
} |
0 | 50 |
} |
51 |
} else { |
|
9 | 52 |
if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) { |
53 |
$pagenow = strtolower( $self_matches[1] ); |
|
54 |
} else { |
|
0 | 55 |
$pagenow = 'index.php'; |
9 | 56 |
} |
0 | 57 |
} |
9 | 58 |
unset( $self_matches ); |
0 | 59 |
|
16 | 60 |
// Simple browser detection. |
61 |
$is_lynx = false; |
|
62 |
$is_gecko = false; |
|
63 |
$is_winIE = false; |
|
64 |
$is_macIE = false; |
|
65 |
$is_opera = false; |
|
66 |
$is_NS4 = false; |
|
67 |
$is_safari = false; |
|
68 |
$is_chrome = false; |
|
69 |
$is_iphone = false; |
|
70 |
$is_edge = false; |
|
0 | 71 |
|
9 | 72 |
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
73 |
if ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) ) { |
0 | 74 |
$is_lynx = true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
$is_edge = true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
77 |
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'OPR/' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
$is_opera = true; |
9 | 79 |
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) { |
0 | 80 |
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) { |
81 |
$is_admin = is_admin(); |
|
82 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* Filters whether Google Chrome Frame should be used, if available. |
0 | 84 |
* |
85 |
* @since 3.2.0 |
|
86 |
* |
|
87 |
* @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin(). |
|
88 |
*/ |
|
16 | 89 |
$is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ); |
90 |
if ( $is_chrome ) { |
|
0 | 91 |
header( 'X-UA-Compatible: chrome=1' ); |
9 | 92 |
} |
0 | 93 |
$is_winIE = ! $is_chrome; |
94 |
} else { |
|
95 |
$is_chrome = true; |
|
96 |
} |
|
9 | 97 |
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) { |
0 | 98 |
$is_safari = true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
99 |
} elseif ( ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
100 |
&& str_contains( $_SERVER['HTTP_USER_AGENT'], 'Win' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
) { |
0 | 102 |
$is_winIE = true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
103 |
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) ) { |
0 | 104 |
$is_macIE = true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) ) { |
0 | 106 |
$is_gecko = true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
107 |
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) ) { |
0 | 108 |
$is_NS4 = true; |
109 |
} |
|
110 |
} |
|
111 |
||
9 | 112 |
if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) { |
0 | 113 |
$is_iphone = true; |
9 | 114 |
} |
0 | 115 |
|
116 |
$is_IE = ( $is_macIE || $is_winIE ); |
|
117 |
||
16 | 118 |
// Server detection. |
0 | 119 |
|
120 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
* Whether the server software is Apache or something else. |
9 | 122 |
* |
0 | 123 |
* @global bool $is_apache |
124 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
$is_apache = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) ); |
0 | 126 |
|
127 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
* Whether the server software is Nginx or something else. |
9 | 129 |
* |
0 | 130 |
* @global bool $is_nginx |
131 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
132 |
$is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) ); |
0 | 133 |
|
134 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
* Whether the server software is Caddy / FrankenPHP or something else. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
136 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
* @global bool $is_caddy |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
138 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
$is_caddy = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Caddy' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'FrankenPHP' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
* Whether the server software is IIS or something else. |
9 | 143 |
* |
0 | 144 |
* @global bool $is_IIS |
145 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
$is_IIS = ! $is_apache && ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) ); |
0 | 147 |
|
148 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
149 |
* Whether the server software is IIS 7.X or greater. |
9 | 150 |
* |
0 | 151 |
* @global bool $is_iis7 |
152 |
*/ |
|
18 | 153 |
$is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) >= 7; |
0 | 154 |
|
155 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
156 |
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.). |
0 | 157 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* @since 3.4.0 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
* @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header. |
9 | 160 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @return bool |
0 | 162 |
*/ |
163 |
function wp_is_mobile() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
if ( isset( $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
// This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
166 |
// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
167 |
$is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
168 |
} elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
0 | 169 |
$is_mobile = false; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
170 |
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Android' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) ) { |
0 | 177 |
$is_mobile = true; |
178 |
} else { |
|
179 |
$is_mobile = false; |
|
180 |
} |
|
181 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* 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
|
184 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
* @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
|
188 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
return apply_filters( 'wp_is_mobile', $is_mobile ); |
0 | 190 |
} |