function _notify_switch_user in Notify 5
Same name and namespace in other branches
- 5.2 notify.module \_notify_switch_user()
- 6 notify.module \_notify_switch_user()
Switch from original user to mail submision user and back.
NOTE: Copied from mailhandler
Note: You first need to run _notify_switch_user without argument to store the current user. Call _notify_switch_user without argument to set the user back to the original user.
Parameters
$uid The user ID to switch to:
1 call to _notify_switch_user()
- _notify_send in ./
notify.module - Helper function to send the notification email.
File
- ./
notify.module, line 554
Code
function _notify_switch_user($uid = NULL) {
global $user;
static $orig_user = array();
if (isset($uid)) {
// Should a user visit cron.php, or should this module be invoked via
// poormanscron and _notify_send() does not complete,
// the visitor will end up logged in as the "switched to user" for
// subsequent requests unless we disable saving the session
// until we are sure we're the invoking user again.
session_save_session(FALSE);
$user = user_load(array(
'uid' => $uid,
));
}
else {
if (count($orig_user)) {
$user = array_shift($orig_user);
array_unshift($orig_user, $user);
session_save_session(TRUE);
}
else {
$orig_user[] = $user;
}
}
}