Enable comments for post with comments meta box removed

Here’s what I ended up with. For limited access users, I set comments on when the post guid is empty. Otherwise, I completely remove the comment_status field for those users. That defaults new posts to comments enabled, prevents limited access user edits from switching them off, while allowing admins to override the setting on/off.

add_filter( 'wp_insert_post_data', 'handle_comments_setting' );
function handle_comments_setting( $data ) {
  if ( current_user_can( 'limited_role_name' )) {
    if ( $data['guid'] == '') {
      //Default new posts to allow comments
      $data['comment_status'] = "open";        
    } else {
      //Otherwise ignore comment setting for community_member role users
      unset($data['comment_status']);
    }
  }
  return $data;
}

Leave a Comment