'disable_comments', 'title' => 'Disable comments site-wide', 'desc' => 'Close comments and remove the comment menu, widget and admin bar item', 'icon' => 'x', 'risk' => 'recommended', 'level' => 'standard', 'audience' => 'business', 'priority' => 7, 'benefit' => 'If your site does not use comments, this closes the comment form that spam bots target and removes comment screens from the admin.', 'help' => 'Closes comments and pingbacks on all post types, hides existing comments on the site, and removes the Comments menu, the admin bar item and the Recent Comments widget. Existing comments stay in the database and show again if you turn this off. WooCommerce product reviews are kept; you can turn those off in WooCommerce → Settings → Products.', 'before' => 'Comment forms open to spam bots', 'after' => 'Comments closed and hidden; comment screens removed from the admin.', 'detect' => function () { // Check if there are any approved comments. $count = wp_count_comments(); $has_comments = ( $count->approved > 0 ); // Check if comments are already disabled by theme/settings. $open = get_option( 'default_comment_status' ) === 'open'; if ( ! $open && ! $has_comments ) { return array( 'detected' => false, 'message' => 'Comments already disabled in Settings', 'safe' => true, ); } if ( $has_comments ) { return array( 'detected' => true, 'message' => $count->approved . ' existing comments — disabling hides them from frontend', 'safe' => true, ); } return array( 'detected' => true, 'message' => 'Comments are open but no approved comments exist', 'safe' => true, ); }, 'callback' => function () { // Preserve WooCommerce product reviews: the 'product' post type is // WC's review surface and disabling it silently would break storefronts. $is_wc_product = function ( $post_id ) { return class_exists( 'WooCommerce' ) && 'product' === get_post_type( $post_id ); }; add_filter( 'comments_open', function ( $open, $post_id ) use ( $is_wc_product ) { return $is_wc_product( $post_id ) ? $open : false; }, 999, 2 ); add_filter( 'pings_open', function ( $open, $post_id ) use ( $is_wc_product ) { return $is_wc_product( $post_id ) ? $open : false; }, 999, 2 ); add_filter( 'comments_array', function ( $comments, $post_id ) use ( $is_wc_product ) { return $is_wc_product( $post_id ) ? $comments : array(); }, 999, 2 ); add_action( 'admin_menu', function () { remove_menu_page( 'edit-comments.php' ); }, 999 ); add_action( 'admin_bar_menu', function ( $b ) { $b->remove_node( 'comments' ); }, 999 ); add_action( 'init', function () { $wc_active = class_exists( 'WooCommerce' ); foreach ( get_post_types() as $pt ) { if ( $wc_active && 'product' === $pt ) { continue; } if ( post_type_supports( $pt, 'comments' ) ) { remove_post_type_support( $pt, 'comments' ); remove_post_type_support( $pt, 'trackbacks' ); } } }, 999 ); add_action( 'widgets_init', function () { unregister_widget( 'WP_Widget_Recent_Comments' ); } ); add_action( 'admin_init', function () { remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); global $pagenow; if ( 'edit-comments.php' === $pagenow ) { wp_safe_redirect( admin_url() ); exit; } } ); }, );