I have read through the dozens of posts on role based menus and have come up with this hack. Place this code in a new block.
I would like to see this vastly improved/modified upon because as far as I know there is still no built in support for this.
Things to improve include:
1) More than one level of depth
2) A gui form/database table to handle assigning of roles to menu items.
3) Hook this into the drupal core (I don't know much about drupal modules or the api so need help here)
As a side note, I use the 'nice menus' module and wonder if anyone knows how to modify this to dynamically generate an actual menu tree (instead of printing off the pieces), so that I could easily feed this into the 'nice menus' module.
<?php global $user;
/****
@author Brian Danchilla
@date June 27, 2006
@brief A hack to get custom role based menus. As is, only goes one level deep. Could expand program and use custom database table for storage of roles/disallowed menu items.
****/
if($user->uid == 1){
//admin gets full menu
print(theme_menu_tree(2));
}else{
//set root menu, replace 2 with actual mid
$rootMenu = menu_get_item(2);
//disallow certains roles for different users
if($user->uid == 5){
$disallowedItems = array(36, 46);
}else if($user->uid == 358){
$disallowedItems = array(93, 100);
}
/**
@brief usort function to sort menus. Here the order is is by weight then title