403, 'back_link' => true]); } return $comment_data; } public function disableRecentComments() { unregister_widget('WP_Widget_Recent_Comments'); add_filter('show_recent_comments_widget_style', '__return_false'); } public function disableCommentsFeed() { if (is_comment_feed()) { wp_die(esc_html__('Comments are closed.', 'wp-extra'), '', ['response' => 403]); } } public function removeCommentAdminBar() { if (is_admin_bar_showing()) { remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); } } public function loadedDisableComments() { $post_types = get_post_types(['public' => true], 'names'); if (!empty($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_filter('comments_array', '__return_empty_array', 20); add_filter('comments_open', '__return_false', 20); add_filter('pings_open', '__return_false', 20); if (is_admin()) { add_action('admin_menu', [$this, 'removeCommentsMenu'], 9999); add_action('admin_print_styles-index.php', [$this, 'hideDashboardComments']); add_action('admin_print_styles-profile.php', [$this, 'hideProfileComments']); add_action('wp_dashboard_setup', [$this, 'removeRecentCommentsMeta']); add_filter('pre_option_default_pingback_flag', '__return_zero'); } else { add_filter('comments_template', [$this, 'BlankCommentsTemplate'], 20); wp_deregister_script('comment-reply'); add_filter('feed_links_show_comments_feed', '__return_false'); } } public function removeCommentsMenu() { global $pagenow; remove_menu_page('edit-comments.php'); remove_submenu_page('options-general.php', 'options-discussion.php'); if ($pagenow === 'comment.php' || $pagenow === 'edit-comments.php' || $pagenow === 'options-discussion.php') { wp_die(esc_html__('Comments are closed.', 'wp-extra'), '', ['response' => 403]); } } public function hideDashboardComments() { echo ''; } public function hideProfileComments() { echo ''; } public function removeRecentCommentsMeta() { remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); } public function BlankCommentsTemplate() { return __DIR__ . '/empty-comments.php'; } public function filter_media_comment_status($open, $post_id) { $post = get_post($post_id); if ($post && $post->post_type === 'attachment') { return false; } return $open; } public function hide_media_comments_column($columns) { if (isset($columns['comments'])) { unset($columns['comments']); } return $columns; } }