function masquerade_rules_is_masquerading in Masquerade Extras 7.2
Same name and namespace in other branches
- 7 masquerade_rules/masquerade_rules.rules.inc \masquerade_rules_is_masquerading()
Checks if the user supplied is masquerading as someone else.
@returns TRUE if:
- The current account is the same as the account being checked, AND the current account has the $_SESSION['masquerading'] key set.
- OR The account passed to us can be located in the {masquerade} database table as a source user.
FALSE otherwise. @retval bool
Parameters
stdClass $account: A fully-loaded Drupal user object.
File
- masquerade_rules/
masquerade_rules.rules.inc, line 58 - Rules support for Masquerade.
Code
function masquerade_rules_is_masquerading($account) {
global $user;
// Anonymous users wont have a UID, but we store them as 0.
$uid = isset($account->uid) ? $account->uid : 0;
// Check if the account provided is the current user.
if ($user->uid == $uid) {
return isset($_SESSION['masquerading']) && is_numeric($_SESSION['masquerading']);
}
// You can override this database query with:
// hook_query_masquerade_rules_is_masquerading_alter().
// @see hook_query_TAG_alter()
$query = db_select('masquerade', 'm')
->addTag('masquerade_rules_is_masquerading')
->fields('m', array(
'uid_as',
))
->condition('uid_from', $uid, '=')
->range(0, 1)
->execute();
$result = $query
->fetchCol();
return !empty($result);
}