<?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' );
?>