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.
$account A user object representing the user for whom the operation is to be performed.

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.

Codes:

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

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

Usage sample:
<?php
CREATE TABLE node_sample (
vid int(10) unsigned NOT NULL default '0',
nid int(10) unsigned NOT NULL default '0',
color varchar(255) NOT NULL default '',
quantity int(10) unsigned NOT NULL default '0',
PRIMARY KEY (vid, nid),
KEY `node_sample_nid` (nid))
?>

function node_sample_access($op, $node, $account) {
if ($op == 'create') {
return user_access('create sample content', $account);
}

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

if ($op == 'delete') {
if (user_access('delete any sample content', $account) || (user_access('delete own sample content', $account) && ($account->uid == $node->uid))) {
return TRUE;
}
}
}