You are here

function user_relationships_api_privatemsg_block_message in User Relationships 6

Blocks messages to users that are not in relationships with sender.

See also

hook_privatemsg_block_message()

File

user_relationships_api/user_relationships_api.privatemsg.inc, line 28
Integration with Privatemsg module @author mansspams http://drupal.org/user/293179 @author alex.k http://drupal.org/user/183217

Code

function user_relationships_api_privatemsg_block_message($author, $recipients) {

  // Check if $author needs to be restricted.
  if (!user_relationships_api_privatemsg_restrict($author)) {
    return;
  }
  $blocked = array();
  foreach ($recipients as $recipient) {

    //block if user is only receiving pm's from his relationships, and author is not one of them
    if ((variable_get('user_relationships_restrict_privatemsg', 'all') == 'relationships' || variable_get('user_relationships_restrict_privatemsg', 'all') == 'all_overridable' && $recipient->user_relationships_allow_private_message == 'on in relations') && !module_invoke_all('socnet_is_related', $author->uid, $recipient->uid)) {
      $blocked[] = array(
        'uid' => $recipient->uid,
        'message' => t('!name is not a friend of yours.', array(
          '!name' => theme('username', $recipient),
        )),
      );
    }
  }
  return $blocked;
}