Send private message snippet

Last modified: April 11, 2007 - 19:31

PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

Description

This php snippet inserts the SEND A PRIVATE MESSAGE link

Dependencies: privatemsg.module must be installed and enabled.

Usage

  • For use in your user profile page override
  • Copy and paste the code into your user_profile.tpl.php file
  • Change the div class name or the link text to suit.

<?php if (user_access('access private messages') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) { ?>
<?php $frommetoprofileuser = arg(1); ?>
<div class="fields">
<?php print l(t('Send a private message to ').$user->name, 'privatemsg/msgto/'. $frommetoprofileuser); ?>
</div>
<?php } ?>

Hide link when on your own page

<?php
if (arg(0) == 'user' && is_numeric(arg(1))) {
   
$node = node_load(arg(1));
    if (
$node->uid == $user->uid) {
      echo ;
    }

    else {
  print
l('Send a message to '.$user->name, 'privatemsg/msgto/'. $user->uid);
 
   }
  }
?>

Working Snippet for Drupal 5.x (I used 5.7 and Privatemsg 1.8)

Glowingtree - March 20, 2008 - 20:46

just put this in the user_profile.tpl.php file or custom block....

<?php
   
print l('Send me a message',"privatemsg/msgto/".$user->uid);  
?>

$user->uid is already referring to the owner of the user_profile.tpl.php page regardless
of the logged in user - good enough solution for starters, though
users would still have it on their own page - However on top of this you could do a simple " if - else"
statement...

<?php
        
 
if  ($user->uid != ($GLOBALS['user']->uid) )
        
         { print
l('Send This User a Private Message',"privatemsg/msgto/".$user->uid); }

         elseif (
$user->uid == ($GLOBALS['user']->uid) ) 
        
         { print (
'') ; }
?>

and I actually tried it! It actually worked! (Drupal 5.7)

And of course, you would want to put in some DIVs in proper place so you can give it a CSS class.
You could just put a div around the whole thing and used contextual CSS selection to style the A tag. i.e.

" div.msg-me-link a "

however if you want to style it as a box the box would be there wether the link is there or not...
(not sure about syntax for conditional printing of html tags, the " " to give the div the class would
kill the link syntax used in the PHP above, any suggestions?)

 
 

Drupal is a registered trademark of Dries Buytaert.