function linkchecker_impersonate_user in Link checker 6.2
Same name and namespace in other branches
- 7 linkchecker.module \linkchecker_impersonate_user()
Impersonates another user. http://drupal.org/node/287292#comment-3162350
Each time this function is called, the active user is saved and $new_user becomes the active user. Multiple calls to this function can be nested, and session saving will be disabled until all impersonation attempts have been reverted using linkchecker_revert_user().
Parameters
$new_user: User to impersonate, either a UID or a user object.
Return value
Current user object.
See also
3 calls to linkchecker_impersonate_user()
- LinkCheckerUserImpersonatingUserTestCase::testLinkCheckerImpersonateUser in tests/
linkchecker_extract_links.test - linkchecker_revert_user in ./
linkchecker.module - Reverts to the previous user after impersonating.
- _linkchecker_status_handling in ./
linkchecker.module - Status code handling.
6 string references to 'linkchecker_impersonate_user'
- linkchecker_admin_settings_form in includes/
linkchecker.admin.inc - @file Administrative page callbacks for the linkchecker module.
- linkchecker_admin_settings_form_validate in includes/
linkchecker.admin.inc - linkchecker_install in ./
linkchecker.install - Implementation of hook_install().
- linkchecker_uninstall in ./
linkchecker.install - Implementation of hook_uninstall().
- linkchecker_update_6217 in ./
linkchecker.install - #1450672: Set user 1 as default user to impersonate content updates.
File
- ./
linkchecker.module, line 1916 - This module periodically check links in given node types, blocks, cck fields, etc.
Code
function linkchecker_impersonate_user($new_user = NULL) {
global $user;
static $user_original;
if (!isset($new_user)) {
if (isset($user_original) && !empty($user_original)) {
// Restore the previous user from the stack.
$user = array_pop($user_original);
// Re-enable session saving if we are no longer impersonating a user.
if (empty($user_original)) {
session_save_session(TRUE);
}
}
}
else {
// Push the original user onto the stack and prevent session saving.
$user_original[] = $user;
session_save_session(FALSE);
if (is_numeric($new_user)) {
$user = user_load($new_user);
}
else {
$user = is_object($new_user) ? $new_user : (object) $new_user;
}
}
return $user;
}