Skip to content

Instantly share code, notes, and snippets.

@timersys
Created July 28, 2016 12:56
Show Gist options
  • Select an option

  • Save timersys/6625d457ce3a47fc42c73ee7da32a047 to your computer and use it in GitHub Desktop.

Select an option

Save timersys/6625d457ce3a47fc42c73ee7da32a047 to your computer and use it in GitHub Desktop.
Create a whitelist for geotargeting redirections in WordPress
<?php
/**
* Create a whitelist for geotargeting redirections
* to be used with Geotargeting Pro plugin https://timersys.com/plugins/geotargeting-pro/
* */
// add filter before redirects are performed
add_action( 'init', 'geot_redirects', 9 );
function geot_redirects() {
add_filter( 'geot/perform_redirect', 'geot_redirect_whitelist');
}
/**
* Grab user IP and check on whitelist
* */
function geot_redirect_whitelist(){
global $geot;
$whitelist = array(
'190.188.194.218'
);
$ip = isset( $geot->functions ) ? $geot->functions->getUserIP() : '';
if( in_array( $ip, $whitelist ) )
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment