function xmlsitemap_switch_user in XML sitemap 6.2
Same name and namespace in other branches
- 7.2 xmlsitemap.module \xmlsitemap_switch_user()
Set the current user stored in $GLOBALS['user'].
4 calls to xmlsitemap_switch_user()
- XMLSitemapUnitTest::testSwitchUser in ./
xmlsitemap.test - Tests for xmlsitemap_switch_user and xmlsitemap_restore_user().
- xmlsitemap_custom_edit_link_form_validate in xmlsitemap_custom/
xmlsitemap_custom.admin.inc - xmlsitemap_menu_xmlsitemap_process_menu_links in xmlsitemap_menu/
xmlsitemap_menu.module - Process menu sitemap links.
- xmlsitemap_restore_user in ./
xmlsitemap.module - Restore the user that was originally loaded.
File
- ./
xmlsitemap.module, line 1208 - Main file for the xmlsitemap module.
Code
function xmlsitemap_switch_user($new_user = NULL) {
global $user;
$user_original =& xmlsitemap_static(__FUNCTION__);
if (!isset($new_user)) {
if (isset($user_original)) {
// Restore the original user.
$user = $user_original;
$user_original = NULL;
session_save_session(TRUE);
}
else {
return FALSE;
}
}
elseif (is_numeric($new_user) && $user->uid != $new_user) {
// Get the full user object.
if (!$new_user) {
$new_user = drupal_anonymous_user();
}
elseif (!($new_user = user_load($new_user))) {
return FALSE;
}
// Backup the original user object.
if (!isset($user_original)) {
$user_original = $user;
session_save_session(FALSE);
}
$user = $new_user;
}
elseif (is_object($new_user) && $user->uid != $new_user->uid) {
// Backup the original user object.
if (!isset($user_original)) {
$user_original = $user;
session_save_session(FALSE);
}
$user = $new_user;
}
else {
return FALSE;
}
return $user;
}