You are here

function hook_redirect_access in Redirect 7.2

Same name and namespace in other branches
  1. 7 redirect.api.php \hook_redirect_access()

Control access to a redirect.

Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a redirect.

The administrative account (user ID #1) always passes any access check, so this hook is not called in that case. Users with the "administer redirects" permission may always update and delete redirects through the administrative interface.

Note that not all modules will want to influence access on all redirect types. If your module does not want to actively grant or block access, return REDIRECT_ACCESS_IGNORE or simply return nothing. Blindly returning FALSE will break other redirect access modules.

Parameters

$redirect: The redirect object on which the operation is to be performed, or, if it does not yet exist, the type of redirect to be created.

$op: The operation to be performed. Possible values:

  • "create"
  • "delete"
  • "update"

$account: A user object representing the user for whom the operation is to be performed.

Return value

REDIRECT_ACCESS_ALLOW if the operation is to be allowed; REDIRECT_ACCESS_DENY if the operation is to be denied; REDIRECT_ACCESSS_IGNORE to not affect this operation at all.

See also

redirect_access()

Related topics

1 invocation of hook_redirect_access()
redirect_access in ./redirect.module
Determine whether the current user may perform the given operation on the specified redirect.

File

./redirect.api.php, line 146
Hooks provided by the Redirect module.

Code

function hook_redirect_access($op, $redirect, $account) {
  $type = is_string($redirect) ? $redirect : $redirect->type;
  if (in_array($type, array(
    'normal',
    'special',
  ))) {
    if ($op == 'create' && user_access('create ' . $type . ' redirects', $account)) {
      return REDIRECT_ACCESS_ALLOW;
    }
    if ($op == 'update') {
      if (user_access('edit any ' . $type . ' content', $account) || user_access('edit own ' . $type . ' content', $account) && $account->uid == $redirect->uid) {
        return REDIRECT_ACCESS_ALLOW;
      }
    }
    if ($op == 'delete') {
      if (user_access('delete any ' . $type . ' content', $account) || user_access('delete own ' . $type . ' content', $account) && $account->uid == $redirect->uid) {
        return REDIRECT_ACCESS_ALLOW;
      }
    }
  }

  // Returning nothing from this function would have the same effect.
  return REDIRECT_ACCESS_IGNORE;
}