Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Multisite No Self Ping
*
* @package MultisiteNoSelfPing
* @author Bernhard Kau
* @license GPLv3
*
* @wordpress-plugin
* Plugin Name: Multisite No Self Ping
* Plugin URI: https://kau-boys.de
* Description: Disables self pings for all blogs on a multisite.
* Version: 0.1
* Author: Bernhard Kau
* Author URI: https://kau-boys.de
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*/
/**
* Prevent pings to multisite links
*
* @param array $links The array of links to ping
*/
function multisite_no_self_ping( &$links ) {
$sites = get_sites();
$site_urls = array();
foreach ( $sites as $site ) {
$site_urls[] = get_home_url( $site->blog_id );
}
foreach ( $links as $key => $link ) {
foreach ( $site_urls as $site_url ) {
if ( 0 === strpos( $link, $site_url ) ) {
unset( $links[ $key ] );
}
}
}
}
add_action( 'pre_ping', 'multisite_no_self_ping' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.