PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.9.3
Jetpack – WP Security, Backup, Speed, & Growth v12.9.3
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / functions.is-mobile.php

functions.is-mobile.php in Jetpack – WP Security, Backup, Speed, & Growth 12.9.3, at functions.is-mobile.php

74 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
74