After examining a customer’s 150,000+ row wp_comments table at work yesterday, I realized that they’d managed to let WordPress approve a massive amount of spam. Since there was no way I was going back thru all of that by hand, I knew that I had to come up with something clever.
Fortunately, running your already approved comments thru Akismet is pretty easy. Well, that might be a bit disingenuous. It’s easy for the geeky types that are comfortable with the MySQL command line and raw queries. So if you manage to fall into that category, feel free to give this a go…
- Fire up your favorite MySQL management tool and feed the following command to your WordPress database:
update wp_comments set comment_approved=’0′ where comment_approved=’1′;
This tells WordPress to take any comment already flagged as “approved” and set it to “pending”.
- Visit “Comments” in your WordPress dashboard. You should notice that you’ve got a bunch of comments under “Pending”.
- So long as you have Akismet installed, you should have a button marked “Check for Spam”. Click it.
- This step is going to require some patience. You’ll need to wait while Akismet does its thing. This means chilling out while watching your browser’s “loading” animation spin for a little bit.
- If you have a lot of comments — and we’re talking about thousands — you might run into your server’s PHP execution timeout. You’ll know this has happened when you see either a 404 or aren’t redirected back to the “Comments” page. Don’t panic.
- If you run into a timeout, simply press “Back” in your browser and click “Check for Spam” again. When the number of comments listed under “Pending” stops decreasing, you’re really close to being done!
- Go back to the MySQL management tool you used in step one and give it one last command:
update wp_comments set comment_approved=’1′ where comment_approved=’0′;
This takes the “pending” comments and sets them back to “approved”.
- Congratulations! Your comments are now much tidier and you’ve helped stamp out the spammers who’ve gotten past your defenses. Since your copy of Akismet has just done a bunch of heavy lifting, you might want to consider giving it a bit of a rest by implementing something like Hashcash as your first line of defense. When it comes to fighting spam, they’re a great combination.
If I can hack together a way to work around the PHP execution timeout issue, I’ll do my best to make this into a simple to use plugin. Since I’ve got a lot on my plate right now, I’d prefer it if the lazyweb could beat me to getting that done. Any takers?