Đóng gói thành plugin hoặc thêm vào file function
<?php
/**
* Plugin Name: WPE Disable All Comments
* Description: Completely disables comments and related features in WordPress, including via XML-RPC and REST API.
*/
// Disable Comments Completely (Admin & Frontend)
function disable_all_comments() {
// Disable comments for all post types
foreach (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');
}
}
// Remove dashboard comments metabox
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
// Disable XML-RPC comments
add_filter('xmlrpc_methods', function($methods) {
unset($methods['wp.newComment']);
return $methods;
});
// Disable REST API comments
add_filter('rest_endpoints', function($endpoints){
if (isset($endpoints['/wp/v2/comments'])) {
unset($endpoints['/wp/v2/comments']);
}
return $endpoints;
});
}
add_action('admin_init', 'disable_all_comments');
// Redirect From Comments Page & Remove Menu Item
function disable_comments_admin_menu() {
global $pagenow;
// Redirect from comments page if accessed directly
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
// Remove the menu item
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'disable_comments_admin_menu');
// Remove Comments Links from Admin Bar
function disable_comments_admin_bar($wp_admin_bar) {
$wp_admin_bar->remove_node('comments');
}
add_action('admin_bar_menu', 'disable_comments_admin_bar', 999);
// Close Comments and Hide Existing (Front-End)
add_filter('comments_open', '__return_false', PHP_INT_MAX); // Highest priority
add_filter('pings_open', '__return_false', PHP_INT_MAX);
add_filter('comments_array', '__return_empty_array', PHP_INT_MAX);