I have an application where I'd like to assign users to a role programatically, if the user meets some criteria. I am finding this difficult to do, since Drupal appears to be unsetting anything that I set in the users_roles table of the database.
Right now, I use hook_user to add a portion of the user registration/edit screen that deals with the application's user settings. I've put code into the 'validate', 'update' and 'insert' options, but I've tried:
- Adding records the the users_roles table. I add them; Drupal removes them behind my back.
- Modifying the $user->roles array in the 'validate' hook. Drupal only laughs at me :-( and the change is ignored.
- Modifying $_POST['edit']['roles'] to fool user module's form processing code. Alas, Drupal ignores me.
Any idea of how the actually do this?
BTW, you core people: an API for this would be really nice.