boss please, i created this gender field on registration page with radio buttons view here:
– https://i.postimg.cc/Gtfdz6FD/gender-field-Screenshot-1.png –
i want if people select female on registration they would be automatically assigned a role ..for example lets say the select female, then they would automatically be assigned “contributor” role (lets just use contributor as example)
i saw this post with someone with same problem who had his problem solved:
– https://buddypress.org/support/topic/add-role-to-user-depending-on-value-in-buddypress-profile-field-on-registration/he used this a code from here:
– https://buddypress.org/support/topic/how-to-assign-a-wp-user-role-based-on-a-registration/#post-232887 –which is this code-
add_action('bp_core_activated_user', 'bp_custom_registration_role',10 , 3); function bp_custom_registration_role($user_id, $key, $user) { $userdata = array(); $userdata['ID'] = $user_id; $userdata['role'] = xprofile_get_field_data('Typ konta', $user_id); if ($userdata['role'] == 'User1') $userdata['role'] = 'subscriber'; if ($userdata['role'] == 'User2') $userdata['role'] = 'subscriber'; if ($userdata['role'] == 'User3') $userdata['role'] = 'contributor'; //only allow if user role is my_role if (($userdata['role'] == "subscriber") or ($userdata['role'] == "contributor")) wp_update_user($userdata); }
–
could you please teach me how to edit it so that i would assign who ever selects “female” on registration to automatically “contributor” role? so i can put it in bp-custom.phpHi,
Please do not use that code. It is a lot of unnecessary code. People can simply use set_role for doing it. Allow me to create a post on BuddyDev with some example. It is only 3-4 lines of code.Regards
Brajeshok boss im waiting, don’t know what i would have done with out you …you are just a legend
ok boss, how long before you make the post, cos electricity is limited here? it wouldnt be today? .. or can you just give me a quick fix code? i could use untill the post is ready?
Hi,
My apologies for the delay in posting.
here we go
https://buddydev.com/assign-user-roles-based-on-buddypress-profile-field-data-on-user-registration/Regards
Brajesh
The topic ‘ [Resolved] how to assign user role on registration, with radio button selection’ is closed to new replies.