function bm_remove_ip ( $ comment_author_ip ) { return '127.0.0.1' ; } add_filter ( 'pre_comment_user_ip' , 'bm_remove_ip' );

Using this method, all commenters’ IP addresses will be replaced with 127.0.0.1 (which is commonly used for localhost). The code used here is basically the same as that used by the “Remove IP” plugin.

You can, however, delete the data completely by pasting the following code into your theme’s functions.php file:

function wpb_remove_commentsip ( $ comment_author_ip ) {
return statement '' ;
}
add_filter ( 'pre_comment_user_ip' , 'wpb_remove_commentsip' );

The code snippet only prevents future IP addresses from being stored. The next step is to remove existing IP addresses from the database.

2. Delete existing IP addresses from the database

To remove existing IP addresses from the database, use the Remove Comment IPs plugin. As soon as the plugin is activated, all old IP addresses will be automatically deleted from the database. But you may have to wait a while depending on how big your WordPress database is.

It is important to note that if you disable WP-Cron, the plugin may not work. If WP Cron is disabled, you must start it manually or reactivate it on temporary basis.

Alternatively, if you are comfortable editing MySQL databases, you can remove IP addresses using a simple command in PHPMyAdmin:

UPDATE wp_comments SET comment_author_IP = ''

Note: If you used a different database prefix than wp_, the command should be edited accordingly. Replace “wp” with your own prefix.

3. Limit storage duration to X days

What if you want to limit the storage duration of IP addresses rather than completely delete them? You can limit storage duration with the plugin “Remove Comment IPs”. The plugin automatically deletes IP addresses after 60 days when activated.

Unfortunately, the plugin does not allow you to adjust the duration. But you can do this by making a small change to the plugin source code.

To do this, go to Plugins> Editor inside the WordPress dashboard and select “Remove Comment IPs” from the top right corner drop down menu. Then click on the plugin file remove-comment-ips.php and look for the following code block:

function remove_comment_ip_schedule_future_processing ( $ comment_id , $ comment_approved ) { // schedule processing in 60 days 
  wp_schedule_single_event ( time () + 5184000 , 'remove_comment_ip_handle' , array ( $ comment_id )); } 
add_action ( 'comment_post' , 'remove_comment_ip_schedule_future_processing' , 10 , 2 );

There you will find the preset 60 days in the form of 5184000 seconds. Replace it with your desired time duration.

For 7 days you have to enter 7 * 24 * 60 * 60 = 604800 seconds; for 14 days this would be 14 * 24 * 60 * 60 = 1209600 seconds, and so on.

Note: Backing up your WordPress installation may affect the actual storage time of IP addresses, since they will continue to appear in your backups even after being deleted.

If you liked this post, please consider sharing it with your friends:


Source link

Leave a Reply

Your email address will not be published. Required fields are marked *