Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to prevent WordPress comments from storing IP addresses

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Xiaobian to share with you how to prohibit WordPress comments storage IP address, I hope you read this article after the harvest, let us discuss it together!

By default WordPress will store the IP address of the commenter in the background, mainly for anti-spam comments, such as plugins such as Akismet, which will judge spam comments by IP. But IP is personal privacy, not storing commenter IP, may make users have more trust in your website.

We can remove this functionality by adding the following code to the current topic function template functions.php:

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

After that, the IP address of the reviewer is no longer stored.

You can also install the Remove IP plug-in to achieve the same functionality, and there is only a similar piece of code in the plug-in, replacing 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 is already stored in the database. If you want to delete it, you can also add the following code to the current topic function template functions.php:

global $wpdb;$wpdb->query( "UPDATE wp_comments SET comment_author_IP=''" );

Then refresh the page. The IP address of the commenter stored before will be deleted from the database. The code does not need to be kept in the theme. Please remove it after use.

Tip: There are risks in operating the database. Please make backups in advance, just in case!

After reading this article, I believe you have a certain understanding of how to prohibit WordPress comments from storing IP addresses. If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report