From 09d8bc184bf4b2d29f3155634687c877774204cc Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 20 Sep 2023 20:51:19 +0000 Subject: [PATCH] General: Account for `Sec-CH-UA-Mobile` client hint request header in `wp_is_mobile()`. Add missing test coverage for `wp_is_mobile()`. Fixes #59370. Props westonruter, flixos90. Built from https://develop.svn.wordpress.org/trunk@56638 git-svn-id: http://core.svn.wordpress.org/trunk@56150 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/vars.php | 7 ++++++- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wp-includes/vars.php b/wp-includes/vars.php index d6160dd23e..dc28b8509a 100644 --- a/wp-includes/vars.php +++ b/wp-includes/vars.php @@ -144,11 +144,16 @@ $is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVE * 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 . + $is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ); + } elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { $is_mobile = false; } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Android' ) diff --git a/wp-includes/version.php b/wp-includes/version.php index eb63da46cd..9020cecd6a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56637'; +$wp_version = '6.4-alpha-56638'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.