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' );