• Resolved Ewout

    (@pomegranate)


    I’m seeing some errors in my PHP log that point to an incompatiblity with your version of
    geoip_country_code_by_name() versus the official version from the geoip PHP extension: https://php.net/manual/en/function.geoip-country-code-by-name.php

    
    PHP Warning:  Missing argument 2 for geoip_country_code_by_name(), called in /wp-content/plugins/edd-vat/includes/actions.php on line 532 and defined in /wp-content/plugins/wordfence/lib/wfGeoIP.php on line 448
    

    It seems that both Wordfence and this other plugin (edd-vat) check for the existence of this function and create it when not present. However, your implementation differs from the official function (here) in that it takes completely different arguments, so when this other plugin calls this function and then uses yours, things go haywire.

    I could enable the geoip extension to prevent either plugins from (re)creating this function, but I’m not sure if this will break anything in your plugin because your syntax will still be different to the official syntax… (regardless of whether I use that other plugin).

    How should I best proceed?
    Ewout

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @pomegranate,

    It looks like the “edd-vat” plugin is defining geoip_country_code_by_name with a parameter list that does not match PHP’s own native definition.

    Wordfence doesn’t redefine the geoip function if present, so it’s ending up calling that incorrect one.

    Have you tried to get in touch with the authors of that other plugin? Are they aware of any issue related to the geoip function?

    Thread Starter Ewout

    (@pomegranate)

    Hi @wfyann,
    It’s actually the other way around.
    Here’s the official function from geoip:
    https://php.net/manual/en/function.geoip-country-code-by-name.php

    string geoip_country_code_by_name ( string $hostname )

    And your code (in lib\wfGeoIP.php):

    
    if(! function_exists('geoip_country_code_by_name')){
    	function geoip_country_code_by_name($gi, $name) {
    		$country_id = geoip_country_id_by_name($gi,$name);
    		if ($country_id !== false) {
    			return $gi->GEOIP_COUNTRY_CODES[$country_id];
    		}
    		return false;
    	}
    }
    

    As you can see, your function takes completely different arguments.
    The problem is that “edd-vat” also checks if geoip_country_code_by_name is defined and if so, it calls it using the official syntax, which then throws an error because you have redefined it with a different syntax.

    This is all happening in the scenario where the geoip extension is not activated and thus both plugins try to work without it. I just think that you shouldn’t redefine an official function with your own arguments in an environment where others may be dependent on this too. If they check the same way you do (function_exists) and you are first, they lose.

    Ewout

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘geoip_country_code_by_name compatibility’ is closed to new replies.