2003-04-21 23:37:11 +02:00
|
|
|
<?php
|
2008-01-04 21:05:07 +01:00
|
|
|
/**
|
|
|
|
* Creates common globals for the rest of WordPress
|
|
|
|
*
|
2022-04-04 20:26:06 +02:00
|
|
|
* Sets $pagenow global which is the filename of the current screen.
|
|
|
|
* Checks for the browser to set which one is currently being used.
|
2008-01-04 21:05:07 +01:00
|
|
|
*
|
|
|
|
* Detects which user environment WordPress is being used on.
|
2014-01-10 19:15:13 +01: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
|
2023-02-23 11:38:21 +01:00
|
|
|
* generate rewrite rules for it. See https://wordpress.org/documentation/article/nginx/
|
2008-01-04 21:05:07 +01:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2011-10-18 21:44:00 +02:00
|
|
|
global $pagenow,
|
2015-09-06 00:33:23 +02: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 20:37:09 +01:00
|
|
|
$is_apache, $is_IIS, $is_iis7, $is_nginx;
|
2011-10-18 21:44:00 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// On which page are we?
|
2007-09-04 05:21:04 +02:00
|
|
|
if ( is_admin() ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// wp-admin pages are checked more carefully.
|
2017-12-01 00:11:00 +01: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 );
|
|
|
|
}
|
2022-04-27 15:47:11 +02:00
|
|
|
|
|
|
|
$pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : '';
|
2017-12-01 00:11:00 +01:00
|
|
|
$pagenow = trim( $pagenow, '/' );
|
|
|
|
$pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
|
2022-04-27 15:47:11 +02:00
|
|
|
|
2007-09-04 05:21:04 +02:00
|
|
|
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
|
|
|
|
$pagenow = 'index.php';
|
|
|
|
} else {
|
2017-12-01 00:11:00 +01:00
|
|
|
preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
|
|
|
|
$pagenow = strtolower( $self_matches[1] );
|
Code Modernization: Replace usage of `substr()` with `str_starts_with()` and `str_ends_with()`.
`str_starts_with()` and `str_ends_with()` were introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins or ends with the given substring (needle).
WordPress core includes a polyfill for these functions on PHP < 8.0 as of WordPress 5.9.
This commit uses `str_starts_with()` and `str_ends_with()` in core files where appropriate:
* `$needle === substr( $string, 0, $length )`, where `$length` is the length of `$needle`, is replaced with `str_starts_with( $haystack, $needle )`.
* `$needle === substr( $string, $offset )`, where `$offset` is negative and the absolute value of `$offset` is the length of `$needle`, is replaced with `str_ends_with( $haystack, $needle )`.
This aims to make the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987], [55988].
Props Soean, spacedmonkey, Clorith, ocean90, azaozz, sabernhardt, SergeyBiryukov.
Fixes #58220.
Built from https://develop.svn.wordpress.org/trunk@55990
git-svn-id: http://core.svn.wordpress.org/trunk@55502 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:57:24 +02:00
|
|
|
if ( ! str_ends_with( $pagenow, '.php' ) ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
$pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried).
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-09-04 05:21:04 +02:00
|
|
|
}
|
2004-10-09 04:00:34 +02:00
|
|
|
} else {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) {
|
|
|
|
$pagenow = strtolower( $self_matches[1] );
|
|
|
|
} else {
|
2007-09-04 05:21:04 +02:00
|
|
|
$pagenow = 'index.php';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2003-04-21 23:37:11 +02:00
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
unset( $self_matches );
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Simple browser detection.
|
2019-07-03 01:42:58 +02: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-04 02:25:04 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
if ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) ) {
|
2009-11-26 12:29:54 +01:00
|
|
|
$is_lynx = true;
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) ) {
|
2015-09-06 00:33:23 +02:00
|
|
|
$is_edge = true;
|
2023-07-13 02:58:25 +02:00
|
|
|
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'OPR/' ) ) {
|
|
|
|
$is_opera = true;
|
2017-12-01 00:11:00 +01:00
|
|
|
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) {
|
2011-05-25 18:15:00 +02:00
|
|
|
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
|
2013-10-07 19:56:10 +02:00
|
|
|
$is_admin = is_admin();
|
2013-10-07 17:30:09 +02:00
|
|
|
/**
|
2016-05-22 20:50:28 +02:00
|
|
|
* Filters whether Google Chrome Frame should be used, if available.
|
2013-10-07 17:30:09 +02: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-03 01:42:58 +02:00
|
|
|
$is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin );
|
|
|
|
if ( $is_chrome ) {
|
2011-05-25 18:15:00 +02:00
|
|
|
header( 'X-UA-Compatible: chrome=1' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-05-25 18:15:00 +02:00
|
|
|
$is_winIE = ! $is_chrome;
|
|
|
|
} else {
|
|
|
|
$is_chrome = true;
|
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) {
|
2009-11-26 12:29:54 +01:00
|
|
|
$is_safari = true;
|
2023-09-16 08:50:23 +02:00
|
|
|
} elseif ( ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) )
|
|
|
|
&& str_contains( $_SERVER['HTTP_USER_AGENT'], 'Win' )
|
|
|
|
) {
|
2009-11-26 12:29:54 +01:00
|
|
|
$is_winIE = true;
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) ) {
|
2009-11-26 12:29:54 +01:00
|
|
|
$is_macIE = true;
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) ) {
|
2013-10-11 19:26:09 +02:00
|
|
|
$is_gecko = true;
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) ) {
|
2009-11-26 12:29:54 +01:00
|
|
|
$is_NS4 = true;
|
|
|
|
}
|
2007-03-11 02:19:16 +01:00
|
|
|
}
|
2006-12-07 04:57:23 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) {
|
2008-12-02 13:32:54 +01:00
|
|
|
$is_iphone = true;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2008-12-02 13:32:54 +01:00
|
|
|
|
2006-12-07 04:57:23 +01:00
|
|
|
$is_IE = ( $is_macIE || $is_winIE );
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Server detection.
|
2008-01-04 21:05:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the server software is Apache or something else
|
2017-12-01 00:11:00 +01:00
|
|
|
*
|
2008-01-04 21:05:07 +01:00
|
|
|
* @global bool $is_apache
|
|
|
|
*/
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
$is_apache = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) );
|
2008-01-04 21:05:07 +01:00
|
|
|
|
2013-09-16 22:07:09 +02:00
|
|
|
/**
|
2013-10-25 04:29:52 +02:00
|
|
|
* Whether the server software is Nginx or something else
|
2017-12-01 00:11:00 +01:00
|
|
|
*
|
2013-10-25 04:29:52 +02:00
|
|
|
* @global bool $is_nginx
|
|
|
|
*/
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
$is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) );
|
2013-10-25 04:29:52 +02:00
|
|
|
|
2008-01-04 21:05:07 +01:00
|
|
|
/**
|
|
|
|
* Whether the server software is IIS or something else
|
2017-12-01 00:11:00 +01:00
|
|
|
*
|
2008-01-04 21:05:07 +01:00
|
|
|
* @global bool $is_IIS
|
|
|
|
*/
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
$is_IIS = ! $is_apache && ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) );
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2009-05-16 04:04:36 +02:00
|
|
|
/**
|
2013-07-08 22:27:06 +02:00
|
|
|
* Whether the server software is IIS 7.X or greater
|
2017-12-01 00:11:00 +01:00
|
|
|
*
|
2009-05-18 16:54:16 +02:00
|
|
|
* @global bool $is_iis7
|
2009-05-16 04:04:36 +02:00
|
|
|
*/
|
2020-10-08 23:15:13 +02:00
|
|
|
$is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) >= 7;
|
2012-04-10 03:19:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
|
|
|
|
*
|
2016-12-27 10:21:44 +01:00
|
|
|
* @since 3.4.0
|
2017-12-01 00:11:00 +01:00
|
|
|
*
|
2015-06-27 02:45:24 +02:00
|
|
|
* @return bool
|
2012-04-10 03:19:30 +02:00
|
|
|
*/
|
|
|
|
function wp_is_mobile() {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
2012-04-10 03:19:30 +02:00
|
|
|
$is_mobile = false;
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.)
|
|
|
|
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Android' )
|
|
|
|
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Silk/' )
|
|
|
|
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Kindle' )
|
|
|
|
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' )
|
|
|
|
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' )
|
|
|
|
|| str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) ) {
|
2012-04-10 03:19:30 +02:00
|
|
|
$is_mobile = true;
|
|
|
|
} else {
|
|
|
|
$is_mobile = false;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:05:42 +02: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-10 03:19:30 +02:00
|
|
|
}
|