You are here

function node_node_access in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/node/node.module \node_node_access()
  2. 9 core/modules/node/node.module \node_node_access()
  3. 10 core/modules/node/node.module \node_node_access()

Implements hook_node_access().

Related topics

File

modules/node/node.module, line 3109
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node->type;
  if (in_array($type, node_permissions_get_configured_types())) {
    if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
      return NODE_ACCESS_ALLOW;
    }
    if ($op == 'update') {
      if (user_access('edit any ' . $type . ' content', $account) || user_access('edit own ' . $type . ' content', $account) && $account->uid == $node->uid) {
        return NODE_ACCESS_ALLOW;
      }
    }
    if ($op == 'delete') {
      if (user_access('delete any ' . $type . ' content', $account) || user_access('delete own ' . $type . ' content', $account) && $account->uid == $node->uid) {
        return NODE_ACCESS_ALLOW;
      }
    }
  }
  return NODE_ACCESS_IGNORE;
}