Howto limit access to a main menu link using drupal 7 api in my scenario I am using Drupal 7 with the ubercart modules. I like to add a link in my main menu that is only visible if you are an authenticated user. 

For testing purposes I am using the bartik theme. 

It is the same function like user/login, which is only visible if you are an anonymus user.

I found some hints and even examples in the drupal api - like

https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu_alter/7

The following implements hook_menu_alter to remove access to the "forum" tab for the anonymous user:

/**
* Implements hook_menu_alter.
* Check access for forum menu item.
*/
function MYMODULE_menu_alter(&amp;$items) {
$items['forum']['access callback'] = '_accesscheck';
}

/**
* Callback to disallow access for the anonymous user.
*/
function _accesscheck(){
  global $user;
 return $user-&gt;uid;
}


Even after many attempts, I can't catch a value for $items, I was using main_menu.

I like to use the function in the theme template. How can I find the variables that I need to alter one item of my menu - I called it > cart &lt;.

I even tried to print_r($items), but nothing was found.

How can I retrieve $items for the main menue
hook_menu_alter only gets executed when you clear cache or rebuilding menu. I would suggest if you want to debug the $items variable, What I used to do
is do print_r($items) and die() after that. Then I would try to clear the cache from the admin UI or save it into watchdog for debugging.