Same name and namespace in other branches
  1. 4.6.x includes/menu.inc \_menu_item_is_accessible()
  2. 4.7.x includes/menu.inc \_menu_item_is_accessible()

Determine whether the given menu item is accessible to the current user.

Use this instead of just checking the "access" property of a menu item to properly handle items with fall-through semantics.

1 call to _menu_item_is_accessible()
_menu_build_visible_tree in includes/menu.inc
Find all visible items in the menu tree, for ease in displaying to user.

File

includes/menu.inc, line 1157
API for the Drupal menu system.

Code

function _menu_item_is_accessible($mid) {
  $menu = menu_get_menu();

  // Follow the path up to find the first "access" attribute.
  $path = isset($menu['items'][$mid]['path']) ? $menu['items'][$mid]['path'] : NULL;
  while ($path && (!isset($menu['path index'][$path]) || !isset($menu['items'][$menu['path index'][$path]]['access']))) {
    $path = substr($path, 0, strrpos($path, '/'));
  }
  if (empty($path)) {

    // Items without any access attribute up the chain are denied, unless they
    // were created by the admin. They most likely point to non-Drupal directories
    // or to an external URL and should be allowed.
    return $menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN;
  }
  return $menu['items'][$menu['path index'][$path]]['access'];
}