by Ron

switch themes with a filter

A while back someone asked on twitter if there were an easy way to change all sites in a network to a different one. Yes, that’s fairly easy to do with a simple plugin that you put in the mu-plugins* folder.

[code]function ra_switch_to_twentyten() {
global $wpdb;

$last_id = get_site_option( ‘ra_twentyten’, 1 );
if( $last_id < 0 )
return;

$next_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE blog_id > %d LIMIT 1", $last_id ) );
if( !$next_id ) {
update_site_option( ‘ra_twentyten’, -1 );
return;
}
switch_to_blog( $next_id );
if( ‘default’ == get_option( ‘template’ ) ) {
update_option( ‘template’, ‘twentyten’ );
update_option( ‘stylesheet’, ‘twentyten’ );
update_option( ‘current_theme’, ” );
}
restore_current_blog();

update_site_option( ‘ra_twentyten’, $next_id );
}
add_action( ‘init’, ‘ra_switch_to_twentyten’ );[/code]

You need to leave this in the mu-plugins folder long enough for the plugin to cycle through all the blogs in the network. Then the code can be removed. In the above case, every site would eventually be switched to Twenty Ten.

* See What is the mu-plugins folder if you are unfamiliar.

#filters#mu-plugins#Themes

Comments

  1. Dan

    Awesome. This will save me a ton of time and work 🙂

Leave a Reply

Your email address will not be published / Required fields are marked *