You are here

function _menu_per_role_access in Menu Per Role 6

Same name and namespace in other branches
  1. 7 menu_per_role.module \_menu_per_role_access()
1 call to _menu_per_role_access()
menu_per_role_translated_menu_link_alter in ./menu_per_role.module

File

./menu_per_role.module, line 37
Allows restricting access to menu items per role

Code

function _menu_per_role_access($item) {
  global $user;
  if (empty($item['mlid'])) {

    // no menu indicated, there's nothing to block
    return NULL;
  }
  if ($user->uid == 1) {

    // UID=1 is the all almighty administrator who usually sees everything
    // (a better way would be to mark the menu item with a special class
    // so it could be shown in a different color.)
    if (variable_get('menu_per_role_uid1_see_all', 1)) {
      return NULL;
    }
  }
  elseif (user_access('administer menu_per_role') && variable_get('menu_per_role_admin_see_all', 0)) {

    // The top administrator can also give the menu_per_role administrators
    // access to all the menu items.
    return NULL;
  }

  // if this menu is being edited, make sure the administrator sees all of its items
  if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'menu-customize' && arg(3) == $item['menu_name']) {
    return NULL;
  }

  // check whether this role has visibility access (must be present)
  $rids = _menu_per_role_get_roles($item['mlid'], 0);
  if (!empty($rids) && count(array_intersect($rids, array_keys($user->roles))) == 0) {

    // not permitted by the rids...
    return FALSE;
  }

  // check whether this role has visibility access (must not be present)
  $hrids = _menu_per_role_get_roles($item['mlid'], 1);
  if (!empty($hrids) && count(array_intersect($hrids, array_keys($user->roles))) > 0) {

    // not permitted by the hrids...
    return FALSE;
  }

  // this module is not preventing user from seeing this menu entry
  return NULL;
}