Home > Article > CMS Tutorial > Teach you how to disable WordPress comments from storing IP addresses
The following column WordPress Tutorial will introduce to you how to disable WordPress comments from storing IP addresses. I hope it will be helpful to friends in need!
DefaultWordPress will store the commenter’s IP address in the background, mainly for anti-spam comments, such as Akismet A plug-in like this will judge spam comments based on IP. However, IP belongs to personal privacy. Not storing the commenter’s IP may make users have more trust in your website.
We can remove this functionality by adding the following code to the current theme function template functions.php:
add_filter( 'pre_comment_user_ip', 'zm_remove_comments_ip' ); function zm_remove_comments_ip( $comment_author_ip ) { return ''; }
Afterwards, the commenter's IP address will no longer be stored.
You can also install the Remove IP plug-in to achieve the same function. There is only a similar code in the plug-in, which replaces all IPs with 127.0.0.1.
add_filter('pre_comment_user_ip', 'pre_comment_anon_ip'); function pre_comment_anon_ip() { $REMOTE_ADDR = "127.0.0.1"; return $REMOTE_ADDR; }
Although the IP address is no longer stored by adding the above code, the IP address of the previous comment has been stored in the database. If you want to delete it, you can also add the following code to the current topic function In template functions.php:
global $wpdb; $wpdb->query( "UPDATE wp_comments SET comment_author_IP=''" );
Then refresh the page, the previously stored commenter IP address will be deleted from the database, this code does not need to be retained in the theme, please remove it after use.
Tip: Operating the database is risky, please make a backup in advance, just in case!
The above is the detailed content of Teach you how to disable WordPress comments from storing IP addresses. For more information, please follow other related articles on the PHP Chinese website!