Skip to content

Instantly share code, notes, and snippets.

@vhsu
Last active August 5, 2019 09:50
Show Gist options
  • Save vhsu/aad62aafd2f782e826f8c0e3589b5440 to your computer and use it in GitHub Desktop.
Save vhsu/aad62aafd2f782e826f8c0e3589b5440 to your computer and use it in GitHub Desktop.
Override $_SERVER['REMOTE_ADDR'] for Wordpress with Contact form 7 [_remote_ip] shortcode and Cloudflare
// Override $_SERVER['REMOTE_ADDR'] on Wordpress to retrieve the client ip for cloudflare users
// This will also correct the [_remote_ip] shortcode with contact form 7 ( wpcf7 ) or any other plugin using $_SERVER['REMOTE_ADDR']
// Simply add the following code in the wp_config.php file and you're done.
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment