Skip to content

Instantly share code, notes, and snippets.

@zeropointdevelopment
Created December 27, 2013 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeropointdevelopment/8143140 to your computer and use it in GitHub Desktop.
Save zeropointdevelopment/8143140 to your computer and use it in GitHub Desktop.
[WordPress] Code from our blog post Stopping WordPress Media Attachment Comment Spamming - http://www.limecanvas.com/stopping-wordpress-media-attachment-comment-spamming/
/** Stop comments being used on Media Files **/
add_filter( 'comments_open', 'stopMediaComments', 10, 2 );
function stopMediaComments( $open, $post_id ) {
$post = get_post( $post_id );
if ( 'attachment' == $post->post_type )
$open = false;
return $open;
}
/** This is used to get around non-native WordPress plugins **/
add_filter('get_header', 'lcTurnCommentsOff');
function lcTurnCommentsOff(){
global $post;
if ( 'attachment' == $post->post_type )
$post->comment_status="closed";
}
@lengxuebingfeng
Copy link

hi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment