Home> CMS Tutorial> WordPress> body text

Teach you how to disable WordPress comments from storing IP addresses

藏色散人
Release: 2020-11-04 15:02:26
forward
2232 people have browsed it

The following columnWordPress Tutorialwill introduce to you how to disable WordPress comments from storing IP addresses. I hope it will be helpful to friends in need!

Teach you how to disable WordPress comments from storing IP addresses

DefaultWordPresswill 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 ''; }
Copy after login

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; }
Copy after login

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=''" );
Copy after login

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!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!