author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Creates common globals for the rest of WordPress |
|
4 |
* |
|
5 |
* Sets $pagenow global which is the current page. Checks |
|
6 |
* for the browser to set which one is currently being used. |
|
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 |
|
13 |
* generate rewrite rules for it. See https://codex.wordpress.org/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 |
|
22 |
// On which page are we ? |
|
23 |
if ( is_admin() ) { |
|
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 |
} |
|
0 | 32 |
$pagenow = $self_matches[1]; |
9 | 33 |
$pagenow = trim( $pagenow, '/' ); |
34 |
$pagenow = preg_replace( '#\?.*?$#', '', $pagenow ); |
|
0 | 35 |
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) { |
36 |
$pagenow = 'index.php'; |
|
37 |
} else { |
|
9 | 38 |
preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches ); |
39 |
$pagenow = strtolower( $self_matches[1] ); |
|
40 |
if ( '.php' !== substr( $pagenow, -4, 4 ) ) { |
|
0 | 41 |
$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried) |
9 | 42 |
} |
0 | 43 |
} |
44 |
} else { |
|
9 | 45 |
if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) { |
46 |
$pagenow = strtolower( $self_matches[1] ); |
|
47 |
} else { |
|
0 | 48 |
$pagenow = 'index.php'; |
9 | 49 |
} |
0 | 50 |
} |
9 | 51 |
unset( $self_matches ); |
0 | 52 |
|
53 |
// Simple browser detection |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
$is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false; |
0 | 55 |
|
9 | 56 |
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { |
57 |
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) { |
|
0 | 58 |
$is_lynx = true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
$is_edge = true; |
9 | 61 |
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) { |
0 | 62 |
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) { |
63 |
$is_admin = is_admin(); |
|
64 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* Filters whether Google Chrome Frame should be used, if available. |
0 | 66 |
* |
67 |
* @since 3.2.0 |
|
68 |
* |
|
69 |
* @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin(). |
|
70 |
*/ |
|
9 | 71 |
if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) ) { |
0 | 72 |
header( 'X-UA-Compatible: chrome=1' ); |
9 | 73 |
} |
0 | 74 |
$is_winIE = ! $is_chrome; |
75 |
} else { |
|
76 |
$is_chrome = true; |
|
77 |
} |
|
9 | 78 |
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) { |
0 | 79 |
$is_safari = true; |
9 | 80 |
} elseif ( ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) !== false ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Win' ) !== false ) { |
0 | 81 |
$is_winIE = true; |
9 | 82 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) !== false ) { |
0 | 83 |
$is_macIE = true; |
9 | 84 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) !== false ) { |
0 | 85 |
$is_gecko = true; |
9 | 86 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) !== false ) { |
0 | 87 |
$is_opera = true; |
9 | 88 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) !== false ) { |
0 | 89 |
$is_NS4 = true; |
90 |
} |
|
91 |
} |
|
92 |
||
9 | 93 |
if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) { |
0 | 94 |
$is_iphone = true; |
9 | 95 |
} |
0 | 96 |
|
97 |
$is_IE = ( $is_macIE || $is_winIE ); |
|
98 |
||
99 |
// Server detection |
|
100 |
||
101 |
/** |
|
102 |
* Whether the server software is Apache or something else |
|
9 | 103 |
* |
0 | 104 |
* @global bool $is_apache |
105 |
*/ |
|
9 | 106 |
$is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false ); |
0 | 107 |
|
108 |
/** |
|
109 |
* Whether the server software is Nginx or something else |
|
9 | 110 |
* |
0 | 111 |
* @global bool $is_nginx |
112 |
*/ |
|
9 | 113 |
$is_nginx = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ); |
0 | 114 |
|
115 |
/** |
|
116 |
* Whether the server software is IIS or something else |
|
9 | 117 |
* |
0 | 118 |
* @global bool $is_IIS |
119 |
*/ |
|
9 | 120 |
$is_IIS = ! $is_apache && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false ); |
0 | 121 |
|
122 |
/** |
|
123 |
* Whether the server software is IIS 7.X or greater |
|
9 | 124 |
* |
0 | 125 |
* @global bool $is_iis7 |
126 |
*/ |
|
127 |
$is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7; |
|
128 |
||
129 |
/** |
|
130 |
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.) |
|
131 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* @since 3.4.0 |
9 | 133 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* @return bool |
0 | 135 |
*/ |
136 |
function wp_is_mobile() { |
|
9 | 137 |
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
0 | 138 |
$is_mobile = false; |
9 | 139 |
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.) |
140 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false |
|
141 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false |
|
142 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false |
|
143 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false |
|
144 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false |
|
145 |
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) { |
|
0 | 146 |
$is_mobile = true; |
147 |
} else { |
|
148 |
$is_mobile = false; |
|
149 |
} |
|
150 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
* 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
|
153 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
* @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
|
157 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
return apply_filters( 'wp_is_mobile', $is_mobile ); |
0 | 159 |
} |