Skip to content

Instantly share code, notes, and snippets.

@timersys
Last active March 7, 2018 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timersys/fca60362573643c32656aaf90d4e3446 to your computer and use it in GitHub Desktop.
Save timersys/fca60362573643c32656aaf90d4e3446 to your computer and use it in GitHub Desktop.
Pass custom data to GeotargetingWP plugins instead of the API
<?php
/**
* If you want to cancel API calls for any reason or to pass custom that you can use the following
* filter. Note that we use json_decode(json_encode to pass an object instead of an array
**/
// Cancel query only for admins
add_filter('geot/cancel_query', function() {
if( ! current_user_can('administrator') )
return false;
$data = [];
$data['city']['names'] = [ 'en' => 'Miami'];
$data['city']['zip'] = '33166';
$data['continent']['names'] = 'North America';
$data['continent']['iso_code'] = 'NA';
$data['country']['iso_code'] = 'US';
$data['country']['names'] = [ 'en' => 'United States'];
$data['state']['iso_code'] = 'FL';
$data['state']['names'] = [ 'en' => 'Florida'];
$data['geolocation']['latitude'] = '11.11';
$data['geolocation']['longitude'] = '11.11';
$data['geolocation']['accuracy_radius']= '100';
$data['geolocation']['time_zone'] = 'UTC';
return json_decode(json_encode($data));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment