Setting User Role During Custom Registration
-
Ok, so I asked something kind of similar before, but there are a ton of new details that I think it deserves a new thread.
So…what I am trying to do is set a user’s role during a registration using a custom registration form. I have used code from Brajesh Singh’s tutorial here http://buddydev.com/buddypress/show-buddypress-user-registration-form-everywhere-buddypress-site/. I can now include a custom form anywhere on the site which is working well. Here is a gist with my custom form code https://gist.github.com/ch1n3s3b0y/63539624787bca8e6bef.
I tried to use the code here https://buddypress.org/support/topic/resolved-different-profile-types-and-different-user-roles/
function guru_bp_core_signup_user($user_id) { $user_type = $POST_['user_type']; $user_role = $user_type; switch($user_role) { case "customer": $new_role = 'customer'; break; case "guru": $new_role = 'expert'; break; } wp_update_user(array( 'ID' => $user_id, 'role' => $new_role )); echo $new_role; } add_action( 'bp_core_signup_user', 'guru_bp_core_signup_user', 10, 1);
I placed this code in my bp-custom.php. I am registering users successfully with this form, but unfortunately the user role isn’t being set as ‘expert’ but instead as the default ‘customer’.
Any ideas on where I have went wrong?
- The topic ‘Setting User Role During Custom Registration’ is closed to new replies.