You are here

function privatemsg_recipient_access in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_recipient_access()
  2. 7.2 privatemsg.module \privatemsg_recipient_access()

This function is used to test if the current user has write/view access for a specific recipient type.

Parameters

$type_name: The name of the recipient type.

$permission: Which permission should be checked: 'write' or 'view'.

$recipient: Optionally pass in a recipient for which the permission should be checked. This only has effect if a the recipient type defines a callback function and is simply passed through in that case.

Return value

TRUE if the user has that permission (or not permission is defined) and FALSE if not.

Related topics

4 calls to privatemsg_recipient_access()
privatemsg_autocomplete in ./privatemsg.pages.inc
Return autocomplete results for usernames.
privatemsg_new in ./privatemsg.pages.inc
_privatemsg_load_thread_participants in ./privatemsg.module
Load all participants of a thread.
_privatemsg_parse_userstring in ./privatemsg.module
Extract the valid usernames of a string and loads them.

File

./privatemsg.module, line 2669
Allows users to send private messages to other users.

Code

function privatemsg_recipient_access($type_name, $permission, $recipient = NULL) {
  if ($type = privatemsg_recipient_get_type($type_name)) {

    // First check if a callback function is defined.
    if (!empty($type[$permission . ' callback']) && is_callable($type[$permission . ' callback'])) {
      $callback = $type[$permission . ' callback'];
      return $callback($recipient);
    }
    if (isset($type[$permission . ' access'])) {
      if (is_bool($type[$permission . ' access'])) {
        return $type[$permission . ' access'];
      }
      return user_access($type[$permission . ' access']);
    }
  }

  // If no access permission is defined, access is allowed.
  return TRUE;
}