You are here

function privatemsg_user_access in Privatemsg 7

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

Privatemsg wrapper for user_access.

Never allows anonymous user access as that doesn't makes sense.

Parameters

$permission: Permission string, defaults to read privatemsg

Return value

TRUE if user has access, FALSE if not

Related topics

25 calls to privatemsg_user_access()
hook_privatemsg_view_alter in ./privatemsg.api.php
Add content to the view thread page.
pm_email_notify_form_alter in pm_email_notify/pm_email_notify.module
Implements hook_form_alter().
pm_email_notify_user_update in pm_email_notify/pm_email_notify.module
Implements hook_user_update().
privatemsg_check_format_access in ./privatemsg.pages.inc
After build callback; Hide format widget if user doesn't have permission.
privatemsg_delete in ./privatemsg.pages.inc

... See full list

3 string references to 'privatemsg_user_access'
pm_block_user_menu in pm_block_user/pm_block_user.module
Implements hook_menu().
privatemsg_filter_menu in privatemsg_filter/privatemsg_filter.module
Implements hook_menu().
privatemsg_menu in ./privatemsg.module
Implements hook_menu().

File

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

Code

function privatemsg_user_access($permission = 'read privatemsg', $account = NULL) {
  static $disabled_displayed = FALSE;
  if ($account === NULL) {
    global $user;
    $account = $user;
  }
  if (!$account->uid) {

    // Disallow anonymous access, regardless of permissions
    return FALSE;
  }
  if (privatemsg_is_disabled($account) && $permission == 'write privatemsg') {
    if (arg(0) == 'messages' && variable_get('privatemsg_display_disabled_message', TRUE) && !$disabled_displayed) {
      $disabled_displayed = TRUE;
      drupal_set_message(t('You have disabled Privatemsg and are not allowed to write messages. Go to your <a href="@settings_url">Account settings</a> to enable it again.', array(
        '@settings_url' => url('user/' . $account->uid . '/edit'),
      )), 'warning');
    }
    return FALSE;
  }
  if (!user_access($permission, $account)) {
    return FALSE;
  }
  return TRUE;
}