Store Only Shortened IP Addresses for Comments
Saves commenters' IP addresses with the last part removed (for example 203.0.113.0), which is still enough for spam checks but no longer identifies a person.
Opens WPIDE on
Code
// 'mask' keeps the network part of the address, 'none' stores nothing.
$wpide_comment_ip_mode = 'mask';
add_filter( 'pre_comment_user_ip', function ( $ip ) use ( $wpide_comment_ip_mode ) {
if ( 'none' === $wpide_comment_ip_mode ) {
return '';
}
return function_exists( 'wp_privacy_anonymize_ip' ) ? wp_privacy_anonymize_ip( $ip ) : '';
}, 20 );
Notes
Set $wpide_comment_ip_mode to 'none' to store no IP address at all; some anti-spam services work less well without it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.