WordPressのコメント機能を全部無効化

WordPressに意地悪してくる人が増えているので、とりあえずコメント対策したい!って事で、コメント関連の機能を全部無効化してくれるコード。
functions.phpに書くよ。


// コメント機能を完全に無効化
add_action('admin_init', function () {
    // 投稿タイプからコメントサポートを削除
    $post_types = get_post_types();
    foreach ($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');
        }
    }
});

// コメント関連のメニューを非表示
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});

// コメント関連のウィジェットを無効化
add_action('widgets_init', function () {
    unregister_widget('WP_Widget_Recent_Comments');
});

// 管理バーからコメント項目を削除
add_action('admin_bar_menu', function ($wp_admin_bar) {
    $wp_admin_bar->remove_node('comments');
}, 999);
にほんブログ村 IT技術ブログへ にほんブログ村 IT技術ブログ WordPressへ にほんブログ村 IT技術ブログ Webサイト構築へ

投稿者: おーあえ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください