The MU forums have moved to WordPress.org

switch_theme not working (5 posts)

  1. svdv
    Member
    Posted 14 years ago #

    I'm trying to set a theme after blog creation but switch_theme doesn't do anything. I use the wpmu_new_blog hook:

    add_action ('wpmu_new_blog', 'wpmu_blogsetup');
    
    function wpmu_blogsetup($blog_id) {
    	global $wp_query, $wpdb;
    
    	switch_to_blog($blog_id);
    
    	switch_theme('ll-event', 'll-event');
    	//update_blog_option($blog_id, 'template', 'll-event');
    	//update_blog_option($blog_id, 'stylesheet', 'll-event');
    	//delete_blog_option($blog_id, 'current_theme');
    
    	echo 'blog_id: ' . $blog_id;
    	echo 'get_template: ' . get_template();
    	echo 'get_stylesheet: ' . get_stylesheet();
    	echo 'get_current_theme: ' . get_current_theme();
    
    	die(); //for debugging reasons...
    
    }

    I also tried setting the theme manually using update_blog_option. The theme is not set, the output:

    blog_id: 42
    get_template: default
    get_stylesheet: default
    get_current_theme: WordPress Default

    What do I do wrong? When I set it with wp-admin it works.

  2. svdv
    Member
    Posted 14 years ago #

    Did some more Googling and this led to the solution:

    http://wordpress.org/support/topic/373030?replies=14#post-1447768

    Code:

    switch_to_blog($blog_id);
    update_blog_option($blog_id, 'template', 'loveland-event');
    update_blog_option($blog_id, 'stylesheet', 'loveland-event');
    delete_blog_option($blog_id, 'current_theme');
    wp_cache_delete('template', 'options');
    wp_cache_delete('stylesheet', 'options');
  3. DeannaS
    Member
    Posted 14 years ago #

    Yah, it seems like there's a bug in 2.9.2's switch theme code. Glad you found the solution.

  4. bobmajdakjr
    Member
    Posted 14 years ago #

    both of these, switch_theme and svdv's solution, do absolutely nothing for me - for me the trick was adding the fourth parametre "true" to the update_blog_option calls to force refreshing *shrug*

  5. greg.hellings
    Member
    Posted 14 years ago #

    None of the above works for me. Is this really a bug in 2.9.2? It seems like a pretty significant bug that could do with some fixing, or at least prominently visible work-arounds being available!

About this Topic

  • Started 14 years ago by svdv
  • Latest reply from greg.hellings