BBQ Pro makes it possible to customize how IP addresses are detected in the plugin. This quick tutorial explains how to make it happen with a bit of custom code.

Important: This post is for people who need who customize the the headers used by BBQ Pro when checking for the request IP address. So 99.9% of users this post is safe to ignore.

Default IP Detection

By default, BBQ Pro checks the IP address against the following headers:

$ip_keys = array('HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_X_REAL_IP', 'HTTP_X_COMING_FROM', 'HTTP_PROXY_CONNECTION', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'HTTP_COMING_FROM', 'HTTP_VIA', 'REMOTE_ADDR');

This ordering of headers proves ideal in most cases. But there may be situations where some other order and/or headers would be optimal. For example, if you are using a service such as Clodflare to filter traffic for your site, the header used for the IP address may be something specific, such as HTTP_CF_CONNECTING_IP for example. In such case, you can customize the header array to suit your needs. Check out the next section to learn how..

Custom IP Detection

To customize the headers that BBQ checks for the IP address, add the following code to your theme (or child theme) functions.php, or add via simple custom plugin:

function bbq_ip_keys_custom($keys) {
	
	return array('HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP'); // must be an array
	
}
add_filter('bbq_ip_keys', 'bbq_ip_keys_custom');

Notice the array that is being returned in this function. That is where you can specify whichever IP headers that should be used for your site. Remember to test well after making any changes!