Skip to content

How to migrate from v1 to v2

Benjamin Pick edited this page Dec 23, 2014 · 19 revisions

What's New

MaxMind released a new version of the library accessing the database:

MaxMind What's New

This is a major change ...

New Function Names

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();

Old Function Names / Legacy Code

The old function names return the same data structure as before, but internally still uses the v2-Database.

Properties that might not work:

  • region and region_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).
Clone this wiki locally