𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /home/blackpussy06/public_html/bossini.com.tw/wp-content/mu-plugins//wpmm-disable-comments.php
<?php
/**
* Plugin Name: wp-MM-System Disable Comments
* Description: Centrally disables WordPress comments, pingbacks and REST comment writes.
* Version: 1.0.1
*/
if (!defined('ABSPATH')) { exit; }
function wpmm_comments_disabled_false() { return false; }
function wpmm_comments_disabled_empty($comments) { return array(); }
add_filter('comments_open', 'wpmm_comments_disabled_false', PHP_INT_MAX, 2);
add_filter('pings_open', 'wpmm_comments_disabled_false', PHP_INT_MAX, 2);
add_filter('comments_array', 'wpmm_comments_disabled_empty', PHP_INT_MAX, 2);
add_filter('get_comments_number', '__return_zero', PHP_INT_MAX, 2);
add_filter('pre_option_default_comment_status', function () { return 'closed'; }, PHP_INT_MAX);
add_filter('pre_option_default_ping_status', function () { return 'closed'; }, PHP_INT_MAX);
add_action('init', function () {
foreach (get_post_types(array(), 'names') as $type) {
if (post_type_supports($type, 'comments')) { remove_post_type_support($type, 'comments'); }
if (post_type_supports($type, 'trackbacks')) { remove_post_type_support($type, 'trackbacks'); }
}
if (get_option('default_comment_status') !== 'closed') { update_option('default_comment_status', 'closed'); }
if (get_option('default_ping_status') !== 'closed') { update_option('default_ping_status', 'closed'); }
}, 0);
add_filter('wp_insert_post_data', function ($data, $postarr) {
$data['comment_status'] = 'closed';
$data['ping_status'] = 'closed';
return $data;
}, PHP_INT_MAX, 2);
add_filter('xmlrpc_methods', function ($methods) {
unset($methods['pingback.ping'], $methods['pingback.extensions.getPingbacks']);
return $methods;
});
add_filter('wp_headers', function ($headers) {
unset($headers['X-Pingback']);
return $headers;
});
add_filter('rest_pre_dispatch', function ($result, $server, $request) {
$route = $request->get_route();
if (preg_match('#^/wp/v2/comments(?:/|$)#', $route) && strtoupper($request->get_method()) !== 'GET') {
return new WP_Error('wpmm_comments_disabled', '本站留言功能已停用。', array('status' => 403));
}
return $result;
}, 10, 3);
add_action('pre_comment_on_post', function () {
wp_die('本站留言功能已停用。', '留言已停用', array('response' => 403));
}, PHP_INT_MAX);