function messaging_message_send_user in Messaging 6.4
Same name and namespace in other branches
- 5 messaging.module \messaging_message_send_user()
- 6 messaging.module \messaging_message_send_user()
- 6.2 messaging.module \messaging_message_send_user()
- 6.3 messaging.module \messaging_message_send_user()
Send message to user represented by account
We are applying same output filter for everybody, depending on send method
The final rendering of the message depends on send method too. I.e. a mail messaging method may want to insert '--' before the body footer.
@ TODO Consider whether it makes sense to allow users decide on formatting
Parameters
$account: User object to recieve message.
$message: Array of message parts that will be compiled depending on send method. Mandatory message parts, which may have nexted parts are:
- 'type'
- 'subject'
- 'body'. The message body may have 'header', 'content', 'footer', 'etc'
$method: Optional send method. Defaults to the user account predefined method
4 calls to messaging_message_send_user()
- messaging_admin_test_post_form_submit in ./
messaging.admin.inc - Post test message
- Messaging_API_Tests::testMessagingBasicAPI in tests/
messaging_api.test - Exercise basic API functions
- messaging_message_bulk_send in ./
messaging.module - Send message to multiple users. For each user it will use the preferred method
- Messaging_Methods_Tests::testMessagingMethods in tests/
messaging_methods.test - Test message sending callbacks for enabled plug-ins
File
- ./
messaging.module, line 291
Code
function messaging_message_send_user($account, $message, $method = NULL, $queue = FALSE) {
messaging_debug('Sending message to user', array(
'account' => $account,
'message' => $message,
'method' => $method,
));
// Build array of parameters so they can be overridden by callbacks
$message = messaging_message_build($message);
if (isset($method)) {
$message->method = $method;
}
// Check user and availability if there's a callback for that. Depending on the sending method,
// when user is not available it may just be discarded / queued / redirected through other method
if ($message
->set_user($account)) {
messaging_debug('Found destination for user, sending message', array(
'method' => $message->method,
'destination' => $message->destination,
));
return $queue ? $message
->queue() : $message
->send();
}
else {
watchdog('messaging', 'Cannot send message to user !username. @message', array(
'!username' => theme('username', $account),
'@message' => (string) $message,
), WATCHDOG_WARNING);
return FALSE;
}
}