You are here

function user_relationship_privatemsg_check_write_access in User Relationships 7

1 string reference to 'user_relationship_privatemsg_check_write_access'
user_relationship_privatemsg_privatemsg_recipient_type_info in user_relationship_privatemsg/user_relationship_privatemsg.module
Implements hook_privatemsg_recipient_types_info().

File

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

Code

function user_relationship_privatemsg_check_write_access($relationship = NULL) {
  global $user;

  // Users are only allowed to write their own related users.
  if ($relationship) {
    if (!isset($relationship->account)) {
      $author = db_query('SELECT author FROM {user_relationship_privatemsg} WHERE urpid = :urpid', array(
        ':urpid' => $relationship->recipient,
      ))
        ->fetchField();
      $relationship->account = user_load($author);
    }
    if ($relationship->account->uid != $user->uid) {
      return FALSE;
    }
  }
  return user_access('write privatemsg to relationships');
}