I'm creating a site for events where people can subscribe themselves to a single one. Now, I'm using Node Registration module to allow users to subscribe. I would like to know if it is possible to enable comments of a particular event only to users who are members of it. Is there a module to do this? I tried with rules module but i couldn't...

  • do anonymous users allowed to register to events?
    – arpitr
    Nov 18, 2013 at 12:12
  • No, only registered users can subscribe to an event...if you are already a site member you can add comments only to events where you are subscribed in..
    – Luke
    Nov 18, 2013 at 14:25
  • check the answer added below if that helps you
    – arpitr
    Nov 18, 2013 at 14:27

1 Answer 1


Here is a programmatic way to do this, add this code to your custom module


In the following code my content type name is article, change it to yours.

Also this code can not handle functionality for anonymous user as I couldn find a way to track if anonymous user is already registered or not.

  * Helper function to check if user is registered to a given event node or node.
function check_if_user_is_registered($node, $uid) {
   $return = FALSE;
   $registrations = node_registration_load_multiple(FALSE, array(
      'uid' => $uid,
      'nid' => $node->nid,
      'cancelled' => 0,
  if(is_array($registrations)) {
    foreach($registrations as $registration) {
      if($registration->author_uid == $uid) {
        $return = TRUE;
  return $return;

  *  Implements hook_node_load().
function MYMODULENAME_node_load($nodes, $types) {
  global $user;
  foreach ($nodes as $node) {
    if($node->type == "article") {
      $access = check_if_user_is_registered($node,$user->uid);
      if(!$access) {
       $node->comment = 0; // to close comments
  • Thanks! but I have only used existing modules (node registration modules), not custom ones...How can i do? Do you suggest me to create a new one by myself?
    – Luke
    Nov 18, 2013 at 14:32
  • check this packtpub.com/article/…
    – arpitr
    Nov 18, 2013 at 14:34
  • basically you need two files mymodulename.info which tells drupal about your custom module and mymodulename.module where your funcitonality lays down. remember "mymodulename" should be replaced by a standard name mostly the name should revolve around the functionality it adds.So the above code in the answer will go to the your .module file and the link shared in the comments can tell you what to add in the .info file
    – arpitr
    Nov 18, 2013 at 14:38
  • Thanks for the answer! Now i'm going to read it. I hope to understand..
    – Luke
    Nov 18, 2013 at 14:39
  • sure let me know if you have issues
    – arpitr
    Nov 18, 2013 at 14:45

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.