The Love Shack

Yes, the B-52's. No, not pr0n. Sheesh!

01 Mar

WordPress + TBValidator Hacking

So I did a bit of hacking on my WP install today. I’ve been using the excellent TrackBack Validator Plugin to manage trackback spam on my blog. So far it’s done an AMAZING job. I have not yet had a single piece of TrackBack spam get through, nor have I had a single VALID TrackBack blocked.

The only problem I’ve had with it comes from the built-in WP notifications. I want to know when people comment on my blog. I also want to know when they leave a trackback. Unfortunately, the trackback notification seems to get sent out before the validator plugin has a chance to work its magic. This means that for every single blocked spam trackback, I still get an email telling me about it. In essence, I’m sending myself spam!

So today I figured I’d do something about it. After digging through the WP source, I came up with the following.

In <wp root dir>/wp-includes/comment.php:

Starting around line #405, you’ll find the following:

if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'])
wp_notify_postauthor($comment_ID, $commentdata['comment_type']);

Change that to:

if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] && $commentdata['comment_type'] != 'trackback')
wp_notify_postauthor($comment_ID, $commentdata['comment_type']);

So basically just add && $commentdata['comment_type'] != 'trackback') to the if. This serves to prevent WP from notifying me about trackbacks. But I still want to know about them. So I then edited the TBValidator plugin.

In <wp root dir>/wp-content/plugins/TBValidator/trackback_validator.php:

Starting around line #140, you’ll find the following:

if($tb_options['auto_approve'])
$wpdb->query("UPDATE $wpdb->comments SET comment_approved = '1' WHERE comment_ID = '$comment_ID'");

Immediately after that, add a line that reads:
wp_notify_postauthor($comment_ID, 'trackback');

This is basically offloading the job of notifying me about trackbacks into the TBValidator plugin.

So this is not elegant. It’s probably not a good idea either. You definitely shouldn’t do this to your blog unless you know what you’re doing. And if you DO know what you’re doing, you still shouldn’t do it because it’s a dirty hack. I’m sure there’s a much better way to handle this. But, it works for me and it took less time to make the change than it has to write this post about. :)

If anyone knows of a better solution, or if you decide to write a better solution, by all means let me know. I’ll install it in a heartbeat. This hack is going to break the next time I do a WP upgrade, but at least it’ll keep me from getting spammed by myself in the meantime. :)

Diggiciourati.This! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Slashdot
  • Technorati

3 Responses to “WordPress + TBValidator Hacking”

  1. 1
    fifers Says:

    I don’t think you are wrong. I’ve just spent quite some time trying to figure out a clean way to add this functionality to the system and your solution is the one that works!!

  2. 2
    Jon B. Says:

    This guy seems to have come up with a more elegant hack that does the same thing as yours, but only changes the plug-in code.

  3. 3
    The Must-Have Plugins I use on my WP Blogs | Niche Store Strategies Says:

    [...] Hack WP [...]

© 2010 The Love Shack

Design by NET-TEC -- Made free by Artikelverzeichnis and Bio-Branchenbuch