2003-04-21 17:37:11 -04:00
|
|
|
<?php
|
2008-01-04 15:05:07 -05:00
|
|
|
/**
|
|
|
|
* Creates common globals for the rest of WordPress
|
|
|
|
*
|
|
|
|
* Sets $pagenow global which is the current page. Checks
|
|
|
|
* for the browser to set which one is currently being used.
|
|
|
|
*
|
|
|
|
* Detects which user environment WordPress is being used on.
|
2014-01-10 13:15:13 -05:00
|
|
|
* Only attempts to check for Apache, Nginx and IIS -- three web
|
|
|
|
* servers with known pretty permalink capability.
|
|
|
|
*
|
|
|
|
* Note: Though Nginx is detected, WordPress does not currently
|
2019-07-25 18:45:57 -04:00
|
|
|
* generate rewrite rules for it. See https://wordpress.org/support/article/nginx/
|
2008-01-04 15:05:07 -05:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2003-04-21 17:37:11 -04:00
|
|
|
|
2011-10-18 15:44:00 -04:00
|
|
|
global $pagenow,
|
2015-09-05 18:33:23 -04:00
|
|
|
$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge,
|
2013-10-30 15:37:09 -04:00
|
|
|
$is_apache, $is_IIS, $is_iis7, $is_nginx;
|
2011-10-18 15:44:00 -04:00
|
|
|
|
2004-04-15 15:08:51 -04:00
|
|
|
// On which page are we ?
|
2007-09-03 23:21:04 -04:00
|
|
|
if ( is_admin() ) {
|
|
|
|
// wp-admin pages are checked more carefully
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_network_admin() ) {
|
|
|
|
preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
|
|
|
|
} elseif ( is_user_admin() ) {
|
|
|
|
preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
|
|
|
|
} else {
|
|
|
|
preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
|
|
|
|
}
|
2004-09-15 04:16:58 -04:00
|
|
|
$pagenow = $self_matches[1];
|
2017-11-30 18:11:00 -05:00
|
|
|
$pagenow = trim( $pagenow, '/' );
|
|
|
|
$pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
|
2007-09-03 23:21:04 -04:00
|
|
|
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
|
|
|
|
$pagenow = 'index.php';
|
|
|
|
} else {
|
2017-11-30 18:11:00 -05:00
|
|
|
preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
|
|
|
|
$pagenow = strtolower( $self_matches[1] );
|
|
|
|
if ( '.php' !== substr( $pagenow, -4, 4 ) ) {
|
2007-09-03 23:21:04 -04:00
|
|
|
$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2007-09-03 23:21:04 -04:00
|
|
|
}
|
2004-10-08 22:00:34 -04:00
|
|
|
} else {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) {
|
|
|
|
$pagenow = strtolower( $self_matches[1] );
|
|
|
|
} else {
|
2007-09-03 23:21:04 -04:00
|
|
|
$pagenow = 'index.php';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2003-04-21 17:37:11 -04:00
|
|
|
}
|
2017-11-30 18:11:00 -05:00
|
|
|
unset( $self_matches );
|
2003-04-21 17:37:11 -04:00
|
|
|
|
2004-04-15 15:08:51 -04:00
|
|
|
// Simple browser detection
|
2019-07-02 19:42:58 -04:00
|
|
|
$is_lynx = false;
|
|
|
|
$is_gecko = false;
|
|
|
|
$is_winIE = false;
|
|
|
|
$is_macIE = false;
|
|
|
|
$is_opera = false;
|
|
|
|
$is_NS4 = false;
|
|
|
|
$is_safari = false;
|
|
|
|
$is_chrome = false;
|
|
|
|
$is_iphone = false;
|
|
|
|
$is_edge = false;
|
2006-04-03 20:25:04 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
|
|
|
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) {
|
2009-11-26 06:29:54 -05:00
|
|
|
$is_lynx = true;
|
2015-09-05 18:33:23 -04:00
|
|
|
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
|
|
|
|
$is_edge = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) {
|
2011-05-25 12:15:00 -04:00
|
|
|
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
|
2013-10-07 13:56:10 -04:00
|
|
|
$is_admin = is_admin();
|
2013-10-07 11:30:09 -04:00
|
|
|
/**
|
2016-05-22 14:50:28 -04:00
|
|
|
* Filters whether Google Chrome Frame should be used, if available.
|
2013-10-07 11:30:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
|
|
|
* @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
|
|
|
|
*/
|
2019-07-02 19:42:58 -04:00
|
|
|
$is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin );
|
|
|
|
if ( $is_chrome ) {
|
2011-05-25 12:15:00 -04:00
|
|
|
header( 'X-UA-Compatible: chrome=1' );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-05-25 12:15:00 -04:00
|
|
|
$is_winIE = ! $is_chrome;
|
|
|
|
} else {
|
|
|
|
$is_chrome = true;
|
|
|
|
}
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) {
|
2009-11-26 06:29:54 -05:00
|
|
|
$is_safari = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) !== false ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Win' ) !== false ) {
|
2009-11-26 06:29:54 -05:00
|
|
|
$is_winIE = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) !== false ) {
|
2009-11-26 06:29:54 -05:00
|
|
|
$is_macIE = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) !== false ) {
|
2013-10-11 13:26:09 -04:00
|
|
|
$is_gecko = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) !== false ) {
|
2009-11-26 06:29:54 -05:00
|
|
|
$is_opera = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) !== false ) {
|
2009-11-26 06:29:54 -05:00
|
|
|
$is_NS4 = true;
|
|
|
|
}
|
2007-03-10 20:19:16 -05:00
|
|
|
}
|
2006-12-06 22:57:23 -05:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) {
|
2008-12-02 07:32:54 -05:00
|
|
|
$is_iphone = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2008-12-02 07:32:54 -05:00
|
|
|
|
2006-12-06 22:57:23 -05:00
|
|
|
$is_IE = ( $is_macIE || $is_winIE );
|
2003-04-21 17:37:11 -04:00
|
|
|
|
2004-04-15 15:08:51 -04:00
|
|
|
// Server detection
|
2008-01-04 15:05:07 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the server software is Apache or something else
|
2017-11-30 18:11:00 -05:00
|
|
|
*
|
2008-01-04 15:05:07 -05:00
|
|
|
* @global bool $is_apache
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false );
|
2008-01-04 15:05:07 -05:00
|
|
|
|
2013-09-16 16:07:09 -04:00
|
|
|
/**
|
2013-10-24 22:29:52 -04:00
|
|
|
* Whether the server software is Nginx or something else
|
2017-11-30 18:11:00 -05:00
|
|
|
*
|
2013-10-24 22:29:52 -04:00
|
|
|
* @global bool $is_nginx
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$is_nginx = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false );
|
2013-10-24 22:29:52 -04:00
|
|
|
|
2008-01-04 15:05:07 -05:00
|
|
|
/**
|
|
|
|
* Whether the server software is IIS or something else
|
2017-11-30 18:11:00 -05:00
|
|
|
*
|
2008-01-04 15:05:07 -05:00
|
|
|
* @global bool $is_IIS
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$is_IIS = ! $is_apache && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false );
|
2003-04-21 17:37:11 -04:00
|
|
|
|
2009-05-15 22:04:36 -04:00
|
|
|
/**
|
2013-07-08 16:27:06 -04:00
|
|
|
* Whether the server software is IIS 7.X or greater
|
2017-11-30 18:11:00 -05:00
|
|
|
*
|
2009-05-18 10:54:16 -04:00
|
|
|
* @global bool $is_iis7
|
2009-05-15 22:04:36 -04:00
|
|
|
*/
|
2013-07-08 16:27:06 -04:00
|
|
|
$is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
|
2012-04-09 21:19:30 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
|
|
|
|
*
|
2016-12-27 04:21:44 -05:00
|
|
|
* @since 3.4.0
|
2017-11-30 18:11:00 -05:00
|
|
|
*
|
2015-06-26 20:45:24 -04:00
|
|
|
* @return bool
|
2012-04-09 21:19:30 -04:00
|
|
|
*/
|
|
|
|
function wp_is_mobile() {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
2012-04-09 21:19:30 -04:00
|
|
|
$is_mobile = false;
|
2017-11-30 18:11:00 -05:00
|
|
|
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.)
|
|
|
|
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
|
|
|
|
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
|
|
|
|
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
|
|
|
|
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
|
|
|
|
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
|
|
|
|
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
|
2012-04-09 21:19:30 -04:00
|
|
|
$is_mobile = true;
|
|
|
|
} else {
|
|
|
|
$is_mobile = false;
|
|
|
|
}
|
|
|
|
|
2017-06-15 08:05:42 -04:00
|
|
|
/**
|
|
|
|
* Filters whether the request should be treated as coming from a mobile device or not.
|
|
|
|
*
|
|
|
|
* @since 4.9.0
|
|
|
|
*
|
|
|
|
* @param bool $is_mobile Whether the request is from a mobile device or not.
|
|
|
|
*/
|
|
|
|
return apply_filters( 'wp_is_mobile', $is_mobile );
|
2012-04-09 21:19:30 -04:00
|
|
|
}
|