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