return $data; } } } return $default; } public function get_request_uri() { return rawurldecode( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); } public function get_current_url() { $protocol = is_ssl() ? 'https:' : 'http:'; $domain = wp_parse_url( site_url(), PHP_URL_HOST ); $path = wp_parse_url( $this->get_request_uri(), PHP_URL_PATH ); $query = wp_parse_url( $this->get_request_uri(), PHP_URL_QUERY ); $url = $protocol . '//' . $domain . $path; if ( $query ) { $url .= '?' . $query; } return $url; } public function get_request_method() { if ( empty( $_SERVER['REQUEST_METHOD'] ) ) { return ''; } return strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ); } public function get_device_type() { if ( ! $this->is_mobile() ) { return 'desktop'; } if ( $this->is_tablet() ) { return 'tablet'; } return 'mobile'; } private function is_tablet() { $user_agent = $this->get_user_agent(); if ( empty( $user_agent ) ) { return false; } /** * It doesn't work with IpadOS due to 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 ); } private function is_mobile() { $user_agent = $this->get_user_agent(); 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 ); } public function is_function_supported( $function_name ) { if ( ! function_exists( $function_name ) ) { return false; } $disabled_functions = explode( ',', ini_get( 'disable_functions' ) ); if ( in_array( $function_name, $disabled_functions ) ) { return false; } return true; } }