Hi,
Well, sorry for the delay but I didn’t find the time to do this thing. Today I can try some things and I think it’s working.
You need to add this filter to your functions.php:
function custom_bp_core_signup_user($user_id) {
$user_role = strtolower(xprofile_get_field_data('NAME OF THE XPROFILE FIELD', $user_id));
switch($user_role) {
case "role 1":
$new_role = 'Contributor';
break;
case "role 2":
$new_role = 'Author';
break;
default:
case "role 3":
$new_role = 'Suscriber';
break;
}
wp_update_user(array(
'ID' => $user_id,
'role' => $new_role
));
}
add_action( 'bp_core_signup_user', 'custom_bp_core_signup_user', 10, 1);
First I have created an xprofile field (dropdown select box) with the name “NAME OF THE XPROFILE FIELD”. You can give the name you want but you need to write it in the place of this string. The options of the field are the name of the roles: “role 1”, “role 2” and “role 3”. I make this field required and the visibility settings admins only. When a user sign up, he choose the role he want. When he sends the sign up form, this function is executed.
The function see what $user_role the user has selected searching it by the name of the field and $user_id. Then it changes the role of the user. If the user selects “role 1” we change his role as a contributor. If he chooses “role 2”, he will be an author. If he chooses “role 3”, he will be a suscriber. Suscriber is also the default role.
Now, you need to decide what you want to do when a user edit his profile. If you don’t want a user be able to change his role, you need to hide this field. I believe you can use this hook “xprofile_screen_edit_profile”. You need to do the same thing, check what value has the field $user_role and then change the role consequently.