0

In my new multi-site project I need to show the theme option before user sign up I have shown the screen short of theme by using the below code.

$themes = wp_get_themes(); foreach( $themes as $theme ){ echo 'Theme Name: '.$theme -> name; echo 'get_screenshot()).'" /> '; }

Now what I need to do is to show the check box once user will select the check box or radio button so after the select of radio button the new site is generated by the user will activate the same theme that he select.

Also how I can show the only selected theme not all theme. Also with that user can preview all pages of theme before sign up. If some one now this please reply. if explain with the code much appreciated. Thanks

0

Please paste the below code in the function.php file to activate the theme from front end

/** * Add custom field to registration form */ add_action( 'signup_blogform', 'aoc_show_addtional_fields' ); add_action( 'user_register', 'aoc_register_extra_fields' );

function aoc_show_addtional_fields() { $themes = wp_get_themes(); echo 'Choose template for your site'; foreach ($themes as $theme){ echo 'get_screenshot().'" width="240"/>'; echo $theme->name . ' template.'" name="template" />'; } echo ''; }

function aoc_register_extra_fields ( $user_id, $password = "", $meta = array() ) { update_user_meta( $user_id, 'template', $_POST['template'] ); }

// The value submitted in our custom input field needs to be added to meta array as the user might not be created yet. add_filter('add_signup_meta', 'aoc_append_extra_field_as_meta'); function aoc_append_extra_field_as_meta($meta) { if(isset($_REQUEST['template'])) { $meta['template'] = $_REQUEST['template']; } return $meta; }

// Once the new site added by registered user is created and activated by user after email verification, update the template selected by user in database. add_action('wpmu_new_blog', 'aoc_extra_field', 10, 6); function aoc_extra_field($blog_id, $user_id, $domain, $path, $site_id, $meta) { update_blog_option($blog_id, 'template', $meta['template']); update_blog_option($blog_id, 'stylesheet', $meta['template']); }

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.