Skip to content
Docs
Get RestroPress

Filter

rpress_get_ip

Updated
On this page

Filters the IP address detected for the current visitor.

The address is taken from HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR (first entry) or REMOTE_ADDR, defaulting to 127.0.0.1. Filter it to read the address from a trusted proxy header instead.

Parameters#

ParameterTypeDescription
$ipstringThe detected IP address.

Return value#

string. The IP address.

Example#

function my_get_ip( $ip ) {
	if ( ! empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
		return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CF_CONNECTING_IP'] ) );
	}
	return $ip;
}
add_filter( 'rpress_get_ip', 'my_get_ip' );

Notes#

The default value comes from client-controllable headers and should not be trusted for security decisions.

Source#

Applied in:

  • includes/rp-core-functions.php (line 1898), in rpress_get_ip()
Was this page helpful?