Make WordPress Core


Ignore:
Timestamp:
09/20/2023 08:49:12 PM (13 months ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/vars.php

    r56596 r56638  
    145145 *
    146146 * @since 3.4.0
     147 * @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header.
    147148 *
    148149 * @return bool
    149150 */
    150151function wp_is_mobile() {
    151     if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
     152    if ( isset( $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ) ) {
     153        // This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header.
     154        // See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>.
     155        $is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] );
     156    } elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
    152157        $is_mobile = false;
    153158    } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.)
Note: See TracChangeset for help on using the changeset viewer.