1 redirect.module | redirect_access($op, $redirect, $account = NULL) |
Determine whether the current user may perform the given operation on the specified redirect.
Parameters
$op: The operation to be performed on the redirect. Possible values are:
- "create"
- "update"
- "delete"
$redirect: The redirect object on which the operation is to be performed, or redirect type (e.g. 'feedburner') for the "create" operation.
$account: Optional, a user object representing the user for whom the operation is to be performed. Determines access for a user other than the current user.
Return value
bool: TRUE if the operation may be performed, FALSE otherwise.
File
- core/
modules/ redirect/ redirect.module, line 589
Code
function redirect_access($op, $redirect, $account = NULL) {
global $user;
$rights = &backdrop_static(__FUNCTION__, array());
if (!$redirect || !in_array($op, array('create', 'update', 'delete'), TRUE)) {
// If there was no redirect to check against, or the $op was not one of the
// supported ones, we return access denied.
return FALSE;
}
// If no user object is supplied, the access check is for the current user.
if (empty($account)) {
$account = $user;
}
$cid = isset($redirect->rid) ? $redirect->rid : $redirect;
// Return cached value if access already checked for this redirect, user and op.
if (isset($rights[$account->uid][$cid][$op])) {
return $rights[$account->uid][$cid][$op];
}
// Administrators can access all redirects.
if (user_access('administer redirects', $account)) {
$rights[$account->uid][$cid][$op] = TRUE;
return TRUE;
}
// We grant access to the redirect if both of the following conditions are met:
// - No modules say to deny access.
// - At least one module says to grant access.
$access = module_invoke_all('redirect_access', $op, $redirect, $account);
if (in_array(REDIRECT_ACCESS_DENY, $access, TRUE)) {
$rights[$account->uid][$cid][$op] = FALSE;
return FALSE;
}
elseif (in_array(REDIRECT_ACCESS_ALLOW, $access, TRUE)) {
$rights[$account->uid][$cid][$op] = TRUE;
return TRUE;
}
return FALSE;
}