Retriev3r
2/1/2018 - 10:00 AM

Cloudflare IP workaround

Override $_SERVER['REMOTE_ADDR'] for Wordpress with Contact form 7 [_remote_ip] shortcode and Cloudflare

Visitor IP: [_remote_ip]
User Agent: [_user_agent]

// 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"];
}