1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
function ds_flush_rewrites() {
  global $wpdb, $wp_rewrite;

  $sites = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs"));

  foreach ( $sites as $site ) {     
    $url = get_site_url($site->blog_id);

    switch_to_blog($site->blog_id);
    $wp_rewrite->flush_rules();
    restore_current_blog();
  }  
}
add_action( 'wp_dashboard_setup', 'ds_flush_rewrites' );
?>