function masquerade_switch_back in Masquerade 7
Same name and namespace in other branches
- 5 masquerade.module \masquerade_switch_back()
- 6 masquerade.module \masquerade_switch_back()
Function for a masquerading user to switch back to the previous user.
1 call to masquerade_switch_back()
- masquerade_switch_back_page in ./masquerade.module 
- Allows a user who is currently masquerading to become a new user.
File
- ./masquerade.module, line 890 
- The masquerade module allows administrators to masquerade as other user.
Code
function masquerade_switch_back() {
  // switch user
  global $user;
  cache_clear_all($user->uid, 'cache_menu', TRUE);
  $uid = db_query("SELECT m.uid_from FROM {masquerade} m WHERE m.sid = :sid AND m.uid_as = :uid_as ", array(
    ':sid' => session_id(),
    ':uid_as' => $user->uid,
  ))
    ->fetchField();
  // erase record
  db_delete('masquerade')
    ->condition('sid', session_id())
    ->condition('uid_as', $user->uid)
    ->execute();
  $oldname = $user->uid == 0 ? variable_get('anonymous', t('Anonymous')) : $user->name;
  // Call logout hooks when switching from masquerading user.
  masquerade_user_logout($user);
  drupal_session_regenerate();
  $user = user_load($uid);
  // Call all login hooks when switching back to original user.
  $edit = array();
  // Passed by reference.
  user_module_invoke('login', $edit, $user);
  watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array(
    '%user' => $user->name,
    '%masq_as' => $oldname,
  ), WATCHDOG_INFO);
}