... ...

Add gmp_g Rewrite API Key filter to rewrite Google Map API key

First of all, for correct work of map it’s highly recommended adding your Google Maps API key. You can get it from Google Maps service.

User_API_key

But sometimes, user needs to substitute the main API key or use several keys according to the circumstances.

There is an additional option to substitute the main API key programally which already has been saved in settings. 

The substitution ensues with a help of the gmp_g Rewrite Api Key filter.

Here  is an instruction how to work with a filters in WordPress.

 


For better understanding take an example:

add_filter('gmp_gRewriteApiKey', array($this, 'getCustomGoogleApiKey'));

function getCustomGoogleApiKey($key) {

if(is_user_logged_in()) {

 $key = 'some_another_key';

}

return $key;

}

 


 You can add this code into the page or to the another plugin – the main thing is that

add_filter(‘gmp_gRewriteApiKey’, array($this, ‘getCustomGoogleApiKey’))

Function have to be called before the system will request API key. 

Categories
Latest Articles