Redirect user after login based on their role

Public

If user has role "staff" then set one destination, if the user does not have the role "staff" then send them to another destination.

Get raw version
php
  1. function MYMODULE_user_login(&$edit, $account) {
  2. $user = user_load($account->uid);
  3. $is_staff = is_staff(); // this is a custom function... please see below snippet.
  4. if($is_staff) {
  5. $destination = '/';
  6. } else {
  7. $destination = 'user';
  8. }
  9.  
  10. $_GET['destination'] = $destination;
  11. $edit['redirect'] = $destination;
  12. }

Check to see if the current user has the role "staff". Alter this depending on your roles.

Get raw version
php
  1. function is_staff() {
  2. global $user;
  3. $bool = FALSE;
  4. if(is_array($user->roles)) {
  5. if(in_array('staff', $user->roles)) {
  6. $bool = TRUE;
  7. }
  8. }
  9.  
  10. return $bool;
  11. }