0

I added a custom admin menu item which I'd like to show up for non-admin users with specific roles. Is there a way to accomplish this?

Thanks in advance! Lee

apaderno
  • 28,547
  • 16
  • 75
  • 90
LEN
  • 35
  • 1
  • 10

1 Answers1

1

Create custom access callback in your custom hook_menu:

//custom hook_menu() 
$items['menu'] = array(
  ................. 
  'access callback' => 'my_custom_callback' 
); 

function my_custom_callback() { 
 global $user; 
 if (in_array('[YOUR_ROLE]', array_values($user->roles))) {
    return TRUE; 
  }
} 
prabeen giri
  • 803
  • 7
  • 18
  • Thanks! I started to implement this yesterday, but got sidetracked w/ other work. I was having trouble with the solution, unfortunately - I'll try to get back to it soon and post details... – LEN Aug 09 '13 at 04:28
  • Before getting back to your suggestion, I tried to get the menu item to show up regardless of role, which wasn't happening to begin with (it was only showing for Drupal admin). In the process of moving the page around in the admin menu and eventually back to where I had it originally (above Administration in the Management menu), and after much clearing of the cache along the way, it actually started to show up for users with more restricted roles. Since all authenticated users (members of 3 different non-admin roles) need to see this page, that is sufficient. – LEN Aug 11 '13 at 07:14