hook_access

Definition

hook_access($op, $node)
developer/hooks/node.php, line 139

Description

Define access restrictions.

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

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.

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.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.
Node access rightsThe node access system determines who can do what to which nodes.

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;
    }
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.