1

I need to be able to incorporate into my system a method for which users can view nodes that only they have created. How can this be done?

2 Answers 2

1

Basically, you need to implement hook_node_access() in a custom module. Something like

function MYMODULE_node_access ($node, $op, $account) {
  if ($op == 'view' && $node->uid != $account->uid) {
    return NODE_ACCESS_DENY;
  }
  else {
    return NODE_ACCESS_IGNORE;
  }
}

should be a start.

2
  • As side note, hook_node_access() is not invoked for node listings, such as RSS feeds, or the default front page (/node).
    – apaderno
    Nov 27, 2012 at 0:02
  • I used this method. I also used it to implement my tagging mechanism (allowing users to edit content they've been tagged in). Pretty sweet. <3 Drupal. Nov 27, 2012 at 0:58
2

I've found the content_access module to be pretty helpful for this kind of thing.

Just enable this on the content type you want to control, and make sure that "view any content" is unchecked for authenticated users, and that "view own content" is checked for authenticated users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.