Stopping WordPress media attachments comment spam

I just had my monthly look at the comments spam queue and was baffled by the amount of spam-comments on WordPress attachments. WordPress, surprisingly, has no option to disable comments on media, so based on information in this codex page about the comments_open function, I quickly assembled a plugin to stop comments on items in the media gallery altogether. The code (which can also be added in functions.php instead of going into a plugin):

<?php
/*
Plugin Name: No Media Comments
Author: Frank Goossens (futtta)
Plugin URI: http://blog.futtta.be/
Author URI: http://blog.futtta.be/
Description: Stop comments on media attachments
Version: 0.1
*/

add_filter( 'comments_open', 'noMediaComments', 10, 2 );

function noMediaComments( $open, $post_id ) {
$post = get_post( $post_id );
if ( 'attachment' == $post->post_type )
$open = false;
return $open;
}
?>

After throwing that at my server and seeing it worked, I realized there had to be a plugin for this and I indeed found Disable Comments and Comment Control in the wordpress.org plugin repository. Both plugins are by the same author and are only slightly different in scope really. So if you want to stop the comment spam on attached images on your WordPress blog, you’ve got several options. But shouldn’t this be tackled in WordPress core instead, really?

4 thoughts on “Stopping WordPress media attachments comment spam

  1. frank Post author

    Just got confirmation that with “Comment Control” you can now choose between disabling comments if they’re disabled on the parent, or disabling them for all attachments alltogether, so that seems to be the plugin to install to solve this WordPress bug.

    Reply
  2. Mario

    Thanks! I have had the very same problem. This works great!
    I personally prefer to add filter to functions.php. Plugins are great, but one have no (or limited) control over the code. Your solution is is perfect and simple. Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *