Provides geographic information detected by an IP adress.
Provides geographic information detected by an IP adress. This can be used in themes or other plugins, as a shortcode, or via CSS body classes. The city & country names are translated in different languages (supported languages).
geoip_detect2_get_info_from_ip($ip, $locales = array('en'), $options = array())
: Lookup Geo-Information of the specified IPgeoip_detect2_get_info_from_current_ip($locales = array('en'), $options = array())
: Lookup Geo-Information of the current website usergeoip_detect2_get_current_source_description(...)
: Return a human-readable label of the currently chosen source.geoip_detect2_get_external_ip_adress()
: Fetch the internet adress of the webservergeoip_detect2_get_client_ip()
: Get client IP (even if it is behind a reverse proxy)[geoip_detect2 property="country.name" default="(country could not be detected)" lang="en"]
(where ‘country.name’ can be one of the other property names as well, and ‘default’ and ‘lang’ are optional).[geoip_detect2_show_if country="FR, DE" not_city="Berlin"]TEXT[/geoip_detect2_show_if]
. See Shortcode Documentation.geoip-province-HE
, geoip-country-DE
and geoip-continent-EU
.[geoip_detect2_countries mycountry]
[geoip_detect2_text_input city property:city lang:fr id:id class:class default:Paris]
[geoip_detect2_user_info]
[geoip_detect2_user_info]
[geoip_detect2_current_flag]
(see documentation)See Documentation for more info.
System Requirements: You will need at least PHP 7.2.5 . Also, if you use the plugin WooCommerce, you’ll need at least WooCommerce 3.9.0 .
GDPR: See Is this plugin GDPR-compliant?
This extension is “charity-ware”. If you are happy with it, please leave a tip for the benefit of this charity. (See FAQ for more infos.)
Here are other ways to contribute to the development of this plugin.
This product can provide GeoLite2 data created by MaxMind, available from http://www.maxmind.com.
geoip_detect2_get_info_from_current_ip()
return the same country, regardless of where you are visiting the site from? Disable caching a page that contains a shortcode or API call to geo-dependent functions.
Technically speaking, how could I verify if my visitor comes from Germany?
How can I show text only if the visitor is coming from Germany?
How can I add the current country name as text in my page?
Which data source should I choose?
Can I change the time period how long the data is cached?
Does this plugin work in a MultiSite-Network environment?
Is this plugin GDPR-compliant?
What does “Privacy Exclusions” mean?
What do you mean by “This plugin is charity-ware”?
{geoip_detect2_user_info}
)geoip_detect2_client_ip_whitelist_internal_ips
.New Datasource: Fastah Web API (beta), see https://aws.amazon.com/marketplace/pp/prodview-k5gjowexrefl2
AJAX mode:
* NEW: The JS function geoip_detect.set_override_with_merge
can modify the override record in one property, merging it with the currently saved property
Other minor changes:
* FIX: In non-AJAX mode, properties such as “extra.original.zip” can be accessed again
* FIX: Automatic download of Maxmind database now also works when the temp folder is group/world writeable (as in AWS configurations)
* If you want to enable more Warnings (e.g. while debugging), you can add define('GEOIP_DETECT_DEBUG', true)
to your wp-config.php or so.
* Library updates
In this release, there a small breaking changes marked by [!].
AJAX mode:
* FIX [!]: Empty attribute values such as [geoip_detect2_show_if country=""]Country was not detected[/geoip_detect2_show_if]
are now working (they were ignored before)
* FIX [!]: Shortcodes that have an invalid value for the property ajax
(e.g. [geoip_detect2_text_input ajax="invalid"]
) are now using the AJAX option instead of always disabling AJAX
* FIX: In CF7, the country selector can now be used in AJAX mode
* FIX: In AJAX mode, the shortcode [geoip_detect2_show_if]
renders as a <div>
if it detects that the containing content has HTML block level elements
* NEW (Beta): In AJAX mode, the new property autosave
saves the user input as local override for this browser. [geoip_detect2_countries mycountry autosave]
and [geoip_detect2_text_input city property:city autosave]
. (Please give feedback if this works as expected!)
* FIX: In AJAX mode, calling the method set_override(record, duration_in_days)
now refreshes the AJAX shortcodes and CSS body classes.
-> Thus, it is now possible to quickly implement different content for different countries with an autodetected default country, see https://github.com/yellowtree/geoip-detect/wiki/API-Usage-Examples#country-selector-that-can-be-overridden-by-the-user
Other changes:
* NEW: Drastically improving performance if the lookup is performed for the current IP more than once (e.g. because of shortcodes without AJAX mode)
* UI: Showing the time for the subsequent lookup on the Test Lookup page
* FIX: Maxmind Datasource: Check if the database file is really a file, not a directory
* NEW: Header Datasource: Now a custom HTTP header can be used via the wordpress filter geoip_detect2_source_header_http_key
Other minor changes:
* Update the list of available APIs for getting the external IP (as whatismyip went down)
* Minimum WordPress version is 5.4 now.
* Update some internal libraries & dev tools
* Checked compatibility with PHP 8.1
[geoip_detect2_property_country__iso_code]
else
shortcode for geoip_detect2_show_if
and geoip_detect2_hide_if
: [geoip_detect2_show_if city="Berlin"]You are in Berlin[else]You are not in Berlin[/geoip_detect2_show_if]
Record.get_with_locales()
and other methods of Record
to be consistent with non-AJAX modeThis version has many changes regarding the Shortcodes API. It is a major version because it increases some system requirements (see below).
set_override(record, duration_in_days)
(see AJAX documentation) so that the record information can be overridden manually (e.g. when the user selects a certain country manually). A PHP equivalent will follow.operator="OR"
– this can be used to create conditions such as “continent = EU OR country = US”Other Improvements:
* NEW (UI): Add a “Empty Cache”-Button on the Lookup page if the data source is caching the results
* FIX: In some cases, the Privacy Exclusions Update wasn’t rescheduled properly before
* FIX: Ipstack: The property country.isInEuropeanUnion is now filled properly.
* Updated vendor code
Also note:
* The minimum PHP version is now 7.2.5
* Minimum WordPress version is now 5.0
* The plugin is now using PHP Type-Hinting for API functions – if you used the PHP API, please check if you see PHP errors
* If you are using WooCommerce, you need at least version 3.9.0 (released Jan 2020) – otherwise this plugin lookup disables itself
As always, if you are happy about the plugin, please consider donating, becoming a Beta-Tester or otherwise contributing to it.
[geoip_detect2_enqueue_javascript]
if you are using AJAX mode, but only on certain wordpress pages.[geoip_detect2_text_input]
now has a parameter type
for hidden or other HTML5 input types (see Postal code example)$record->extra->currencyCode
for the currency code of the detected country has been added$record->country
: $record->extra->countryIsoCode3
or [geoip_detect2 property="extra.countryIsoCode3"]
[geoip_detect2_countries]
now selects the selected country on page reload (the HTML tag autocomplete is set to off
now)[geoip_detect2_countries mycountry include_blank flag tel]
now adds the flag emoji (or ISO code in Windows) and the telephone international code to the country namegeoip_detect2_enqueue_javascript()
can be used now in function.php or templates (see PHP Example)[geoip_detect2_show_if property="country.isInEuropeanUnion" property_value="true"]Products list for EU[/geoip_detect2_show_if]
now works properly (boolean values can be “true”/”yes” or “false”/”no”)[geoip_detect2_current_flag]
now compatible with the SVG Flags version 0.9.0. See Documentation for more infos. (Was not released)
The code of the plugin has not changed much, I have named this version 3.0 to indicate the major change on Maxmind’s side of things. They explain it in this blog post:
https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/