function user_relationship_privatemsg_privatemsg_block_message in User Relationships 7
Implements hook_privatemsg_block_message().
File
- user_relationship_privatemsg/
user_relationship_privatemsg.module, line 209 - Allows to send messages to all members of a role.
Code
function user_relationship_privatemsg_privatemsg_block_message($author, $recipients) {
// Check if $author needs to be restricted.
if (!user_relationship_privatemsg_restrict($author)) {
return;
}
$blocked = array();
foreach ($recipients as $recipient) {
if (isset($recipient->type) && $recipient->type != 'user' && $recipient->type != 'hidden') {
continue;
}
// Don't block if the user is writing himself.
if ($author->uid == $recipient->uid) {
continue;
}
//block if user is only receiving pm's from his relationships, and author is not one of them
$user_setting = isset($recipient->data['user_relationships_allow_private_message']) ? $recipient->data['user_relationships_allow_private_message'] : 'on all users';
$setting = variable_get('user_relationships_restrict_privatemsg', 'all');
if ($setting == 'relationships' || $setting == 'all_overridable' && $user_setting == 'on in relations') {
// Check if author is related.
$relations = user_relationships_load(array(
'between' => array(
$author->uid,
$recipient->uid,
),
));
// Remove pending relationships.
foreach ($relations as $rid => $relation) {
if ($relation->requires_approval && empty($relation->approved)) {
unset($relations[$rid]);
}
}
if (empty($relations)) {
$blocked[] = array(
'recipient' => privatemsg_recipient_key($recipient),
'message' => t('!name does not have an established relationship with you.', array(
'!name' => privatemsg_recipient_format($recipient),
)),
);
}
}
}
return $blocked;
}