Allowing new users to select WP role
-
I’m looking for new users to be able to select from the default WP roles available (Subscriber/Editor/Admin/Contributor). Currently, my WP is set up so new users are Subscriber by default, but I want this to be overwritten by a selection on the registration form.
So far, I have a new xprofile group called ‘User Role’ with the four options, and within by bp-custom.php file I have:
function register_role($user_id) { $user_role = strtolower(xprofile_get_field_data('User Role', $user_id)); switch($user_role) { case "Editor": $new_role = 'editor'; break; case "Contributor": $new_role = 'contributor'; break; case "Admin": $new_role = 'admin'; break; case "Subscriber": $new_role = 'subscriber'; break; } wp_update_user(array( 'ID' => $user_id, 'role' => $new_role )); } add_action( 'user_register', 'register_role');
This doesn’t work though, it still creates new user entries with the default role of Subscriber. I have also tried the plugin WordPress Roles at Registration, with also didn’t work. Any ideas?
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Allowing new users to select WP role’ is closed to new replies.