WordPress 彻底关闭禁用评论功能

// 禁用默认的评论功能
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);

// 移除评论相关的功能和显示
add_action('admin_menu', 'remove_comment_menu');
add_action('wp_before_admin_bar_render', 'remove_comment_admin_bar');
add_action('widgets_init', 'remove_recent_comments_style');
add_filter('comments_array', 'remove_comments');
add_action('admin_init', 'disable_comment_dashboard');
add_action('do_feed_rss2_comments', 'disable_comment_feed');
add_action('wp_enqueue_scripts', 'disable_comment_embed');

function remove_comment_menu() {
    remove_menu_page('edit-comments.php');
}

function remove_comment_admin_bar() {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
}

function remove_recent_comments_style() {
    global $wp_widget_factory;
    remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
}

function remove_comments($comments) {
    $comments = array();
    return $comments;
}

function disable_comment_dashboard() {
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}

function disable_comment_feed() {
    wp_die(__('Comments are closed.'), '', array('response' => 403));
}

function disable_comment_embed() {
    if (is_singular() && comments_open() && get_option('thread_comments')) {
        wp_die('Comments are closed.');
    }
}