Hi there,

I have made a menu item, and it works just fine, added it under "administration" menu, but when anonymous logs in, they can see it, how to hide from the normal user?

Comments

madhatter’s picture

Under Administer->Blocks, create a new block with this php code:

<?php
global $user;

$output = ' ';
if (is_array($user->roles) && in_array('admin', $user->roles)) {
  $output .= '<ul><li><a href="?q=[Drupal Path]">MyMenuItem</a></li></ul>';
}
return $output;
?>

In the [Drupal Path], write in the path to your node. For example, to link to the user search page, you would put in search/user (without the brackets) for the path. In the Input Format area, select the PHP code radio button.

And you need to disable the menu item in administer->menus because you don't want it to show up on your navigation menu. It's now inside the block.

cokeman’s picture

Sorry, I get the block, but no "link"... :(

- Regards

Michael
www.cokeman.dk

sepeck’s picture

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

cokeman’s picture

Thanks, got it working.... (Forgot to create the "gorup"), stupid me....

- Regards

Michael
www.cokeman.dk

sepeck’s picture

These things happen to us all at various times.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide