wp/wp-includes/vars.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/vars.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/vars.php	Fri Sep 05 18:40:08 2025 +0200
@@ -10,14 +10,14 @@
  * servers with known pretty permalink capability.
  *
  * Note: Though Nginx is detected, WordPress does not currently
- * generate rewrite rules for it. See https://wordpress.org/support/article/nginx/
+ * generate rewrite rules for it. See https://developer.wordpress.org/advanced-administration/server/web-server/nginx/
  *
  * @package WordPress
  */
 
 global $pagenow,
 	$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge,
-	$is_apache, $is_IIS, $is_iis7, $is_nginx;
+	$is_apache, $is_IIS, $is_iis7, $is_nginx, $is_caddy;
 
 // On which page are we?
 if ( is_admin() ) {
@@ -39,7 +39,7 @@
 	} else {
 		preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
 		$pagenow = strtolower( $self_matches[1] );
-		if ( '.php' !== substr( $pagenow, -4, 4 ) ) {
+		if ( ! str_ends_with( $pagenow, '.php' ) ) {
 			$pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried).
 		}
 	}
@@ -65,10 +65,12 @@
 $is_edge   = false;
 
 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
-	if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) {
+	if ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) ) {
 		$is_lynx = true;
-	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) !== false ) {
+	} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) ) {
 		$is_edge = true;
+	} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'OPR/' ) ) {
+		$is_opera = true;
 	} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) {
 		if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
 			$is_admin = is_admin();
@@ -89,15 +91,15 @@
 		}
 	} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) {
 		$is_safari = true;
-	} elseif ( ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) !== false ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Win' ) !== false ) {
+	} elseif ( ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) )
+		&& str_contains( $_SERVER['HTTP_USER_AGENT'], 'Win' )
+	) {
 		$is_winIE = true;
-	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) !== false ) {
+	} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) ) {
 		$is_macIE = true;
-	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) !== false ) {
+	} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) ) {
 		$is_gecko = true;
-	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) !== false ) {
-		$is_opera = true;
-	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) !== false ) {
+	} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) ) {
 		$is_NS4 = true;
 	}
 }
@@ -111,50 +113,62 @@
 // Server detection.
 
 /**
- * Whether the server software is Apache or something else
+ * Whether the server software is Apache or something else.
  *
  * @global bool $is_apache
  */
-$is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false );
+$is_apache = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) );
 
 /**
- * Whether the server software is Nginx or something else
+ * Whether the server software is Nginx or something else.
  *
  * @global bool $is_nginx
  */
-$is_nginx = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false );
+$is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) );
 
 /**
- * Whether the server software is IIS or something else
+ * Whether the server software is Caddy / FrankenPHP or something else.
+ *
+ * @global bool $is_caddy
+ */
+$is_caddy = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Caddy' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'FrankenPHP' ) );
+
+/**
+ * Whether the server software is IIS or something else.
  *
  * @global bool $is_IIS
  */
-$is_IIS = ! $is_apache && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false );
+$is_IIS = ! $is_apache && ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) );
 
 /**
- * Whether the server software is IIS 7.X or greater
+ * Whether the server software is IIS 7.X or greater.
  *
  * @global bool $is_iis7
  */
 $is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) >= 7;
 
 /**
- * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
+ * Test if the current browser runs on a mobile device (smart phone, tablet, etc.).
  *
  * @since 3.4.0
+ * @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header.
  *
  * @return bool
  */
 function wp_is_mobile() {
-	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
+	if ( isset( $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ) ) {
+		// This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header.
+		// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>.
+		$is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] );
+	} elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
 		$is_mobile = false;
-	} 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 ) {
+	} 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' ) ) {
 			$is_mobile = true;
 	} else {
 		$is_mobile = false;