-
-
Save 2ndkauboy/6f72df01dde65b78a6c71c50d7dc4774 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* 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