You are here

function hook_privatemsg_message_validate in Privatemsg 6.2

Same name and namespace in other branches
  1. 6 privatemsg.api.php \hook_privatemsg_message_validate()
  2. 7.2 privatemsg.api.php \hook_privatemsg_message_validate()
  3. 7 privatemsg.api.php \hook_privatemsg_message_validate()

Validate a message before it is sent/saved in the database.

Validation errors can be returned, either as a string or as array when there are multiple errors. If the $form flag is set, errors should be reported with form_set_error instead.

@todo adapt api return value changes

Parameters

$message: Message array

Related topics

1 function implements hook_privatemsg_message_validate()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

privatemsg_limits_privatemsg_message_validate in privatemsg_limits/privatemsg_limits.module
Implements hook_privatemsg_message_validate().
1 invocation of hook_privatemsg_message_validate()
_privatemsg_validate_message in ./privatemsg.module

File

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

Code

function hook_privatemsg_message_validate($message, $form = FALSE) {
  global $_privatemsg_invalid_recipients;
  $_privatemsg_invalid_recipients = array();
  $errors = array();
  foreach ($message['recipients'] as $recipient) {
    if ($recipient->name == 'blocked user') {
      $_privatemsg_invalid_recipients[] = $recipient->uid;
      $errors[] = t('%name has chosen to not recieve any more messages from you.', array(
        '%name' => privatemsg_recipient_format($recipient, array(
          'plain' => TRUE,
        )),
      ));
    }
  }
}