Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| jetpack_is_mobile | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
110 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
| 2 | /** |
| 3 | * This file holds a function that needs to be loaded before WordPress itself |
| 4 | * on WordPress.com. |
| 5 | * |
| 6 | * @package automattic/jetpack |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Device_Detection; |
| 10 | |
| 11 | /** |
| 12 | * Determine if the current User Agent matches the passed $kind |
| 13 | * |
| 14 | * @param string $kind Category of mobile device to check for. |
| 15 | * Either: any, dumb, smart. |
| 16 | * @param bool $return_matched_agent Boolean indicating if the UA should be returned. |
| 17 | * |
| 18 | * @return bool|string Boolean indicating if current UA matches $kind. If |
| 19 | * $return_matched_agent is true, returns the UA string |
| 20 | */ |
| 21 | function jetpack_is_mobile( $kind = 'any', $return_matched_agent = false ) { |
| 22 | |
| 23 | if ( function_exists( 'apply_filters' ) ) { |
| 24 | /** |
| 25 | * Filter the value of jetpack_is_mobile before it is calculated. |
| 26 | * |
| 27 | * Passing a truthy value to the filter will short-circuit determining the |
| 28 | * mobile type, returning the passed value instead. |
| 29 | * |
| 30 | * @since 4.2.0 |
| 31 | * |
| 32 | * @param bool|string $matches Boolean if current UA matches $kind or not. If |
| 33 | * $return_matched_agent is true, should return the UA string |
| 34 | * @param string $kind Category of mobile device being checked |
| 35 | * @param bool $return_matched_agent Boolean indicating if the UA should be returned |
| 36 | */ |
| 37 | $pre = apply_filters( 'pre_jetpack_is_mobile', null, $kind, $return_matched_agent ); |
| 38 | if ( $pre ) { |
| 39 | return $pre; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | $return = false; |
| 44 | $device_info = Device_Detection::get_info(); |
| 45 | |
| 46 | if ( 'any' === $kind ) { |
| 47 | $return = $device_info['is_phone']; |
| 48 | } elseif ( 'smart' === $kind ) { |
| 49 | $return = $device_info['is_smartphone']; |
| 50 | } elseif ( 'dumb' === $kind ) { |
| 51 | $return = $device_info['is_phone'] && ! $device_info['is_smartphone']; |
| 52 | } |
| 53 | |
| 54 | if ( $return_matched_agent && true === $return ) { |
| 55 | $return = $device_info['is_phone_matched_ua']; |
| 56 | } |
| 57 | |
| 58 | if ( function_exists( 'apply_filters' ) ) { |
| 59 | /** |
| 60 | * Filter the value of jetpack_is_mobile |
| 61 | * |
| 62 | * @since 4.2.0 |
| 63 | * |
| 64 | * @param bool|string $matches Boolean if current UA matches $kind or not. If |
| 65 | * $return_matched_agent is true, should return the UA string |
| 66 | * @param string $kind Category of mobile device being checked |
| 67 | * @param bool $return_matched_agent Boolean indicating if the UA should be returned |
| 68 | */ |
| 69 | $return = apply_filters( 'jetpack_is_mobile', $return, $kind, $return_matched_agent ); |
| 70 | } |
| 71 | |
| 72 | return $return; |
| 73 | } |