I have 3 roles on site:
- anonymous user
- authenticated user
- admin
I created a new page:
function learning_menu()
{
$items = array();
$items['learning'] = array(
'page callback' => 'learning_output',
'access callback' => 'learning_access',
'type' => MENU_CALLBACK,
);
return $items;
}
I manually created a menu item for this page in the top menu. This item should be displayed only for authenticated users, but not admins. Unfortunately, admin as also an authenticated user. So I had to use a trick to disallow access to this page to admins using this access callback:
function learning_access()
{
global $user;
$n = count($user->roles);
if ($n === 1)
{
$data = array_values($user->roles);
if ($data[0] === 'authenticated user')
{
return true;
}
}
return false;
}
It works but when I uploaded this module to server, I was unable to manually add a menu item for this page. Because admin doesn't have access to it.
How can I allow an admin to access this page? In the same time the menu item shouldn't be shown for him.