Created
July 28, 2016 12:56
-
-
Save timersys/6625d457ce3a47fc42c73ee7da32a047 to your computer and use it in GitHub Desktop.
Create a whitelist for geotargeting redirections in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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