How to assign a WP user role based on a registration
-
Hello everybody
I’d like to ask you for a help with assigning a WP user role based on a BuddyPress registration.
REASON: I do this because I want to have an automatic way of allowing users after their registration to see and contribude only to specific forums.For subscribers I have Forum1 ready,
for contributors Forum1 AND Forum2.
Subscribers cannot see the content of Forum2!Everything should be automatically done. User comes to the website, registers (chooses type of account), gets access to specific forum.
If you could suggest a better solution, OK, if not, plese, try to fix this:
I have BuddyPress installed. I used extended profile fields to create a list of different users, let’s say User1, User2, User3. After hitting “finish registration” button, based on a selection of User1 or User2 or User3, specific role is assigned. So for example:
If User1 is chosen, user gets WP role subscriber,
if User2 is chosen, user gets WP role subscriber,
if User3 is chosen, user gets WP role contributor.Something similar is mentioned below with Cimy User Extra Fields, but it does NOT work with BuddyPress registration. If you add anything with Cimy User Extra Fields, you cannot see it in BuddyPress registration.
What function/code, to what file I should add so I could have my solution?
Thank you.———————————————————————-
// // Modify registration form to include roles // add_action('user_register', 'register_role'); function register_role($user_id, $password="", $meta=array()) { $userdata = array(); $userdata['ID'] = $user_id; $userdata['role'] = $_POST['cimy_uef_USERTYPE']; if ($userdata['role'] == 'A Contributor') { $userdata['role'] = 'contributor'; } if ($userdata['role'] == 'An Editor') { $userdata['role'] = 'editor'; } //only allow if user role is my_role if (($userdata['role'] == "contributor") or ($userdata['role'] == "editor")){ wp_update_user($userdata); } }
- The topic ‘How to assign a WP user role based on a registration’ is closed to new replies.