pre_comment_user_ip WordPress Filter Hook

The pre_comment_user_ip hook is a WordPress hook that is triggered before a comment is saved to the database. This hook can be used to check the comment author's IP address and to make sure that it is not on a blacklist.

apply_filters( 'pre_comment_user_ip', string $comment_author_ip ) #

Filters the comment author’s IP address before it is set.


Parameters

$comment_author_ip

(string)The comment author's IP address.


Top ↑

More Information

With this filter, we can change the comment author’s IP before it’s recorded. Example use case can be when a client submits a comment through a proxy server.

The general format of the header is:
X-Forwarded-For: client1, proxy1, proxy2

where the value is a comma+space separated list of IP addresses, the left-most being the original client, and each successive proxy that passed the request adding the IP address where it received the request from. In this example, the request goes through the IPs: client1 -> proxy1 -> proxy2 -> proxy3. Proxy3 is not shown in the X-Forwarded-For header here and appears as the remote address of the request.

Since it is easy to forge an X-Forwarded-For header, the given information should be used with care.

X-Forwarded-For, X-Forwarded-By, and X-Forwarded-Proto are non-standard header fields and in increasing cases, have been superseded by the standard Forwarded header defined in RFC 7239. Example of a Forwarded header:
Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43


Top ↑

Source

File: wp-includes/comment.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More