I just ran over a problem to properly use the count of external (meaning no relative or absolute links to my own blog) links on my blog for the Comment Moderation count Option.
It’s labeled Hold a comment in the queue if it contains [your number here] or more links. (A common characteristic of comment spam is a large number of hyperlinks.) on Settings -> Discussion in the WordPress Back-end. Screenshot:
I’m aware that currently it counts all links inkl. links to the blog and other comments (reported it here: #14681) but I can’t imagine that there isn’t a plugin or hack already available that properly corrects the count to only external links.
So my question is: Is there a plugin / hack that makes WordPress properly count only the external links in comments for it’s Moderation Options?
Haha, I actually figured out a way to do this. As a plugin, this should work.
I should add that I have not in any way tested this. But it should theoretically work.
I now wrote a complete plugin for this that offers the basic link counting interface for adding comments with wordpress 3.0. In addition to what John proposed I made some changes / addings based on tracing the hooks triggered by adding the comment as I wanted to get this only executed when a new comment is actually added.
I therefore did chose the
comment_text
instead of thepre_comment_content
hook. The rest is basically the same but some sanity checks were added so that it only get’s executed once and on adding a new comment only. An additional (but currently unimplemented) check would be to enable it only after thecomment_max_links
option has been read byget_option()
(thepre_option_comment_max_links
-hook), but as for the moment this did pass testing, I have not done it so far.The sourcecode can be viewed online in trac.
I’ll give the answer to John even I did not choose his suggestion as he posted the same principle here first.