1 node_access_example.module node_access_example_node_access($node, $op, $account)

Implements hook_node_access().

Allows view and edit access to private nodes, when the account requesting access has the username 'foobar'.

hook_node_access() is used here to demonstrate allowing certain privileges to an arbitrary user.

See also

hook_node_access()

Related topics

File

modules/examples/node_access_example/node_access_example.module, line 213
Module file illustrating API-based node access.

Code

function node_access_example_node_access($node, $op, $account) {
  // If $node is a string, the node has not yet been created. We don't care
  // about that case.
  if (is_string($node)) {
    return NODE_ACCESS_IGNORE;
  }
  if (($op == 'view' || $op == 'update') && (!empty($account->name) && $account->name == 'foobar') && !empty($node->private)) {
    backdrop_set_message(t('Access to node @nid allowed because requester name (@name) is specifically allowed', array('@name' => $node->name, '@uid' => $account->uid)));
    return NODE_ACCESS_ALLOW;
  }
  return NODE_ACCESS_IGNORE;
}