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.

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' );
share|improve this question
    
Thanks for the down vote! –  Andrew Oct 26 '12 at 3:35
1  
I think this is a good question, +1 –  Rilwis Oct 26 '12 at 5:25
1  
theoretically it is possible by adding additional fields to the registration form, but how would the user know how the themes looks like ? the preview will make the registration process a bit more complicated imho... –  krembo99 Oct 26 '12 at 7:11
    
@krembo99 fair point. I tried to simplify it for the question. I was going to use radio fields with thumbnail previews or have a button on each theme page that said "signup with this theme". The button would simply pass the name of the theme name to the signup form. Thought I'd start out simple :) –  Andrew Oct 26 '12 at 7:27
1  
ok - in that case, if you really want to do so , see my answer.. –  krembo99 Oct 27 '12 at 9:11

3 Answers 3

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 .. )

  // Render Form Fields
add_action('register_form','k99_register_form_add_theme_field');
// Checking
add_action('register_post','k99_check_fields',10,3);
// Insert Data
add_action('user_register', 'k99_register_new_register_fields');

// Render the form with the additional radio field 
function k99_register_form_add_theme_field(){
?>

<p>
<label>Theme<br />
 <?php $themes=wp_get_themes();
foreach ($themes as $theme ) {
$theme['Name'] = sanitize_title_with_dashes($theme['Name']);
$checked = checked( $_POST['custom_theme'], 1 );
 echo '<input id="custom_theme'.$theme['Name'] .'" type="radio" name="custom_theme" value="'. $theme['Name'] .'" '.$checked.'>  '. $theme['Name'].'<br />';
$custom_theme = $_POST['custom_theme'];
} ?>
</label>
</p>

<?php
}

// checking , sanitation etc .. of course this is not done...

function k99_check_fields($login, $email, $errors) {
global $custom_theme;
if ($_POST['custom_theme'] == '') {
$errors->add('empty_theme', "<strong>Error:</strong> Please select theme.");
}
else {
$custom_theme = $_POST['custom_theme'];
}
}

// Write to DB ... if you will..
function k99_register_new_register_fields($user_id, $password="", $meta=array())  {

$custom_theme = $_POST['custom_theme']; //just in case ..
update_usermeta($user_id, 'user_custom_theme',$custom_theme);

}

after all of that you can retrieve the user_theme like so :

get_user_meta($user_id, 'user_custom_theme', true);

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

share|improve this answer
    
thanks for your help. I've managed to piece together something and nearly have it working. Just having trouble getting the hidden field to stick and pass the value onto the last function. Have updated my question to include my progress thus far. –  Andrew Oct 28 '12 at 4:48
    
did you tried my function ? it should work .. –  krembo99 Oct 28 '12 at 8:39
    
The register_form hook in your example won't work in multisite. Found another hook to add the radio buttons to. Also get_themes() is deprecated and I found a better way to get the theme's information. Finally I don't think adding the theme's name to the user's meta table is the best way, the theme's template and stylesheet are stored in the options table. In saying that, your code has been a tremendous help so far, thanks. –  Andrew Oct 28 '12 at 9:17
    
the register_form hook will work on multisite (see CODEX codex.wordpress.org/Plugin_API/Action_Reference/register_form) . you can find many other hooks, but that would be the right one to use IMHO.. about the other comments, i do not really understand the point, care to explain ? –  krembo99 Oct 28 '12 at 21:24
    
Thanks for the note on the gravity forms user registration plugin. I have that plugin already but it does not allow you to select a theme when the user registers for a site, hence my question. –  Andrew Oct 28 '12 at 22:41

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/

share|improve this answer

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.

share|improve this answer
    
Sorry I'm not after a "theme switcher". I would like the user to be able to select a theme when they signup for a blog using wp-signup.php in a multisite installation. –  Andrew Oct 26 '12 at 5:14
    
I just stumbled on a $19 plugin that lets users install a theme on registration: premium.wpmudev.org/project/new-blog-template <= check it out :) –  Nohl Nov 7 '12 at 0:23

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.