Skip to content

Instantly share code, notes, and snippets.

@jubstuff
Last active November 17, 2015 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jubstuff/089bf475c19d783bf48a to your computer and use it in GitHub Desktop.
Save jubstuff/089bf475c19d783bf48a to your computer and use it in GitHub Desktop.
<?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