3 * Creates common globals for the rest of WordPress
5 * Sets $pagenow global which is the current page. Checks
6 * for the browser to set which one is currently being used.
8 * Detects which user environment WordPress is being used on.
9 * Only attempts to check for Apache, Nginx and IIS -- three web
10 * servers with known pretty permalink capability.
12 * Note: Though Nginx is detected, WordPress does not currently
13 * generate rewrite rules for it. See https://codex.wordpress.org/Nginx
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;
22 // On which page are we ?
24 // wp-admin pages are checked more carefully
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);
30 preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
31 $pagenow = $self_matches[1];
32 $pagenow = trim($pagenow, '/');
33 $pagenow = preg_replace('#\?.*?$#', '', $pagenow);
34 if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
35 $pagenow = 'index.php';
37 preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
38 $pagenow = strtolower($self_matches[1]);
39 if ( '.php' !== substr($pagenow, -4, 4) )
40 $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
43 if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
44 $pagenow = strtolower($self_matches[1]);
46 $pagenow = 'index.php';
50 // Simple browser detection
51 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false;
53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
54 if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
56 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
58 } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
59 if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
60 $is_admin = is_admin();
62 * Filters whether Google Chrome Frame should be used, if available.
66 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
68 if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) )
69 header( 'X-UA-Compatible: chrome=1' );
70 $is_winIE = ! $is_chrome;
74 } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
76 } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
78 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
80 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
82 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
84 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
89 if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
92 $is_IE = ( $is_macIE || $is_winIE );
97 * Whether the server software is Apache or something else
98 * @global bool $is_apache
100 $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
103 * Whether the server software is Nginx or something else
104 * @global bool $is_nginx
106 $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
109 * Whether the server software is IIS or something else
110 * @global bool $is_IIS
112 $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
115 * Whether the server software is IIS 7.X or greater
116 * @global bool $is_iis7
118 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
121 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
125 function wp_is_mobile() {
126 if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
128 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
129 || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
130 || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
131 || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
132 || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
133 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
134 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {