You are here

function views_access in Views (for Drupal 7) 5

Same name and namespace in other branches
  1. 8.3 views.module \views_access()
  2. 6.3 views.module \views_access()
  3. 6.2 views.module \views_access()
  4. 7.3 views.module \views_access()

Determine if the specified user has access to a view.

2 calls to views_access()
views_view_block in ./views.module
This views a view by block. Can be used as a callback or programmatically.
_views_create_menu_item in ./views.module
Helper function to add a menu item for a view.

File

./views.module, line 292

Code

function views_access($view, $account = NULL) {
  if (!$account) {
    global $user;
    $account = $user;
  }

  // Administrator privileges
  if (user_access('access all views', $account)) {
    return TRUE;
  }

  // All views with an empty access setting are available to all roles.
  if (!$view->access) {
    return TRUE;
  }

  // Otherwise, check roles
  static $roles = array();
  if (!isset($roles[$account->uid])) {
    $roles[$account->uid] = array_keys($account->roles);
    $roles[$account->uid][] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
  }
  return array_intersect($view->access, $roles[$account->uid]);
}