Hello Cristián,
I’ve spent almost all day trying to add a combo box to registration form to let the user select the role. I’ve achieved it in wp registration form, but not in s2Member regostration form. To achieve this goal (select the role at registration) in wp registration form, I’ve used the next code:
function wp_choose_roles_registration_form() {
global $wp_roles;
if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles();
$default_role = get_option("default_role");
if($_POST['wp_rar_user_role']) {
$selected_role = $_POST['wp_rar_user_role'];
} else {
$selected_role = $default_role;
}
if(count($this->wp_selected_rar_roles) < 2) return true;
?>
<style type="text/css">
<!--
select.input {
background: #FFF;
border: 1px solid #E5E5E5;
font-size: 16px;
margin-bottom: 16px;
margin-right: 6px;
margin-top: 2px;
padding: 3px;
width: 100%;
}
-->
</style>
<p>
<label for="wp_rar_user_role"><?php echo $this->wp_rar_role_label; ?><br />
<select id="wp_rar_user_role" name="wp_rar_user_role" class="input select">
<?php
foreach($this->wp_selected_rar_roles as $role) {
?>
<option value="<?php echo $role; ?>"<?php echo ($selected_role == $role) ? ' selected="selected"' : ''; ?>>
<?php echo $wp_roles->roles[$role]['name'];?>
</option>
<?php
}
?>
</select>
</label>
</p>
<?php
}
function set_roles_at_registration($user_ID) {
if( in_array($_POST['wp_rar_user_role'], $this->wp_selected_rar_roles) ) {
$wp_rar_user_role = $_POST['wp_rar_user_role'];
} else {
$wp_rar_user_role = get_option("default_role");
}
if(isset($wp_rar_user_role) and $user_ID) {
wp_update_user( array ('ID' => $user_ID, 'role' => $wp_rar_user_role) );
}
}
function init_rar() {
$wp_rar_plugin = new WPRolesAtRegistration;
add_action('register_form', array($wp_rar_plugin, 'wp_choose_roles_registration_form'));
add_action('user_register', array($wp_rar_plugin, 'set_roles_at_registration'));
}
add_action('init', 'init_rar');
where WPRolesAtRegistration is the class that contains the functions.
This is working ok in the wp rgistration form, but the combo box does not even appear in the s2Member registration form. Therefore my question is what hook may I have to try to add this combo box to the s2Member registration form.
In http://www.s2member.com/kb/pro-forms/ mentions a hook which is:
add_action('ws_plugin__s2member_during_configure_user_registration', 'store_my_custom_input_fields');
but if I add inside the function init_rar() the next:
add_action('ws_plugin__s2member_during_configure_user_registration', array($wp_rar_plugin, 'wp_choose_roles_registration_form'));
it’s useless, nothing new appears at s2member registration form. So, what am I missing? What’s the hook to use and how?
Please, help me, I’ve spent lots of hours.