-
-
Notifications
You must be signed in to change notification settings - Fork 38
How to migrate from v1 to v2
MaxMind released a new version of the library accessing the database:
This is a major change ...
In order to preserve backwards compatibility, the new API got new functions:
function geoip_detect2_get_info_from_ip($ip, $locales = null) { ... }
function geoip_detect2_get_info_from_current_ip($locales = null) { ... }
As you can see, you can now indicate a language that you want your labels in. Not all names are translated in all languages, so you can give an fallback order (array('de', 'en')
means "German if possible, English otherwise"). List of supported locales By default (null), it uses the current wordpress (backend) language for names or english as fallback. It also respects the WPML current language if present.
Note that unlike the MaxMind API, the plugin functions do not throw exceptions. If you want to see the exceptions to get more details about why a specific request failed, you can get the MaxMind Reader object and proceed as in their PHP Documentation:
$reader = geoip_detect2_get_reader();
- If the client IP is a public IP, but no information is found in the IP database, the API no longer falls back to the information of the server. If you need a default value, you can implement it e.g. as a filter.
- This also means that CLI usage is no longer supported.
- The API no longer returns null if there is no information about this IP, but an empty GeoIP object instead.
The old function names return the same data structure as before, but internally still uses the v2-Database.
-
region
andregion_name
: As the data-basis changed, there seem to be less regional coding. Also, the region-ids have changed: now they are two-letter-ISO-Codes. -
timezone
: Similarly, there is less data available. If it is not available, the plugin tries to fill it in - but without a region to rely on this only works in so many countries (ie countries with only 1 timezone).
Content of this documentation is available under Creative Commons Attribution-Share Alike 3.0 Unported License. Feel free to improve it by logging in with a Github user and editing it.