I know that this question had been asked several times, but it seems like all existing answers only apply to ealier versions of Privatemsg module. I am running 7.x-2.x-dev and I would like to programatically render the "Send this user a private message" link. The PHP code is supposed to be the $block['content']
of a programatically created block that will be displayed on user pages.
Somebody suggested to use
if ($account = menu_get_object('user') ) {
if ($url = privatemsg_get_link(array($account))) {
$block['content'] = l(t('Send this user a private message'), $url, array('query' => drupal_get_destination()));
}
}
but this is doing absolutely nothing.
I also want that the link is only displayed if the viewed user has enabled the "Enable private messages" option in his/her account settings and if the viewing user has permission to send messages. Any ideas how to achieve this?