get_cached_result( $ip ); if ( $cached !== false ) { return $cached; } $url = $this->api_url . $ip . '?fields=status,country,countryCode,region,regionName,city,lat,lon,timezone,isp,org,as,proxy,hosting,query'; $response = $this->make_request( $url ); if ( ! $response['success'] ) { $this->log_usage( false ); return false; } $data = $response['data']; // Check if API returned success if ( isset( $data['status'] ) && $data['status'] !== 'success' ) { $this->log_usage( false ); return false; } $result = array( 'ip' => $data['query'] ?? $ip, 'country' => $data['country'] ?? '', 'country_code' => $data['countryCode'] ?? '', 'region' => $data['regionName'] ?? '', 'city' => $data['city'] ?? '', 'latitude' => $data['lat'] ?? null, 'longitude' => $data['lon'] ?? null, 'timezone' => $data['timezone'] ?? '', 'isp' => $data['isp'] ?? '', 'organization' => $data['org'] ?? '', 'as_number' => $data['as'] ?? '', 'is_proxy' => $data['proxy'] ?? false, 'is_hosting' => $data['hosting'] ?? false, 'provider' => $this->get_slug(), ); $this->cache_result( $ip, $result ); $this->log_usage( true ); return $result; } /** * Check if IP is VPN/Proxy * * @param array $ip_info IP information from get_ip_info * @return bool True if VPN/Proxy detected */ public function is_vpn_proxy( array $ip_info ): bool { return ! empty( $ip_info['is_proxy'] ) || ! empty( $ip_info['is_hosting'] ); } /** * Get country information * * @param array $ip_info IP information from get_ip_info * @return array Country info */ public function get_country_info( array $ip_info ): array { return array( 'code' => $ip_info['country_code'] ?? '', 'name' => $ip_info['country'] ?? '', ); } }