How to delete masses of WordPress Spam Comments in One Go
Monday, April 18th, 2011Recently a friend of mine asked me to look at his blog as he had a huge spam comment problem.
He’d been a regular blogger, then had a 6 month break while his little girl had been born, and came back to find he’d got 50,000 spam comments. Worst of all every time he went to the comments page there were that many that it timed out, so he couldn’t even delete them manually.
We took and look and found out his hosted WordPress install wouldn’t allow database access, nor file system access. Not good.
So we took a look at his potential plugin list - and “Hello Dolly” was right there waiting to be abused.
Of course we don’t want to name and shame the owner of the blog (let’s call him Greg to keep him anonymous - that’s ok isn’t it Greg?
) but he thankfully made a decision that made this a 10 minute change: he declared he wasn’t interested in keeping any comments.
Here’s what we did:
Go to Plugins, activate the Hello Dolly plugin. Go to plugin editor and then hack some additional code right into the plugin.
As this isn’t production code we’re going to abuse the “dolly_css” function. So look for “function dolly_css” then right underneath the { paste the following lines:
global $wpdb; Then click ok. The page will take a minute or so to refresh, but you should see a “**** DELETE FROM…” message at the top of the screen. If so then you’ve just deleted all comments on your blog (congratulations???).Once that’s complete you can either delete those lines, or leave them in place so every time you login and do admin stuff it’ll nuke all new comments - your call…
$wpdb->query("DELETE FROM $wpdb->comments");
print ("************** DELETE FROM $wpdb->comments");
$wpdb->query("OPTIMIZE TABLE $wpdb->comments");
Hope that hackery is helpful