Message hooks

  1. privatemsg
    1. 1 privatemsg.api.php
    2. 6-2 privatemsg.api.php
    3. 7-1 privatemsg.api.php
    4. 7-2 privatemsg.api.php

All message-level hooks look like hook_privatemsg_message_op, where op is one of the following:

  • load: Called when a full message is loaded similiar to nodeapi_load, new values can be returned and will be added to $message, parameter: $message
  • validate: Validation, before the message is sent/saved. Return validation errors as array, parameter: $message, $form = FALSE
  • presave_alter: Last changes to $message before the message is saved, parameter: $message
  • insert: message has been saved, $message has been updated with the mid and thread_id, parameter: $message
  • delete: the message is going to be deleted, parameter: $message
  • view_alter: the message is going to be displayed, parameter: $vars
  • recipient changed: a recipient is added or removed from/to a message.

In hooks with _alter suffix, $message is by reference.

$message is an array, with all the relevant information about the message. The information in there can be changed/extended by modules, but looks typically like this:

array (
  'mid' => 3517, // message id, identifies a message
  'author' => 27, // author id
  'subject' => 'raclebugav', // Message subject
  'body' => 'bla bla', // Body of the message
  'timestamp' => 351287003, // unix timestamp, creation time
  'is_new' => 0, // If the message has been read by the user
  'thread_id' => 3341, // thread id, this is actually the mid from the first
                          message of the thread
)

Functions & methods

NameDescription
hook_privatemsg_message_flushIs called when a message is flushed.
hook_privatemsg_message_insertThis hook is executed after the message has been saved.
hook_privatemsg_message_presave_alterChange the message before it is stored.
hook_privatemsg_message_recipient_changedThis hook is invoked when a recipient is added to a message.
hook_privatemsg_message_validateValidate a message before it is sent/saved in the database.
hook_privatemsg_message_view_alterAct on the $vars before a message is displayed.

File

./privatemsg.api.php, line 146
Privatemsg API Documentation

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.