Set user role at registration
-
Hello.
I created two customs register-form.php that show different field groups. I want to change to user role to s2member_level1 after the activation if they used the second register-form. I have tried some other example on this site with no luck.here is the php of the register-form :
<form action=”<?php echo bp_get_signup_page();?>” name=”signup_form” id=”signup_form” class=”standard-form” method=”post” enctype=”multipart/form-data”>
<?php if ( ‘registration-disabled’ == bp_get_current_signup_step() ) : ?>
<?php do_action( ‘template_notices’ ); ?>
<?php do_action( ‘bp_before_registration_disabled’ ); ?><p><?php _e( ‘User registration is currently not allowed.’, ‘buddypress’ ); ?></p>
<?php do_action( ‘bp_after_registration_disabled’ ); ?>
<?php endif; // registration-disabled signup step ?><?php if ( ‘request-details’ == bp_get_current_signup_step() ) : ?>
<?php do_action( ‘template_notices’ ); ?>
<p><?php _e( ‘Registering for this site is easy. Just fill in the fields below, and we\’ll get a new account set up for you in no time.’, ‘buddypress’ ); ?></p>
<?php do_action( ‘bp_before_account_details_fields’ ); ?>
<div class=”register-section” id=”basic-details-section”>
<?php /***** Basic Account Details ******/ ?>
<h4><?php _e( ‘Account Details’, ‘buddypress’ ); ?></h4>
<div class=”newline”><label for=”signup_username”><?php _e( ‘Username’, ‘buddypress’ ); ?></label>
<?php do_action( ‘bp_signup_username_errors’ ); ?>
<input type=”text” name=”signup_username” id=”signup_username” value=”<?php bp_signup_username_value(); ?>” <?php bp_form_field_attributes( ‘username’ ); ?>/>
</div><div class=”newline”><label for=”signup_email”><?php _e( “Adresse courriel (votre nom d’usager) :”, ‘buddypress’ ); ?></label>
<?php do_action( ‘bp_signup_email_errors’ ); ?>
<input type=”email” name=”signup_email” id=”signup_email” value=”<?php bp_signup_email_value(); ?>” <?php bp_form_field_attributes( ’email’ ); ?>/>
</div><div class=”newline”><label for=”signup_password”><?php _e( ‘Créez un mot de passe (6 à 8 caractères) :’, ‘buddypress’ ); ?></label>
<?php do_action( ‘bp_signup_password_errors’ ); ?>
<input type=”password” name=”signup_password” id=”signup_password” value=”” class=”password-entry” <?php bp_form_field_attributes( ‘password’ ); ?>/>
<div id=”pass-strength-result”></div>
</div><div class=”newline”><label for=”signup_password_confirm”><?php _e( ‘Confirmation du mot de passe :’, ‘buddypress’ ); ?></label>
<?php do_action( ‘bp_signup_password_confirm_errors’ ); ?>
<input type=”password” name=”signup_password_confirm” id=”signup_password_confirm” value=”” class=”password-entry-confirm” <?php bp_form_field_attributes( ‘password’ ); ?>/>
</div><input type=”hidden” name=”user_type” id=”user_type” value=”your_role” />
<?php do_action( ‘bp_account_details_fields’ ); ?>
</div><!– #basic-details-section –>
<?php do_action( ‘bp_after_account_details_fields’ ); ?>
<?php /***** Extra Profile Details ******/ ?>
<?php if ( bp_is_active( ‘xprofile’ ) ) : ?>
<?php do_action( ‘bp_before_signup_profile_fields’ ); ?>
<div class=”register-section” id=”permanent-details-section”>
<?php /* Use the profile field loop to render input fields for the ‘base’ profile field group */ ?>
<?php if ( function_exists( ‘bp_has_profile’ ) ) : if ( bp_has_profile( ‘profile_group_id=1’ ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?><?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
<?php if ( ‘textbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”></span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<input type=”text” name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>” value=”<?php bp_the_profile_field_edit_value() ?>” />
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘textarea’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<textarea rows=”5″ cols=”40″ name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_edit_value() ?></textarea>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘selectbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<select name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>”>
<?php bp_the_profile_field_options() ?>
</select>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘multiselectbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<select name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>” multiple=”multiple”>
<?php bp_the_profile_field_options() ?>
</select>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘radio’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-line”><div class=”editfield”>
<div class=”radio”>
<span id=”styled<?php bp_the_profile_field_input_name() ?>”><span class=”label”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></span></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<?php bp_the_profile_field_options() ?>
<?php if ( !bp_get_the_profile_field_is_required() ) : ?>
<span class=”clear-link”>‘ );”><?php _e( ‘Clear’, ‘buddypress’ ) ?></span>
<?php endif; ?>
</div>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘checkbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-line”><div class=”editfield”>
<div class=”checkbox”>
<span id=”styled<?php bp_the_profile_field_input_name() ?>”><span class=”label”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></span></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<?php bp_the_profile_field_options() ?>
</div>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘datebox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<!–<div class=”datebox”>–>
<label for=”<?php bp_the_profile_field_input_name() ?>_day”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<select name=”<?php bp_the_profile_field_input_name() ?>_day” id=”<?php bp_the_profile_field_input_name() ?>_day”>
<?php bp_the_profile_field_options( ‘type=day’ ) ?>
</select>
<select name=”<?php bp_the_profile_field_input_name() ?>_month” id=”<?php bp_the_profile_field_input_name() ?>_month”>
<?php bp_the_profile_field_options( ‘type=month’ ) ?>
</select>
<select name=”<?php bp_the_profile_field_input_name() ?>_year” id=”<?php bp_the_profile_field_input_name() ?>_year”>
<?php bp_the_profile_field_options( ‘type=year’ ) ?>
</select>
<!–</div>–>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php endwhile; ?><?php $fields_ids[]= bp_get_the_profile_group_field_ids();?>
<?php endwhile; endif; endif; ?>
<input type=”hidden” name=”signup_profile_field_ids” id=”signup_profile_field_ids” value=”<?php echo implode(“,”,$fields_ids);?>” />
<input type=”hidden” name=”user_type” id=”user_type” value=”your_role” />
</div><div class=”register-section” id=”candidats-details-section”>
<?php /* Use the profile field loop to render input fields for the ‘base’ profile field group */ ?>
<?php if ( function_exists( ‘bp_has_profile’ ) ) : if ( bp_has_profile( ‘profile_group_id=2’ ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?><?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
<?php if ( ‘textbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”></span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<input type=”text” name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>” value=”<?php bp_the_profile_field_edit_value() ?>” />
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘textarea’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<textarea rows=”5″ cols=”40″ name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_edit_value() ?></textarea>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘selectbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<select name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>”>
<?php bp_the_profile_field_options() ?>
</select>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘multiselectbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”>
<label for=”<?php bp_the_profile_field_input_name() ?>”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<select name=”<?php bp_the_profile_field_input_name() ?>” id=”<?php bp_the_profile_field_input_name() ?>” multiple=”multiple”>
<?php bp_the_profile_field_options() ?>
</select>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘radio’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-line”><div class=”editfield”>
<div class=”radio”>
<span id=”styled<?php bp_the_profile_field_input_name() ?>”><span class=”label”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></span></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<?php bp_the_profile_field_options() ?>
<?php if ( !bp_get_the_profile_field_is_required() ) : ?>
<span class=”clear-link”>‘ );”><?php _e( ‘Clear’, ‘buddypress’ ) ?></span>
<?php endif; ?>
</div>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘checkbox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-line”><div class=”editfield”>
<div class=”checkbox”>
<span id=”styled<?php bp_the_profile_field_input_name() ?>”><span class=”label”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></span></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<?php bp_the_profile_field_options() ?>
</div>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php if ( ‘datebox’ == bp_get_the_profile_field_type() ) : ?>
<div class=”profile-table”><div class=”editfield”><span id=”styled<?php bp_the_profile_field_input_name() ?>”>
<!–<div class=”datebox”>–>
<label for=”<?php bp_the_profile_field_input_name() ?>_day”><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( ‘<span title=”Required” class=”required”>*</span>’, ‘buddypress’ ) ?><?php endif; ?></label></span>
<?php do_action( ‘bp_’ . bp_get_the_profile_field_input_name() . ‘_errors’ ) ?>
<select name=”<?php bp_the_profile_field_input_name() ?>_day” id=”<?php bp_the_profile_field_input_name() ?>_day”>
<?php bp_the_profile_field_options( ‘type=day’ ) ?>
</select>
<select name=”<?php bp_the_profile_field_input_name() ?>_month” id=”<?php bp_the_profile_field_input_name() ?>_month”>
<?php bp_the_profile_field_options( ‘type=month’ ) ?>
</select>
<select name=”<?php bp_the_profile_field_input_name() ?>_year” id=”<?php bp_the_profile_field_input_name() ?>_year”>
<?php bp_the_profile_field_options( ‘type=year’ ) ?>
</select>
<!–</div>–>
<?php do_action( ‘bp_custom_profile_edit_fields’ ) ?>
<div class=”editfield-description”><?php bp_the_profile_field_description() ?></div>
</div></div>
<?php endif; ?>
<?php endwhile; ?><?php $fields_ids[]= bp_get_the_profile_group_field_ids();?>
<?php endwhile; endif; endif; ?>
<input type=”hidden” name=”signup_profile_field_ids” id=”signup_profile_field_ids” value=”<?php echo implode(“,”,$fields_ids);?>” />
</div><?php do_action( ‘bp_after_signup_profile_fields’ ); ?>
<?php endif; ?>
<?php if ( bp_get_blog_signup_allowed() ) : ?>
<?php do_action( ‘bp_before_blog_details_fields’ ); ?>
<?php /***** Blog Creation Details ******/ ?>
<div class=”register-section” id=”blog-details-section”>
<h4><?php _e( ‘Blog Details’, ‘buddypress’ ); ?></h4>
<p><input type=”checkbox” name=”signup_with_blog” id=”signup_with_blog” value=”1″<?php if ( (int) bp_get_signup_with_blog_value() ) : ?> checked=”checked”<?php endif; ?> /> <?php _e( ‘Yes, I\’d like to create a new site’, ‘buddypress’ ); ?></p>
<div id=”blog-details”<?php if ( (int) bp_get_signup_with_blog_value() ) : ?>class=”show”<?php endif; ?>>
<label for=”signup_blog_url”><?php _e( ‘Blog URL’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
<?php do_action( ‘bp_signup_blog_url_errors’ ); ?><?php if ( is_subdomain_install() ) : ?>
http:// <input type=”text” name=”signup_blog_url” id=”signup_blog_url” value=”<?php bp_signup_blog_url_value(); ?>” /> .<?php bp_signup_subdomain_base(); ?>
<?php else : ?>
<?php echo home_url( ‘/’ ); ?> <input type=”text” name=”signup_blog_url” id=”signup_blog_url” value=”<?php bp_signup_blog_url_value(); ?>” />
<?php endif; ?><label for=”signup_blog_title”><?php _e( ‘Site Title’, ‘buddypress’ ); ?> <?php _e( ‘(required)’, ‘buddypress’ ); ?></label>
<?php do_action( ‘bp_signup_blog_title_errors’ ); ?>
<input type=”text” name=”signup_blog_title” id=”signup_blog_title” value=”<?php bp_signup_blog_title_value(); ?>” /><span class=”label”><?php _e( ‘I would like my site to appear in search engines, and in public listings around this network.’, ‘buddypress’ ); ?></span>
<?php do_action( ‘bp_signup_blog_privacy_errors’ ); ?><label><input type=”radio” name=”signup_blog_privacy” id=”signup_blog_privacy_public” value=”public”<?php if ( ‘public’ == bp_get_signup_blog_privacy_value() || !bp_get_signup_blog_privacy_value() ) : ?> checked=”checked”<?php endif; ?> /> <?php _e( ‘Yes’, ‘buddypress’ ); ?></label>
<label><input type=”radio” name=”signup_blog_privacy” id=”signup_blog_privacy_private” value=”private”<?php if ( ‘private’ == bp_get_signup_blog_privacy_value() ) : ?> checked=”checked”<?php endif; ?> /> <?php _e( ‘No’, ‘buddypress’ ); ?></label><?php do_action( ‘bp_blog_details_fields’ ); ?>
</div>
</div><!– #blog-details-section –>
<?php do_action( ‘bp_after_blog_details_fields’ ); ?>
<?php endif; ?>
<?php do_action( ‘bp_before_registration_submit_buttons’ ); ?>
<div class=”submit”>
<input type=”submit” name=”signup_submit” id=”signup_submit” value=”<?php esc_attr_e( ‘Sauvegarder mes infos’, ‘buddypress’ ); ?>” />
</div><?php do_action( ‘bp_after_registration_submit_buttons’ ); ?>
<?php wp_nonce_field( ‘bp_new_signup’ ); ?>
<?php endif; // request-details signup step ?>
<?php if ( ‘completed-confirmation’ == bp_get_current_signup_step() ) : ?>
<?php do_action( ‘template_notices’ ); ?>
<?php do_action( ‘bp_before_registration_confirmed’ ); ?><?php if ( bp_registration_needs_activation() ) : ?>
<p><?php _e( ‘You have successfully created your account! To begin using this site you will need to activate your account via the email we have just sent to your address.’, ‘buddypress’ ); ?></p>
<?php else : ?>
<p><?php _e( ‘You have successfully created your account! Please log in using the username and password you have just created.’, ‘buddypress’ ); ?></p>
<?php endif; ?><?php do_action( ‘bp_after_registration_confirmed’ ); ?>
<?php endif; // completed-confirmation signup step ?>
<?php do_action( ‘bp_custom_signup_steps’ ); ?>
</form>
Any ideas? Also I don’t want to use another pluggins and I don’t want to give the user the option of choosing his user role. Thank you in advance.
- You must be logged in to reply to this topic.