meyerweb.com

Skip to: site navigation/presentation
Skip to: Thoughts From Eric

Wanted: Akismet Warning Plugin

Okay, with my WordPress install mostly stabilized (I even fixed the archive paging!), I have a LazyWeb request for all you WP hackers.  What I want is very simple:  a WP 2.x plugin that notifies a commenter when their comment has been condemned to the Akismet queue.  I’ve had a few legitimate comments suffer that fate, and I imagine there have been more I never saw, so it’s something I’d really like to have (and something I think other people would also find useful).

At the most basic level, all I really want is for the plugin to die() with a message telling the commenter that their comment has been Akismetted and that they should contact the site administrator about it if they’re legitimate.  If instead of dying it gave that message upon returning them to the post on which they commented, the way “Your message is awaiting moderation” works, that would be extra-cool.  Either way, it obviously only fires if the comment has been marked spam.

I’m guessing this is a pretty simple plugin to write.  I did attempt to write it myself, but was spectacularly unsuccessful in the attempt.  The really frustrating part is that I think I got close to making it work, but, in the end, failed badly.  Then I asked for plugin help on IRC, but nobody noticed.  So I’m throwing the request out to the audience here to see what y’all can do.  Thanks to anyone who can help!

Update 5 Feb 07: Mark Jaquith has come through with Antispam Collateral Condolences, a plugin that does exactly what I requested.  It can put up the warning either as a JavaScript alert box, or a message embedded in the page upon returning them to the post on which they commented.  Totally, completely awesome.  You rock, Mark!

12 Responses»

    • #1
    • Comment
    • Mon 5 Feb 2007
    • 0612
    Alexander Graf wrote in to say...

    Well, if you don’t mind hacking the Akismet Plugin itself, there is a function akismet_auto_check_comment() which preprocesses the comment.

    In line 204 through 214, the spam comment gets put in the spam queue. In line 212 you could add a redirect yourself which notifies the user of bad things happening.

    Hope that helps. I doubt you could make a plugin that notifies the user without hacking the Akismet Plugin itself. Akismet adds itself as the first action in the comment preprocessing queue. If you could put a custom action before that, you’d probably be best off by storing the comment in a session, letting Akismet do it’s job and on the next page check whether the comment has been actually posted or not. Akismet doesn’t exactly provide any API hooks from what I can see.

    • #2
    • Comment
    • Mon 5 Feb 2007
    • 0716
    Gerard wrote in to say...

    I’d be a tiny bit worried that you’d effectively be sending a confirmation email to the spammers as well. Wouldn’t you be waving a big flag saying “Spam Me!!!”

    With the amount of comment spam these days, I check my moderation queues less and less. Comment spam really increases the cost of blog ownership, and if you don’t start to ignore it, you’ll spend your life in moderation hell!

    • #3
    • Comment
    • Mon 5 Feb 2007
    • 0909
    Amber wrote in to say...

    Not sure how it works with the WordPress plug-in specifically, but I use Akismet on my home-grown blog and it was simply a matter of adding what I wanted to the exit() line in the PHP code. I imagine you could do the same?

    Mine just looks like this:


    if($akismet->isSpam()) {
    // Save the suspicious comment in the spam table
    /*** Insert query goes here ***/

    // Delete the buffer
    ob_end_clean();
    exit("Akismet thinks your comment is spam. E-mail me (amber at tangerinecs dot com) if that's not the case.");
    }

    • #4
    • Comment
    • Mon 5 Feb 2007
    • 1258
    Tom Johnson wrote in to say...

    I’m interested in the same plugin/hack. If you find something that works, please let me know.

    • #5
    • Comment
    • Mon 5 Feb 2007
    • 1342
    Eric Meyer wrote in to say...

    It does help, Alexander—thanks! I’m wondering if a redirect or a die at that point is a good idea, though. It would prevent the next few lines from executing, and those look like cleanup actions. I think. Then again, I’m confused by lines 213-214, which invoke a die under certain conditions, only I don’t know how likely it is to see those conditions.

    If the die on 213 isn’t often triggered, then I’d probably drop a conditional right after line 216 (akismet_delete_old();) in order to make this happen. I think a plain old die would be good enough for me at the moment, considering that redirects are kind of dark-gray magic to me. (I get the general principle, but the specifics of their handling in WP bedevil me.)

    Gerard, I don’t think this would be that big a flag, since I’m not sending anyone any e-mail. I’m just throwing what is, in effect, an error page back at the web browser. I suppose that I could eventually get fancy and return an HTTP error code and page, maybe a 417.

    Sounds like a generally good idea, Amber, except the way the Akismet WP plugin is written, there are a few exits scattered about, and identifying just the right one is a bit tricky for me. I think I’ll probably do something based on Alexander’s suggestion.

    • #6
    • Comment
    • Mon 5 Feb 2007
    • 1436
    Mark Jaquith wrote in to say...

    Try this!

    That was actually the sole reason that I put that hook (comment_post_redirect) in there… just never got around to writing the plugin to use it.

    Default notification is JS alert() because that’ll work most generally, but I included an alternative notification method that you can use if your theme has the comment_form hook.

    • #7
    • Comment
    • Mon 5 Feb 2007
    • 1451
    Eric Meyer wrote in to say...

    Awesome, Mark! Thank you! I just tested it with some choice bits from my Akismet queue and it works great. I went with the JS popup method, since it’s the most obvious. I bow down before your PHP and WP sagacity.

    • #8
    • Comment
    • Mon 5 Feb 2007
    • 1556
    Eric Meyer wrote in to say...

    Just a quick test here to see if I get the warning on a legitimate comment.

    • #9
    • Comment
    • Mon 5 Feb 2007
    • 1557
    Eric Meyer wrote in to say...

    …and another test of the plugin.

    • #10
    • Comment
    • Tue 6 Feb 2007
    • 0242
    Alexander Graf wrote in to say...

    Nice Mark, I didn’t think this was possible. Clean solution, I like it.

    • #11
    • Pingback
    • Wed 28 Feb 2007
    • 0415
    Received from XiAP Design: Web & Graphic design | WordPress & MacOSX Themes » Antispam Collateral Condolences

    [...] is an interesting plugin I found by chance in reading Eric Meyer’s blog. So what does it do? This plugin will notify commenters when their comments are [...]

    • #12
    • Pingback
    • Fri 24 Sep 2010
    • 2023
    Received from Todays Spammers - Page 2 - Net Builders

    [...] are too many spam comments to justify the time it takes to review the spam bin. I came across a solution which is to add a hack to the exit() line in the PHP code. This would notify the commenter that [...]

Leave a Comment

Line and paragraph breaks automatic, e-mail address required but never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Remember to encode character entities if you're posting markup examples! Management reserves the right to edit or remove any comment—especially those that are abusive, irrelevant to the topic at hand, or made by anonymous posters—although honestly, most edits are a matter of fixing mangled markup. Thus the note about encoding your entities. If you're satisfied with what you've written, then go ahead...


February 2007
SMTWTFS
January March
 123
45678910
11121314151617
18192021222324
25262728  

Sidestep

Feeds

Extras