Send private message snippet
Task · insert a Send Private Message link · theme private messages · Developers and coders · Themers · Drupal 4.5.x or older · Drupal 4.6.x · Drupal 4.7.x
Last modified: August 26, 2009 - 22: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)
just put this in the user_profile.tpl.php file or custom block....
<?phpprint 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
please delete my post
With Drupal 6.x it would be
With Drupal 6.x it would be something like this:
<?phpif (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
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
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
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
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
<?phpif ($profileuser->uid == $loggedinuser->uid) {
print " ";
} 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
did you try using
<?php print $profile[privatemsg_send_new_message]; ?>instead of the code you're providing?
Luis
thnx a lot
Hi,
@lelizondob you code helped me ;).
Thnx
Benitoi
to answer my own question
'privatemsg/msgto/'. $profileuser->uid,NULL,NULL,NULL,NULL,TRUE);becomes
'privatemsg/new/'. $profileuser->uid,NULL,NULL,NULL,NULL,TRUE);hope that clears things up!