Patch to not show links to which the user does not have permissions to access.
sopris - February 21, 2007 - 20:46
| Project: | Adminmenu Dhtml |
| Version: | 4.7.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | sopris |
| Status: | active |
Description
Hi,
For what its worth, I love the admin menu! I wanted to remove links that the user ultimately cannot access... ie... dont show them if they cant access them.
This little patch works perfectly.. (for me), your mileage may vary.... its a bit hokey granted. ; )
function _admin_menu_get_children(&$admin_items, &$item) {
global $_menu;
global $user;
if (isset( $item['children'] )) {
foreach ($item['children'] as $child) {
// old line
// $is_visible_item = $_menu['items'][$child]['type'] & (MENU_VISIBLE_IN_TREE | MENU_IS_LOCAL_TASK);
// new line: remove entries which should not be viewable in the menu
$is_visible_item = ( $user->uid == 1 || $_menu['items'][$child]['access'] ) ? 1: 0;
// create the child item if it's visible in navigation
// Hide items linking to parent: && !($_menu['items'][$child]['type'] & MENU_LINKS_TO_PARENT) 12/01/2007 sun
if ($is_visible_item) {
$admin_items[$child] = $_menu['items'][$child];
// recurse to child menu items
if (isset( $_menu['items'][$child]['children'] )) {
_admin_menu_get_children($admin_items, $admin_items[$child]);
}
// remove this child item if it's visible in navigation
unset( $_menu['visible'][$child] );
}
else {
// remove child menu item from parent's children list
$parent_id = $_menu['items'][$child]['pid'];
$child_key = array_search($child, $_menu['items'][$parent_id]['children']);
if ($child_key !== FALSE) {
unset( $admin_items[$parent_id]['children'][$child_key] );
}
}
}
// sort remaining items
usort($item['children'], '_menu_sort');
}
}