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.








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!!
April 1st, 2007 at 8:31 amThis 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.
June 6th, 2007 at 8:54 am[...] Hack WP [...]
July 31st, 2008 at 11:56 am