You are here

function user_relationship_privatemsg_restrict in User Relationships 7

Check if the current user should be restricted.

Parameters

$author: User object of the message author.

$check_permission: If TRUE, this only applies if all users are restricted by default.

Return value

FALSE if the current user should be not be restricted, TRUE otherwise.

2 calls to user_relationship_privatemsg_restrict()
user_relationship_privatemsg_privatemsg_block_message in user_relationship_privatemsg/user_relationship_privatemsg.module
Implements hook_privatemsg_block_message().
user_relationship_privatemsg_query_privatemsg_autocomplete_alter in user_relationship_privatemsg/user_relationship_privatemsg.module
Implements hook_query_privatemsg_autocomplete_alter().

File

user_relationship_privatemsg/user_relationship_privatemsg.module, line 260
Allows to send messages to all members of a role.

Code

function user_relationship_privatemsg_restrict($author, $check_permission = TRUE) {

  //#522078 admin killswitch, always ignore this for user 1.
  if ($check_permission && variable_get('user_relationships_restrict_privatemsg', 'all') == 'all' || $author->uid == 1) {
    return FALSE;
  }
  $exclude_roles = array_filter(variable_get('user_relationships_privatemsg_role_exclusions', array()));

  // First, make sure that we have a user object with roles, and then check if
  // the users does have any of the excluded roles.
  if (!empty($author->roles) || ($author = user_load($author->uid))) {
    $is_excluded = array_intersect(array_keys($author->roles), $exclude_roles);
    if (!empty($is_excluded)) {
      return FALSE;
    }
  }
  return TRUE;
}