[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Creates common globals for the rest of WordPress 4 * 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. 7 * 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. 11 * 12 * Note: Though Nginx is detected, WordPress does not currently 13 * generate rewrite rules for it. See https://developer.wordpress.org/advanced-administration/server/web-server/nginx/ 14 * 15 * @package WordPress 16 */ 17 18 // Don't load directly. 19 if ( ! defined( 'ABSPATH' ) ) { 20 die( '-1' ); 21 } 22 23 global $pagenow, 24 $is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge, 25 $is_apache, $is_IIS, $is_iis7, $is_nginx, $is_caddy; 26 27 // On which page are we? 28 if ( is_admin() ) { 29 // wp-admin pages are checked more carefully. 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 } 37 38 $pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : ''; 39 $pagenow = trim( $pagenow, '/' ); 40 $pagenow = preg_replace( '#\?.*?$#', '', $pagenow ); 41 42 if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) { 43 $pagenow = 'index.php'; 44 } else { 45 preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches ); 46 $pagenow = strtolower( $self_matches[1] ); 47 if ( ! str_ends_with( $pagenow, '.php' ) ) { 48 $pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried). 49 } 50 } 51 } else { 52 if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) { 53 $pagenow = strtolower( $self_matches[1] ); 54 } else { 55 $pagenow = 'index.php'; 56 } 57 } 58 unset( $self_matches ); 59 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; 71 72 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { 73 if ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) ) { 74 $is_lynx = true; 75 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) ) { 76 $is_edge = true; 77 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'OPR/' ) ) { 78 $is_opera = true; 79 } elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) { 80 if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) { 81 $is_admin = is_admin(); 82 /** 83 * Filters whether Google Chrome Frame should be used, if available. 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 */ 89 $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ); 90 if ( $is_chrome ) { 91 header( 'X-UA-Compatible: chrome=1' ); 92 } 93 $is_winIE = ! $is_chrome; 94 } else { 95 $is_chrome = true; 96 } 97 } elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) { 98 $is_safari = true; 99 } elseif ( ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) ) 100 && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Win' ) 101 ) { 102 $is_winIE = true; 103 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) ) { 104 $is_macIE = true; 105 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) ) { 106 $is_gecko = true; 107 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) ) { 108 $is_NS4 = true; 109 } 110 } 111 112 if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) { 113 $is_iphone = true; 114 } 115 116 $is_IE = ( $is_macIE || $is_winIE ); 117 118 // Server detection. 119 120 /** 121 * Whether the server software is Apache or something else. 122 * 123 * @global bool $is_apache 124 */ 125 $is_apache = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) ); 126 127 /** 128 * Whether the server software is Nginx or something else. 129 * 130 * @global bool $is_nginx 131 */ 132 $is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) ); 133 134 /** 135 * Whether the server software is Caddy / FrankenPHP or something else. 136 * 137 * @global bool $is_caddy 138 */ 139 $is_caddy = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Caddy' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'FrankenPHP' ) ); 140 141 /** 142 * Whether the server software is IIS or something else. 143 * 144 * @global bool $is_IIS 145 */ 146 $is_IIS = ! $is_apache && ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) ); 147 148 /** 149 * Whether the server software is IIS 7.X or greater. 150 * 151 * @global bool $is_iis7 152 */ 153 $is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) >= 7; 154 155 /** 156 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.). 157 * 158 * @since 3.4.0 159 * @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header. 160 * 161 * @return bool 162 */ 163 function wp_is_mobile() { 164 if ( isset( $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ) ) { 165 // This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header. 166 // See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>. 167 $is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ); 168 } elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { 169 $is_mobile = false; 170 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.) 171 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Android' ) 172 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) 173 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) 174 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) 175 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) 176 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) ) { 177 $is_mobile = true; 178 } else { 179 $is_mobile = false; 180 } 181 182 /** 183 * Filters whether the request should be treated as coming from a mobile device or not. 184 * 185 * @since 4.9.0 186 * 187 * @param bool $is_mobile Whether the request is from a mobile device or not. 188 */ 189 return apply_filters( 'wp_is_mobile', $is_mobile ); 190 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Feb 21 08:20:01 2025 | Cross-referenced by PHPXref |