_menu_item_is_accessible

Versions
4.6 – 5
_menu_item_is_accessible($mid)

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.

▾ 5 functions call _menu_item_is_accessible()

menu_execute_active_handler in includes/menu.inc
Execute the handler associated with the active menu item.
menu_get_active_help in includes/menu.inc
Returns the help associated with the active menu item.
_menu_append_contextual_items in includes/menu.inc
Account for menu items that are only defined at certain paths, so will not be cached.
_menu_build_local_tasks in includes/menu.inc
Find all the items in the current local task tree.
_menu_build_visible_tree in includes/menu.inc
Find all visible items in the menu tree, for ease in displaying to user.

Code

includes/menu.inc, line 848

<?php
function _menu_item_is_accessible($mid) {
  $menu = menu_get_menu();

  // Follow the path up to find the first "access" attribute.
  $path = $menu['items'][$mid]['path'];
  while ($path && (!array_key_exists($path, $menu['path index']) || !array_key_exists('access', $menu['items'][$menu['path index'][$path]]))) {
    $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'];
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.