PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.2.0
Defender Security – Malware Scanner, Login Security & Firewall v6.2.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / traits / device.php

device.php in Defender Security – Malware Scanner, Login Security & Firewall 6.2.0, at src/traits/device.php

65 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Device helper.
4 *
5 * @package WP_Defender\Traits
6 * @since 4.2.0
7 */
8
9 namespace WP_Defender\Traits;
10
11 trait Device {
12
13 /**
14 * Detect if the device is a tablet.
15 *
16 * @return bool
17 */
18 private function is_tablet() {
19 $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' );
20 if ( '' === $user_agent ) {
21 return false;
22 }
23 /**
24 * It doesn't work with IpadOS due to of this:
25 * https://stackoverflow.com/questions/62323230/how-can-i-detect-with-php-that-the-user-uses-an-ipad-when-my-user-agent-doesnt-c
26 */
27 $tablet_pattern = '/(tablet|ipad|playbook|kindle|silk)/i';
28
29 return preg_match( $tablet_pattern, $user_agent );
30 }
31
32 /**
33 * Detect if the device is a mobile.
34 *
35 * @return bool|string
36 */
37 private function is_mobile() {
38 $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' );
39 if ( '' === $user_agent ) {
40 return false;
41 }
42 // Do not use wp_is_mobile() since it doesn't detect ipad/tablet.
43 $mobile_patten = '/Mobile|iP(hone|od|ad)|Android|BlackBerry|tablet|IEMobile|Kindle|NetFront|Silk|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune|playbook/i';
44
45 return preg_match( $mobile_patten, $user_agent );
46 }
47
48 /**
49 * Get current device type.
50 *
51 * @return string
52 */
53 protected function get_device() {
54 if ( $this->is_mobile() ) {
55 return 'mobile';
56 }
57
58 if ( $this->is_tablet() ) {
59 return 'tablet';
60 }
61
62 return 'desktop';
63 }
64 }
65