-
-
Save smhmic/d7cc344e577a26608316 to your computer and use it in GitHub Desktop.
wordpress - disable all rss and pingbacks and trackbacks on dev/staging sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( IS_DEV_SITE ) { | |
//Disable RSS Feeds functions | |
add_action('do_feed', array( $this, 'disabler_kill_rss' ), 1); | |
add_action('do_feed_rdf', array( $this, 'disabler_kill_rss' ), 1); | |
add_action('do_feed_rss', array( $this, 'disabler_kill_rss' ), 1); | |
add_action('do_feed_rss2', array( $this, 'disabler_kill_rss' ), 1); | |
add_action('do_feed_atom', array( $this, 'disabler_kill_rss' ), 1); | |
if(function_exists('disabler_kill_rss')) { | |
function disabler_kill_rss(){ | |
wp_die( _e("Feeds disabled.", '') ); | |
} | |
} | |
//Remove feed link from header | |
//remove_action( 'wp_head', 'feed_links_extra', 3 ); //Extra feeds such as category feeds | |
//remove_action( 'wp_head', 'feed_links', 2 ); // General feeds: Post and Comment Feed | |
// Disable X-Pingback HTTP Header. | |
add_filter('wp_headers', function($headers, $wp_query){ | |
if(isset($headers['X-Pingback'])){ | |
// Drop X-Pingback | |
unset($headers['X-Pingback']); | |
} | |
return $headers; | |
}, 11, 2); | |
// Disable XMLRPC by hijacking and blocking the option. | |
add_filter('pre_option_enable_xmlrpc', function($state){ | |
return '0'; // return $state; // To leave XMLRPC intact and drop just Pingback | |
}); | |
// Remove rsd_link from filters (<link rel="EditURI" />). | |
//add_action('wp', function(){ remove_action('wp_head', 'rsd_link'); }, 9); | |
// Hijack pingback_url for get_bloginfo (<link rel="pingback" />). | |
//add_filter('bloginfo_url', function($output, $property){return ($property == 'pingback_url') ? null : $output;}, 11, 2); | |
// Just disable pingback.ping functionality while leaving XMLRPC intact? | |
add_action('xmlrpc_call', function($method){ | |
if($method != 'pingback.ping') return; | |
wp_die( | |
'Pingback functionality is disabled on this Blog.', | |
'Pingback Disabled!', | |
array('response' => 403) | |
); | |
}); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment