Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: How to assign a WP user role based on a registration

@spiritix

Participant

Never mind, I think I have it 🙂
[edited – please use the ‘code’ button to share snippets]

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);
   
  }
Skip to toolbar