Skip to content

Instantly share code, notes, and snippets.

@tokkonopapa
Created March 17, 2017 16:54
Show Gist options
  • Save tokkonopapa/1700523ad20543e8697be31109e301c5 to your computer and use it in GitHub Desktop.
Save tokkonopapa/1700523ad20543e8697be31109e301c5 to your computer and use it in GitHub Desktop.
In case $_SERVER[‘REMOTE_ADDR’] returns 127.0.0.1
<?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' );
@tokkonopapa
Copy link
Author

Topic: Need to Clear Cache Every 2-3 Days « WordPress.org Forums

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment