Skip to content

Instantly share code, notes, and snippets.

@MarZab
Last active August 29, 2015 14:16
Show Gist options
  • Save MarZab/a582488418f730657fa6 to your computer and use it in GitHub Desktop.
Save MarZab/a582488418f730657fa6 to your computer and use it in GitHub Desktop.
Disable WordPress Feed Comments
<?php
/*
Plugin Name: Disable Feed Comments
Description: Disable commenting, comment feeds
Author: Marko Zabreznik
Version: 0.1
Author URI: http://zabreznik.net
*/
// if a comments template is requested, quit
function disable_feed_comments_disable_feed ( $for_comments ) {
if ($for_comments) {
wp_die( __( 'ERROR: Comments are disabled.' ), '', array( 'response' => 404 ) );
}
}
add_action( 'do_feed_rdf', 'disable_feed_comments_disable_feed', 9, 1 );
add_action( 'do_feed_rss', 'disable_feed_comments_disable_feed', 9, 1 );
add_action( 'do_feed_rss2', 'disable_feed_comments_disable_feed', 9, 1 );
add_action( 'do_feed_atom', 'disable_feed_comments_disable_feed', 9, 1 );
// remove all links to the comments feed
function disable_feed_comments_remove_links ( $link ) {
return;
}
add_filter('post_comments_feed_link', 'disable_feed_comments_remove_links', 10, 1);
add_filter('comments_link_feed', 'disable_feed_comments_remove_links', 10, 1);
add_filter('comment_link', 'disable_feed_comments_remove_links', 10, 1);
// dissable comments count within RSS
function disable_feed_comments_remove_count ( $count, $post ) {
if (is_feed()) {
return;
}
}
add_filter('get_comments_number', 'disable_feed_comments_remove_count', 10, 2);
/* disable frontend comments
// disable new comments
add_filter( 'comments_open', '__return_false' );
// disable posting comments
add_action('pre_comment_on_post', 'no_wp_comments');
function no_wp_comments() {
wp_die( __( 'ERROR: Comments are disabled.' ), '', array( 'response' => 404 ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment