Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I enable specific themes and plugins for new blogs that have been created with wpmu_create_blog? I'd like to set the themes and plugins in code rather than having a person manually set them in the network administration section (i.e. not in http://domain/wp-admin/network/site-themes.php?id=xx).

Thanks!

Update: Actually I think I may have figured part of this out. wpmu_create_blog has a $meta property. This property can be set to an associative array with a key of 'allowedthemes'. That key's value should be set to an associative array with keys:values = 'theme-name-or-id':true. I still need to set the starting theme for this blog and set plugins, which must be similar. Is this even a good approach?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

This WPSE answer led me to the $meta argument for wpmu_create_blog. That led me to this Support thread showing that $meta can include template and stylesheet arguments which seem to contain the folder name for the theme you want (just like the "Template" field in a child theme's style.css head section).

I'm having a hard time finding good documentation on wpmu_create_blog, but hopefully this is enough to work on.

share|improve this answer
add comment

You can use the following code to assign template and stylesheet to a sub site/blog:

// create the blog
$blog_ID = wpmu_create_blog( $domain, $path, $title, 1 );

// assign template and stylesheet to the blog
update_blog_option( $blog_ID, 'template', 'your_template_name' );
update_blog_option( $blog_ID, 'stylesheet', 'your_stylesheet_name' );

This will assign the template and stylesheet to the blog that has been just created. Please visit the following link to see the documentation for wpmu_create_blog function.

wpmu_create_blog

Many thanks.

share|improve this answer
    
I gave the answer to @mrwweb because his answer was written first, but thanks for writing code. –  weberwithoneb May 15 '12 at 16:26
add comment
function mysite_wpmu_new_blog($blog_id)
{
    switch_to_blog($blog_id);
    switch_theme('my-theme', 'my-theme');
    restore_current_blog();
}

add_action('wpmu_new_blog', 'mysite_wpmu_new_blog');

This works for me!

share|improve this answer
    
No need to post exactly the same answer two times. –  toscho Nov 26 '12 at 12:11
    
sorry, i just want to make sure people do not miss the answers they need. –  Wint Nov 27 '12 at 3:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.