Created
March 17, 2017 16:54
-
-
Save tokkonopapa/1700523ad20543e8697be31109e301c5 to your computer and use it in GitHub Desktop.
In case $_SERVER[‘REMOTE_ADDR’] returns 127.0.0.1
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 | |
/** | |
* Example 2: Usage of 'ip-geo-block-ip-addr' | |
* Use case: Retrieve ip address behind the proxy | |
* | |
* @param string $ip original ip address | |
* @return string $ip replaced ip address | |
*/ | |
function my_retrieve_ip( $ip ) { | |
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { | |
$tmp = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ); | |
$tmp = trim( $tmp[0] ); | |
if ( filter_var( $tmp, FILTER_VALIDATE_IP ) ) { | |
$ip = $tmp; | |
} | |
} | |
return $ip; | |
} | |
add_filter( 'ip-geo-block-ip-addr', 'my_retrieve_ip' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Topic: Need to Clear Cache Every 2-3 Days « WordPress.org Forums