Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By newdru on
The title says it all but i'll clarify.
Lets say i have a user. Normally i can go in via admin panels and assign user to a given role and then check off the permissions.
I basically want to be able to do the same thing but via code.
Can anyone point me to the right hooks or offer up a snippet?
thanks
Comments
hook_user
With hook_user you can add roles during user registration or editing.
I wanted to assign a role based on certain conditions at registration, so used $op == 'insert'.
The thing that confused me was that I needed to have the number for the array item matching the role ID.
http://api.drupal.org/api/function/hook_user