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 http://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,
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 = false;
53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
54 if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
56 } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
57 if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
58 $is_admin = is_admin();
60 * Filter whether Google Chrome Frame should be used, if available.
64 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
66 if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) )
67 header( 'X-UA-Compatible: chrome=1' );
68 $is_winIE = ! $is_chrome;
72 } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
74 } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
76 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
78 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
80 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
82 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
87 if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
90 $is_IE = ( $is_macIE || $is_winIE );
95 * Whether the server software is Apache or something else
96 * @global bool $is_apache
98 $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
101 * Whether the server software is Nginx or something else
102 * @global bool $is_nginx
104 $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
107 * Whether the server software is IIS or something else
108 * @global bool $is_IIS
110 $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
113 * Whether the server software is IIS 7.X or greater
114 * @global bool $is_iis7
116 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
119 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
121 * @return bool true|false
123 function wp_is_mobile() {
126 if ( isset($is_mobile) )
129 if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
131 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
132 || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
133 || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
134 || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
135 || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
136 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
137 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {