Limiting spam comments on posts or images (wordpress attachments)

Last updated on June 25th, 2014 at 01:47 pm

Spammers seem to have found a way of sending spam comments to your wordpress images – and there doesn’t appear (as yet) to be a way to default the options on attachments to “No Comments” or “No Pings”.

so – I wrote a quick and easy script to drop into the root folder of your wordpress blog – calling it from the browser will close all pings and comments:

$strict = 'Y';
if ("$strict" == "Y") {
$sql1="UPDATE wp_posts SET ping_status = replace(ping_status, 'open', 'closed');";
$sql2="UPDATE wp_posts SET comment_status = replace(comment_status, 'open', 'closed');";
} else {
$sql1="UPDATE wp_posts SET ping_status = replace(ping_status, 'open', 'closed') WHERE post_type = 'attachment';";
$sql2="UPDATE wp_posts SET comment_status = replace(comment_status, 'open', 'closed') WHERE post_type = 'attachment';";
// Connect to MySQL - use the wordpress built-in function - it is easier
echo 'About to update ... ['.$sql1.']<br>';
$result1 = mysql_query($sql1) or die(mysql_error());
echo '['.$result1.']<br>';
echo 'About to update ... ['.$sql2.']<br>';
$result2 = mysql_query($sql2) or die(mysql_error());
echo '['.$result2.']<br>';
echo '<P>We are done - exiting...</P>';

Once you have dropped this script in the root of your wordpress blog, you can close comments and pings to your site by bringing up the script in your browser window:

(assuming you saved it as lockdownblog.php)