Send private message snippet

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?)

delete please

Kit_Hally - February 7, 2009 - 14:12

please delete my post

With Drupal 6.x it would be

lelizondob - March 11, 2009 - 12:43

With Drupal 6.x it would be something like this:

<?php
if (user_access('access private messages') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
   
$frommetoprofileuser = arg(1);
    if (
arg(0) == 'user' && is_numeric(arg(1))) {
            if (
$account->uid == $user->uid) {
                echo
'';
            }
            else {
            print
l(t('Send a message to ').$account->name, 'messages/new/'. $frommetoprofileuser);
         }
        }
    }
?>

Luis

Drupal 6

merchadmin - March 29, 2009 - 13:20

Unfortunately, this snippet does not work for me with drupal 6. I am at a loss to find a snippet or static link to send a private message to another user.

Strangely enough, the original link on the profile page to send a private message just disappeared. I can't say if it was something with my css or what is the reason, but I would really like to be able to customize my own anyway.

Can anyone tell me what in the world would be the proper way to put a static link to send a private message to the corresponding profile page?

It would be much, much appreciated, I assure you!
Thanks in advance, of course.

With Drupal 6.x <?php print

lelizondob - March 29, 2009 - 18:32

With Drupal 6.x

<?php print $profile[privatemsg_send_new_message]; ?>

Will do the job and it's the right way to do it since you're using the block created by the module. This also prevents the link from showing up when the user it's viewing it's own profile page.

Luis

Still not working

merchadmin - April 11, 2009 - 20:56

Again, this link will not show in a block on any page, let alone profile page.

I have figured out, tho, that it was the My Account Alter module that made the original link fro privatemsg module disappear. When I disable My_Account Alter, then the privatemsg link returns. Unfortunately, without the my_account alter module, the profile page is a mess.

I have been trying to get this link to appear in a block to put in a content header on the profile page but I just can't seem to get it going.

By any chance, do you have any more ideas?

not really, the only thing I

lelizondob - April 12, 2009 - 00:51

not really, the only thing I could suggest is to configure every aspect of the profile page... it's not that hard and you could have amazing results.

Luis

<?php        if

mouse77e - July 12, 2009 - 08:42

<?php
        if ($profileuser->uid == $loggedinuser->uid) {
          print "&nbsp";
         } else {
           if (user_access('access private messages') && (isset($profileuser->privatemsg_allow) ? $profileuser->privatemsg_allow : 1)) {
              print l(' ' .theme_image(path_to_theme() .
              "/images/profile/user_comment.png", $alt = 'Private Message', $title = 'Private Message', $attributes = NULL, $getsize = TRUE),
               'privatemsg/msgto/'. $profileuser->uid,NULL,NULL,NULL,NULL,TRUE);
            }
        }

Can anyone help please on this topic the above code worked well with Privatemsg 1.8 but broke in 3.0 a bit stuck
Many thanks

did you try using <?php

lelizondob - July 13, 2009 - 15:33

did you try using

<?php print $profile[privatemsg_send_new_message]; ?>

instead of the code you're providing?

Luis

thnx a lot

derbenito - July 24, 2009 - 12:15

Hi,

@lelizondob you code helped me ;).
Thnx
Benitoi

to answer my own question

mouse77e - July 29, 2009 - 12:19

'privatemsg/msgto/'. $profileuser->uid,NULL,NULL,NULL,NULL,TRUE);

becomes

'privatemsg/new/'. $profileuser->uid,NULL,NULL,NULL,NULL,TRUE);

hope that clears things up!

 
 

Drupal is a registered trademark of Dries Buytaert.