I currently have:

<?php if (user_access('access private messages')) : ?>
<div><a href="/privatemsg/msgto/<?php print $node->uid; ?>">Private Message</a></div>
<?php endif; ?>

in my forum template. Which is great. Only viewing members who can send PM's get to see that link. However, I would like to alter the conditional code so that it also only shows on forum posts by members who have PM privileges.

as I have it set up now, someone with PM permission could click on a link but then find out the DESTINATION member for the PM doesn't have PM permissions - so I need a check at both ends of the equation, not just at the viewing member as I do currently.

could anyone help with that?

Comments

jdevries’s picture

I came across this post while searching for something completely different. I don't know if you've ever figured out how to do it (seeing the question was asked nearly a month ago), but if not, here is one way of doing what you want. I dont't know if it's the best though, I'm still a learning programmer.

Anyway, the user object of the author contains a variable that determines if he or she has allowed private messages. This should work for what you want:

  $author = user_load(array('uid' => $node->uid));
  if ($author->privatemsg_allow) {
    print 'Yes, the author allows private messages.';
  } else {
    print 'No, the author does not allow private messages.';
  }
esllou’s picture

I'll try this later on. Will it work in something like a forum.tpl.php file where there would be 20 different users loaded up to view a whole thread? Or is it something for a profile page, etc where the whole "node" is only about that one user?

jdevries’s picture

The code snippet can be used in any node. For forum use you will probably need to substitute

$author = user_load(array('uid' => $node->uid));
for
$author = user_load(array('uid' => $comment->uid));

On my own site I only check for the privatemsg_allow variable on a profile page, but the user is already loaded there. I mainly decided to do so, because each user_load() call costs at least one database query (see API documentation). I don't know what kind of performance you'll suffer if you need to call user_load() 20 times on a page. You'll need a more expert opinion than mine to answer that question.

esllou’s picture

I have a template for forum/comment.tpl.php that is quite vBulletiny...so "Send PM" is one of the links included in every post. Maybe it's a touch of overkill:

John
Location: Texas, USA
Number of Posts: 219
View John's Profile
Send PM to John

that's what the left div in my forum/comments looks like. So that's a good few db queries every post...hmmmm!