Incompatibility fix
-
I spotted an issue in the plugin, which makes it incompatible with any plugin using the same GeoIP library (e.g. Geo Redirect). The issue is that the plugin loads the
geoip.incfile unconditionally, without checking if such library has already been loaded, and will crash if another plugin has loaded the same library earlier.We could reproduce this issue consistently while using the plugin with our Currency Switcher for WooCommerce, which uses the same library, but checks if it has been loaded first. When both plugins are installed, two scenarios can occur.
Scenario 1
1. Block Country plugin loads first
2. Block Country plugin loadsgeoip.inc.
3. The Currency Switcher loads.
4. The Currency Switcher checks ifgeoip.inchas been loaded, and skips it.
5. Site works normally.Scenario 2
1. The Currency Switcher loads first.
2. The Currency Switcher checks ifgeoip.inchas been loaded. This is not the case, to it loads the library.
3. Block Country plugin loads
4. Block Country plugin **loadsgeoip.incwithout checking, and crashes**. This is the error to correct.Solution
Since there is no way to guarantee in which order plugins will be processed by WordPress, your plugin should check if the MaxMind library has been loaded before trying to load it again.Due to the procedural design of such an old library, such check is not as straightforward as it should be, but you can use the modified
geoip.incthat we added to our products, which already includes all necessary conditions. You can find it in our GitHub repository: https://github.com/daigo75/geoip-api-php. The library is an almost exact copy of the original one, with several conditions added to prevent duplicate loading and related crashes.
The topic ‘Incompatibility fix’ is closed to new replies.