Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function wpse15750_comment_check( $id ){
  2. if( get_post_type( $id ) == 'attachment' )
  3. exit;
  4. }
  5.  
  6. add_action( 'pre_comment_on_post', 'wpse15750_comment_check' );
  7.  
  8. function wpse15750_comments_closed( $open, $id ){
  9. if( get_post_type( $id ) == 'attachment' )
  10. return false;
  11. return $open;
  12. }
  13.  
  14. add_action( 'pre_comment_on_post', 'wpse15750_comments_closed', 10, 2 );
  15.  
  16. global $wpdb;
  17. $wpdb->update( $wpdb->posts, array( 'comment_status' => 'closed' ), array( 'post_type' => 'attachments', 'comment_status' => 'open' ) );
  18.  
  19. function wpse15750_no_attachment_comments( $data ){
  20. if( $data['post_type'] == 'attachment' )
  21. $data['comment_status'] = 'closed';
  22. return $data;
  23. }
  24.  
  25. add_filter( 'wp_insert_post_data', 'wpse15750_no_attachment_comments' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement