This filter can be used to allow guests to vote on a comment that was posted from their own IP address.
Parameters
- $denyVote (type: bool) – whether the vote should be denied. true by default
- $comment (type: WP_Comment object) – the comment being voted on
- $userIP (type: string) – the current guest’s IP address, after the pre_comment_user_ip filter has been applied
Usage
add_filter("wpdiscuz_deny_vote_from_same_ip", "my_allow_office_votes", 10, 3);
function my_allow_office_votes($denyVote, $comment, $userIP) {
if (strpos($userIP, "192.168.") === 0) {
return false;
}
return $denyVote;
}
Note
The filter runs twice per comment. Once while the vote controls are rendered, and once while the vote request is handled. A callback that returns different values in the two contexts produces visible buttons that reject the click.
It only runs for guests, and only when the visitor’s IP is not empty and matches the comment author’s IP. Registered users never reach it.
Returning false does not give same-IP guests separate voting identities. They still share one identity, md5($ip), so the comment author and the visitor count as one voter.
The address itself comes from the WordPress core filter pre_comment_user_ip, which wpDiscuz applies in WpdiscuzHelper::getRealIPAddr(). A callback that anonymises or truncates the address changes how guests are grouped, and one that returns an empty string blocks guest voting outright with the You Must Be Logged In To Vote message. wpDiscuz hooks that filter itself at priority 10, to convert ::1 to 127.0.0.1.
Changelog
Since 7.6.67 version
