Hello,

On my site I need to keep comments hidden from other authors and comments hidden from other commenters. The reason being I don't want authors seeing comments on other authors nodes and I don't want commenters being influenced by previous comments. I've nearly accomplished that with the following if condition in my comment.tpl.php file.

<?php
global $user;
?>
<?php if (($comment->uid==$user->uid) || (in_array('author_role', $user->roles))) : ?>
// Code
<?php endif; ?>

As you can see the above code will successfully make comments viewable to only the commenter. But the second OR condition will restrict viewable comments to anyone in the author_role. This won't work since I need only the author of a node to see all of the comments belonging to it.

If anyone out there would be kind enough to help me finish this logic up I would greatly appreciate it.

Comments

WorldFallz’s picture

I don't believe the node is loaded during comments so you'll need to do something like:

<?php
global $user;
$node = node_load($comment->nid);
?>
<?php if (($comment->uid==$user->uid) || ($user->uid == $node->uid)) : ?>
// Code
<?php endif; ?>

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

Grimlock’s picture

You saved me a lot of hair pulling, thank you.

WorldFallz’s picture

lol, you're very welcome.

one thing you might want to keep in mind-- that's going to do a node_load for each comment. If you have lots of comments per node and notice a slowdown, that code might be the culprit (though in general node_loads aren't too bad).

also, it always makes me nervous to do access control in the theme layer, but I can't think of any way around it off the top of my head.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

Grimlock’s picture

Awesome!

Thanks for all your help and the two caveats. You're the man.

WorldFallz’s picture

or wo-man, lol.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

Grimlock’s picture

Yeah I didn't look at your profile, my apologies,

You're the woman!

ocamp’s picture

hi, sorry to bring up an old post, but im trying to do the same,

I tried using this code but dont think its working.

I noticed this is for drupal 5 but im using 6, would this make a difference?

Thanks for any help

Ivanhoe123’s picture

You can use $node object directly in comment.tpl.php

Example:

if($node->type=='contenttype'){
// Your code
}

Also, AFAIK, the arguments for function node_load must be in array, at least in drupal 6

ocamp’s picture

thanks for the help, butstill not sure what I should be doing

MOB Design’s picture

Thanks so much, this seems to be working well. I've tried numerous other ways to acheive the same thing with very limited success, Thanks Grimlock.