Blocking Trackback Spam Using WordPress 1.2

1 minute read

Every day I get a number of trackback spams that I have to delete manually as part of my morning email processing ritual.

This morning I got tired of doing so, and put a quick hack into WordPress to block trackbacks which contain the most common words. This took just a minute, and I think it will make a difference.

The code works for WordPress 1.2 (I have not had the time to upgrade to 1.5 yet). The modifications are in wp-trackback.php . Simply open up this file, and add the new lines as shown in bold, below. This is at line 25 in my copy of the code.

…… if \(empty\(\$title) && empty\(\$tb\_url) && empty\(\$blog\_name)) { // If it doesn’t look like a trackback at all… header\(‘Location: ‘ . get\_permalink\(\$tb\_id)); } <span style=\"font-weight:bold;\"> // Trackback spam if \(\(strstr\(\$excerpt, \"casino\") !== false) \|| \(strstr\(\$excerpt, \"poker\") !== false) \|| \(strstr\(\$excerpt, \"phentermine\") !== false)) { header\(\"Location: \" . get\_permalink\(\$tb\_id)); } </span> if \(\(strlen\(”.\$tb\_id)) && \(empty\(\$\_GET\['\_\_mode'])) && \(strlen\(”.\$tb\_url))) { ……

Be careful not to disturb anything else, and save the file. That’s all you need to do. If new types of trackbacks (with different subjects) start to appear, isolate the appropriate word and plug it in. The safest way to do this is to copy the line which contains the test for ‘poker’, paste it immediately following the original line, and adding the new “bad word”.