get_post_types() as $post_type ) { if ( post_type_supports( $post_type, 'comments' ) ) { remove_post_type_support( $post_type, 'comments' ); remove_post_type_support( $post_type, 'trackbacks' ); } } } /** * Close comments on the front end. * * @param bool $open Whether comments are open. * @param int $post_id Post ID. * @return bool */ public function close_comments( $open, $post_id ) { $post = get_post( $post_id ); if ( $post && in_array( $post->post_type, $this->get_post_types(), true ) ) { return false; } return $open; } /** * Hide existing comments on the front end. * * @param array $comments Comments array. * @param int $post_id Post ID. * @return array */ public function hide_comments( $comments, $post_id ) { $post = get_post( $post_id ); if ( $post && in_array( $post->post_type, $this->get_post_types(), true ) ) { return array(); } return $comments; } /** * Remove Comments admin menu when all types are disabled. * * @return void */ public function remove_comments_menu() { remove_menu_page( 'edit-comments.php' ); } /** * Remove comments from admin bar. * * @return void */ public function remove_admin_bar_comments() { global $wp_admin_bar; if ( $wp_admin_bar ) { $wp_admin_bar->remove_node( 'comments' ); } } /** * Get configured post types. * * @return string[] */ private function get_post_types() { $settings = EDMINBOOST_Settings::get_feature_settings( $this->get_id() ); $types = isset( $settings['post_types'] ) && is_array( $settings['post_types'] ) ? $settings['post_types'] : array(); return ! empty( $types ) ? $types : array( 'post' ); } }