function masquerade_user in Masquerade 5
Same name and namespace in other branches
- 6 masquerade.module \masquerade_user()
Implementation of hook_user().
File
- ./
masquerade.module, line 168 - masquerade.module
Code
function masquerade_user($op, &$edit, &$edit_user, $category = NULL) {
switch ($op) {
case 'logout':
if (!empty($edit_user->masquerading)) {
global $user;
cache_clear_all($user->uid, 'cache_menu', true);
$real_user = user_load(array(
'uid' => $user->masquerading,
));
watchdog('masquerade', t("User %user no longer masquerading as %masq_as.", array(
'%user' => $real_user->name,
'%masq_as' => $user->name,
)));
db_query("DELETE FROM {masquerade} WHERE sid = '%s' AND uid_as = %d", session_id(), $edit_user->uid);
}
break;
case 'view':
// check if user qualifies as admin
$roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array())));
$perm = $edit_user->uid == 1 || array_intersect(array_keys((array) $edit_user->roles), $roles) ? 'masquerade as admin' : 'masquerade as user';
global $user;
if (user_access($perm) && !$edit_user->masquerading && $user->uid != $edit_user->uid) {
$items['masquerade'] = array(
'value' => l(t('Masquerade as !user', array(
'!user' => $edit_user->name,
)), 'masquerade/switch/' . $edit_user->uid, array(
'destination' => $_GET['q'],
)),
'class' => 'masquerade',
);
return array(
t('Masquerade') => $items,
);
}
break;
}
}