Server IP : 172.67.157.199 / Your IP : 18.223.210.67 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wp-content/plugins/defender-security/src/traits/ |
Upload File : |
<?php /** * Device helper. * * @package WP_Defender\Traits * @since 4.2.0 */ namespace WP_Defender\Traits; trait Device { /** * Detect if the device is a tablet. * * @return bool */ private function is_tablet() { $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' ); if ( empty( $user_agent ) ) { return false; } /** * It doesn't work with IpadOS due to of this: * https://stackoverflow.com/questions/62323230/how-can-i-detect-with-php-that-the-user-uses-an-ipad-when-my-user-agent-doesnt-c */ $tablet_pattern = '/(tablet|ipad|playbook|kindle|silk)/i'; return preg_match( $tablet_pattern, $user_agent ); } /** * Detect if the device is a mobile. * * @return bool|string */ private function is_mobile() { $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' ); if ( empty( $user_agent ) ) { return false; } // Do not use wp_is_mobile() since it doesn't detect ipad/tablet. $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'; return preg_match( $mobile_patten, $user_agent ); } /** * Get current device type. * * @return string */ protected function get_device() { if ( $this->is_mobile() ) { return 'mobile'; } if ( $this->is_tablet() ) { return 'tablet'; } return 'desktop'; } }