function privatemsg_roles_write_access

7-2 privatemsg_roles.module privatemsg_roles_write_access($recipient)
6-2 privatemsg_roles.module privatemsg_roles_write_access($recipient)

Write permission check for roles recipients.

2 string references to 'privatemsg_roles_write_access'
hook_privatemsg_recipient_type_info in ./privatemsg.api.php
This hook is used to tell privatemsg about the recipient types defined by a module. Each type consists of an array keyed by the internal recipient type name and the following keys must be defined.
privatemsg_roles_privatemsg_recipient_type_info in privatemsg_roles/privatemsg_roles.module
Implements hook_privatemsg_recipient_type_info().

File

privatemsg_roles/privatemsg_roles.module, line 61
Allows to send messages to all members of a role.

Code

function privatemsg_roles_write_access($recipient) {

  // Check if user has permission to write to all roles.
  if (user_access('write privatemsg to all roles')) {
    return TRUE;
  }

  if ($recipient) {
    if (empty($recipient->name)) {
      $recipient = array_shift(privatemsg_roles_load_multiple(array($recipient->recipient), $recipient->type));
    }
    // Check permission for this recipient.
    return user_access('write privatemsg to role ' . $recipient->name);
  }
  // Check if user has permission to write at least one role.
  foreach (user_roles(TRUE) as $role) {
    if (user_access('write privatemsg to role ' . $role)) {
      return TRUE;
    }
  }
  // No permission, return FALSE.
  return FALSE;
}