Is it possible to allow a user to select which theme they would like installed from the new site signup page? And once the site is created, it obviously installs whichever theme they chose.
I found wp_get_themes. Is this how you would go about pre-populating a dropdown menu with all the available themes? How do you pass the theme’s information to the actual signup process so the site is created with the correct theme?
If someone knows how to do this with Gravity Forms, that would be great also.
Update:
Here’s what I have so far, it doesn’t take into account child themes, will work on that after
This function will output a list of themes with radio buttons, storing the selected theme in $_POST[‘custom_theme’]
/**
* Show list of themes at bottom of wp-signup.php (multisite)
*/
function 70169_add_signup_extra_fields() { ?>
Themes<br />
<?php
$themes = wp_get_themes();
foreach ( $themes as $theme ) {
$theme_name = $theme['Name'];
$theme_stylesheet = $theme->stylesheet;
?>
<label>
<input id="<?php echo $theme_stylesheet; ?>" type="radio" <?php if ( isset( $_POST['custom_theme'] ) ) checked( $_POST['custom_theme'], $theme_stylesheet ); ?> name="custom_theme" value="<?php echo $theme_stylesheet; ?>" ><?php echo $theme_name; ?>
</label>
<?php } ?>
<?php }
add_action( 'signup_extra_fields', '70169_add_signup_extra_fields' );
I thought I’d add a hidden field as a way to pass the theme’s value onto the site creation. There’s something wrong with this though – at the last step it loses it’s value, not sure why yet.
/**
* Add a hidden field with the theme's value
*/
function 70169_theme_hidden_fields() { ?>
<?php
$theme = isset( $_POST['custom_theme'] ) ? $_POST['custom_theme'] : null;
?>
<input type="hidden" name="user_theme" value="<?php echo $theme; ?>" />
<?php }
add_action( 'signup_hidden_fields', '70169_theme_hidden_fields' );
And finally a function to pass the theme name to the newly created site. This works if I hardcode the variables, but I’m unable to pass the value of the custom_theme yet. The site gets created fine but the template and stylesheet options are blank. It’s just not getting the value no matter what I try. I guess I have to use $_GET to access the hidden field I created earlier. Again, all I want to do at this point is pass the same theme name to the template and stylesheet options, I’ll figure out how to differentiate them after I get it working.
/**
* Create the new site with the theme name
*/
function 70169_wpmu_new_blog( $blog_id ) {
// need to get this working, use $_GET?
// $theme = ???
update_blog_option( $blog_id, 'template', $theme ); // $theme works if I hardcode it with a theme name
update_blog_option( $blog_id, 'stylesheet', $theme );
}
add_action( 'wpmu_new_blog', '70169_wpmu_new_blog' );
In order to do what you want , you can add whatever fields you want, and then store them in the
user_meta
…(One could also store them in the
$user_info
array/object, but I am not sure what would be the benefit .. )after all of that you can retrieve the user_theme like so :
NOTE : This was written On-The-Fly. It was not verified on multi-blog, but on a simple wp installation , and although there should not be much difference – still this is not a production function, it was only to put you on the right track. Sanitation and checking on variables, cleaning code and FORM MARKUP are needed , as well as adding the field also to other user related screens (create user, edit user, edit profile etc..) .
NOTE II: you asked about gravity forms in your uodate – they have an add-on for that
I know this is kind of cheating, but I use this plugin. It lets you copy any existing network site and then makes it available as a template when new users sign up. You can create as many new blog templates as you wish. They will contain all content, plugins, setting etc etc and users can choose one when setting up a new site / account 🙂
http://premium.wpmudev.org/project/new-blog-template/
This kind of answers your question:
We put a plugin called ‘Theme Switch‘ on this site: focusww.com and it put a sidebar where you can choose from a list of themes. It lets you choose which themes may be used and how long before the cookie expires to revert to a default theme.
If still relevant, maybe this could help others looking for similar solutions
I have written a blog post (http://artofcoding.in/select-theme-while-registering-wordpress-multisite-network/) here when I had a similar requirement. Hope this is helpful.