Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Created April 23, 2017 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2ndkauboy/6f72df01dde65b78a6c71c50d7dc4774 to your computer and use it in GitHub Desktop.
Save 2ndkauboy/6f72df01dde65b78a6c71c50d7dc4774 to your computer and use it in GitHub Desktop.
<?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