You are here

function privatemsg_recipient_access in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 privatemsg.module \privatemsg_recipient_access()
  2. 7 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

5 calls to privatemsg_recipient_access()
privatemsg_autocomplete in ./privatemsg.pages.inc
Return autocomplete results for usernames.
privatemsg_new in ./privatemsg.pages.inc
Form builder function; Write a new private message.
_privatemsg_get_allowed_recipients in ./privatemsg.pages.inc
Check if the current user is allowed to write these recipients.
_privatemsg_load_thread_participants in ./privatemsg.module
Load all participants of a thread, optionally without author.
_privatemsg_parse_userstring in ./privatemsg.module
Extract the valid usernames of a string and loads them.

File

./privatemsg.module, line 2763
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 $types[$permission . ' access'];
      }
      return user_access($type[$permission . ' access']);
    }
  }

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