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’]);
}