How can I add a flag for reporting abuse on private messages using hook_privatemsg_message_view_alter()? I have a flag on my Drupal 7 site for alerting moderators regarding potential abuse.

I want a link to this flag to be displayed next to the Delete and Block links on the view private message screen (messages/view) provided by the Private Message module.

By inserting the following code below the code for the delete link (line 769) in the latest version of the module, I can render the link correctly.

$author = $vars['message']-&gt;author;
$vars['message_actions'][] = array('title' =&gt; t('Report abuse'), 'href' =&gt; 'flag/confirm/flag/abuse/flag/block/' . $author-&gt;uid .  '?destination=user/' . $author-&gt;uid );


However, I don't want to hack the module; I want to add this code to a custom module.  hook_privatemsg_message_view_alter() appears to be the function for this, but I don't understand how to use it.  Simply inserting the above code and calling the function from within my custom module does not result in any errors but the link is not displayed.  What do I need to show the link?

EDIT: The solution need not use hook_privatemsg_message_view_alter(); if there is a better way that doesn't involve hacking privatemsg, I'd be happy to hear of it.
I really don't know why you don't like the answer by Rene.

Let me show a more detailed example.
You have to replace YOURMODULE with name of your module or theme.

/**
 * Implements hook_privatemsg_message_view_alter().
 * The &amp; for param $vars is important: we pass it by reference.
 */
function YOURMODULE_privatemsg_message_view_alter(&amp;$vars) {
  // Message author
  $uid = $vars['message']-&gt;author-&gt;uid;
  // Get flag for abusing user
  $flag = flag_get_flag('abuse_user');
  // Make flag module to check permissions
  if ($flag-&gt;access($uid)) {
    // Use flag API to show a flag according to flag preferences
    $vars['message_actions']['flag-'. $flag-&gt;name] = array(
      'title' =&gt; $flag-&gt;theme($flag-&gt;is_flagged($uid) ? 'unflag' : 'flag', $uid),
      'html' =&gt; TRUE,
    );
  }
}


Here I'm using a flag with name 'abuse_user':

You can edit Flag labels, link type and permissions here.
The result:
  

Please, feel free to ask questions.