$name) { if (strpos($name, ',') !== false) { $data = str_ireplace($name, $code, $data); } } if ( strpos($data, ',') !== false) return array_map( 'trim', explode( ',', $data ) ); return array( trim( $data ) ); } function wplocation_visitor_country_name() { $wplocation_ip_address = wplocation_get_ipaddress(); // Get visitor's IP address $get_country_iso = wplocation_get_country_iso($wplocation_ip_address); // Get visitor's country ISO if( (empty($get_country_iso)) ) { // if invalid Country ISO return return false; } $get_country_iso = strtolower($get_country_iso); $get_country_name = wplocation_iso_to_country( $get_country_iso ); // Get visitor's country Name if( $get_country_name == false ) { // if (invalid/not found) Country name return return false; } $get_country_name = strtolower($get_country_name); return $get_country_name; } // Retrieves the IP address from the HTTP Headers function wplocation_get_ipaddress() { // Forwarded headers are untrusted unless infrastructure explicitly supplies // an independently verified address through this filter. $remote = isset($_SERVER['REMOTE_ADDR']) && is_string($_SERVER['REMOTE_ADDR']) ? trim(sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR']))) : ''; $address = apply_filters('wplocation_verified_client_ip', $remote); return is_string($address) && filter_var($address, FILTER_VALIDATE_IP) ? $address : ''; } // Check if IP address is a valid IPv4 address function wplocation_is_valid_ipv4($ipv4) { if(filter_var($ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE) { // Is not ipv4 return false; } // Is valid ipv4 return true; } // Check if IP address is a valid IPv6 address function wplocation_is_valid_ipv6($ipv6) { if(filter_var($ipv6, FILTER_VALIDATE_IP,FILTER_FLAG_IPV6) === FALSE) { // Is not ipv6 return false; } // Is valid ipv6 return true; } function wplocation_get_country_iso($address) { static $results = array(); $database = wplocation_database_path(); if (!is_string($address) || !filter_var($address, FILTER_VALIDATE_IP) || !is_file($database)) { return false; } $site = function_exists('get_current_blog_id') ? get_current_blog_id() : 0; $key = $site . '|' . $database . '|' . $address; if (array_key_exists($key, $results)) { return $results[$key]; } $country = false; try { $reader = new \MaxMind\Db\Reader($database); $type = $reader->metadata()->databaseType; if ($type !== 'GeoLite2-Country') { $reader->close(); return false; } $record = $reader->get($address); $reader->close(); if (!empty($record['country']['iso_code']) && preg_match('/^[A-Z]{2}$/', $record['country']['iso_code'])) { $country = $record['country']['iso_code']; } } catch (Throwable $e) { $country = false; } $results[$key] = $country; return $country; }