function hook_access

6.x node.php hook_access($op, $node, $account)

Define access restrictions.

This hook allows node modules to limit access to the node types they define.

Parameters

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

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

$node: Either a node object or the machine name of the content type on which to perform the access check.

$account: The user object to perform the access check operation on.

Return value

  • TRUE if the operation is to be allowed.
  • FALSE if the operation is to be denied.
  • NULL to not override the settings in the node_access table, or access control modules.

The administrative account (user ID #1) always passes any access check, so this hook is not called in that case. If this hook is not defined for a node type, all access checks will fail, so only the administrator will be able to see content of that type. However, users with the "administer nodes" permission may always view and edit content through the administrative interface.

For a detailed usage example, see node_example.module.

Related topics

16 functions implement hook_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

blog_access in drupal-6.x/modules/blog/blog.module
Implementation of hook_access().
blog_page_user_access in drupal-6.x/modules/blog/blog.module
Access callback for user blog pages.
comment_access in drupal-6.x/modules/comment/comment.module
This is *not* a hook_access() implementation. This function is called to determine whether the current user has access to a particular comment.
filter_access in drupal-6.x/modules/filter/filter.module
Returns TRUE if the user is allowed to access this format.
forum_access in drupal-6.x/modules/forum/forum.module
Implementation of hook_access().

... See full list

1 invocation of hook_access()
node_access in drupal-6.x/modules/node/node.module
Determine whether the current user may perform the given operation on the specified node.

File

documentation-6.x/developer/hooks/node.php, line 160
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_access($op, $node, $account) {
  if ($op == 'create') {
    return user_access('create stories', $account);
  }

  if ($op == 'update' || $op == 'delete') {
    if (user_access('edit own stories', $account) && ($account->uid == $node->uid)) {
      return TRUE;
    }
  }
}