admin管理员组

文章数量:1122846

My WordPress website is being bombarded by spam comments. Nearly all of them contain a valid URL.

How can I delete these comments automatically? I don't want to put them into the review queue; I just want to get rid of them completely. I don't care if a few legitimate comments get deleted in the process.

My WordPress website is being bombarded by spam comments. Nearly all of them contain a valid URL.

How can I delete these comments automatically? I don't want to put them into the review queue; I just want to get rid of them completely. I don't care if a few legitimate comments get deleted in the process.

Share Improve this question asked May 22, 2019 at 9:55 Pikamander2Pikamander2 6086 silver badges20 bronze badges 1
  • I hope you can find another way than deleting legit comments that fill url field. What about trying an honey-trap instead, i.e. introduce a hidden field that might look like an url field to (dummy) bots and don't save the comments that have it filled? Other ways exists too. – birgire Commented May 22, 2019 at 10:36
Add a comment  | 

2 Answers 2

Reset to default 0

Well the best way is to use a antispam plugin like Aksimet. Other captcha plugins can be helpful too, you just have to look for the captcha keyword in wordpress repository.

If you want to do this manually, I can give you a hint. First of all, you need to know which action hook you want. I couldn't find an action that fires before the comment insertion, but comment_post runs after that.

Then you need to detect if your comment body contains a url, this SO question can be helpful with that. You can delete a comment with wp_delete_comment function.

You might need to add a plugin (or add your own comment filter) to 'count' the number of URLs in a comment before it is stored.

The Akismet plugin is a good one for catching a lot of spam. For one the sites that I managed, I had a similar problem. I ended up writing a plugin to allow for counting URLs (and lots of other customization of the comment form). It's called "FormSpammerTrap for Comments". It is fairly effective against someone that fills in the comment form.

It is not so effective for someone that uses CURL to directly post to the wp-comments.php page, bypassing the comment form. I haven't found a good way to block that yet; there aren't filters that happen in the proper place to block CURL commenters.

本文标签: functionsHow can I automatically delete comments that contain a URL