Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have coded a module which uses hook_user at login to set some user variables. When using masquerade to switch user, hook_user is not called and my variables are not set.
I think a "hook_user('load', $new_account)" call whould be the solution.
Comments
Comment #1
geaseYes, this would be great. I have some rules that set user roles at login depending on various conditions, and to check how it all works via masquerade simulating user login is needed. Obviously, hook_user('login') should be called somewhere.
Comment #2
peterx CreditAttribution: peterx commented@enboig and @gease I am interested in your use of login and rules for possible use in http://drupal.org/node/1416136. The second login has to get all the roles assigned to the fist login. I am looking at custom code. hook_user and/or Rules might be a cleaner way to do things.
Comment #3
enboig CreditAttribution: enboig commentedAt hook_boot() I check global $user->uid versus $_SESSION['my_old_uid']; if its different, I reload anything I need and update $_SESSION['my_old_uid'].
Comment #4
peterx CreditAttribution: peterx commentedSounds like your code would have to run after everything else that modifies the user. For my use, it would be something like:
$old = load user $_SESSION['mymodule_old_uid']
$user->roles = array_merge($user->roles, $old->roles);
Comment #5
apadernoI am closing this feature request, as Drupal 6 is no longer supported. Please re-open it if you would like the feature implemented in the Drupal 7 or 8 version of the module.