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

Implements hook_node_access().

It allows view and edit access to private nodes, for the account whose username is foobar.

This hook is used to demonstrate how to give certain permissions to an arbitrary user.

Related topics

File

modules/examples/node_access_example/node_access_example.module, line 207
Hook implementations for the Node Access Example module.

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