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
This commit is contained in:
Weston Ruter 2023-09-20 20:51:19 +00:00
parent ebfa9be225
commit 09d8bc184b
2 changed files with 7 additions and 2 deletions

View File

@ -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.) * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
* *
* @since 3.4.0 * @since 3.4.0
* @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header.
* *
* @return bool * @return bool
*/ */
function wp_is_mobile() { 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; $is_mobile = false;
} elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.) } 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'], 'Android' )

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.