-
-
Save groucho75/39cdb1adf633e1ad7866 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 | |
/* | |
* Plugin name: Test Rewrite Plugin | |
* Source: https://jeremyfelt.com/2015/07/17/flushing-rewrite-rules-in-wordpress-multisite-for-fun-and-profit/ | |
* */ | |
add_action( 'admin_bar_menu', 'toolbar_link_to_mypage', 999 ); | |
function toolbar_link_to_mypage( $wp_admin_bar ) { | |
global $wp; | |
$args = array( 'action' => 'flush-rules' ); | |
$self = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; | |
$current_url = add_query_arg( $args, $self ); | |
$args = array( | |
'id' => 'dk_flush_network_permalink', | |
'title' => 'Flush network permalink', | |
'href' => $current_url, | |
'meta' => array( 'class' => 'my-toolbar-page' ) | |
); | |
$wp_admin_bar->add_node( $args ); | |
} | |
add_action( 'init', 'dk_flushrules_init' ); | |
function dk_flushrules_init() { | |
if ( wp_is_large_network() ) { | |
return; | |
} | |
if ( isset( $_GET['action'] ) && $_GET['action'] == 'flush-rules' ) { | |
// ...and we're probably still friends. | |
$sites = wp_get_sites( array( 'network' => 1, 'limit' => 1000 ) ); | |
foreach ( $sites as $site ) { | |
switch_to_blog( $site['blog_id'] ); | |
delete_option( 'rewrite_rules' ); | |
restore_current_blog(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment