Community Documentation

hook_access

5 node.php hook_access($op, $node)
6 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: The node on which the operation is to be performed, or, if it does not yet exist, the type of node to be created.

Return value

TRUE if the operation may be performed; FALSE if the operation may not be returned; NULL to not override the settings in the node_access table.

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

▾ 15 functions implement hook_access()

blog_access in modules/blog.module
Implementation of hook_access().
book_access in modules/book.module
Implementation of hook_access().
comment_access in modules/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.
fileupload_access in developer/examples/fileupload.module
Implementation of hook_access.
filter_access in modules/filter.module
Returns true if the user is allowed to access this format.
forum_access in modules/forum.module
Implementation of hook_access().
multipage_form_example_access in developer/examples/multipage_form_example.module
Implementation of hook_access().
Node access rights in modules/node.module
The node access system determines who can do what to which nodes.
node_access in modules/node.module
Determine whether the current user may perform the given operation on the specified node.
node_example_access in developer/examples/node_example.module
Implementation of hook_access().
page_access in modules/page.module
Implementation of hook_access().
poll_access in modules/poll.module
Implementation of hook_access().
story_access in modules/story.module
Implementation of hook_access().
user_access in modules/user.module
Determine whether the user has a given privilege.
user_admin_access in modules/user.module
Menu callback: list all access rules

File

developer/hooks/node.php, line 79
These hooks are defined by node modules, modules that define a new kind of node.

Code

<?php
function hook_access($op, $node) {
  global $user;

  if ($op == 'create') {
    return user_access('create stories');
  }

  if ($op == 'update' || $op == 'delete') {
    if (user_access('edit own stories') && ($user->uid == $node->uid)) {
      return TRUE;
    }
  }
}
?>
Login or register to post comments