0

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?

2

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.

2

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.

  • I gave the answer to @mrwweb because his answer was written first, but thanks for writing code. – getWeberForStackExchange May 15 '12 at 16:26
0
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!

  • No need to post exactly the same answer two times. – fuxia 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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