I am creating my own shortcut bar but can't manage the user access I am creating a shortcut bar something like below, but unfortuntly it show up despite my wish that I could hide it for anonymous and administrator users/role. I want to display it for editor roles only. How do I achieve this? Thanks

function shortcat_permission() {
  return array(
    'administer shortcat' =&gt; array(
      'title' =&gt; t('Administer shortcats'),
      'restrict access' =&gt; TRUE,
    ),
  );
}

function shortcat_page_alter(&amp;$page) {
       $page['page_top']['#pre_render'][] = 'shortcat_toolbar_pre_render';
   }



function shortcat_renderables() {

  $shortcut_set = array();
  $shortcut_set['my_list'][] = array("#markup" =&gt;"&lt;ul&gt;");
  $shortcut_set['my_list'][] = array("#markup" =&gt;"&lt;li&gt;&lt;a href='node/add' class='shlinks'&gt;".t('Add Content')."&lt;/a&gt;&lt;/li&gt;");
  $shortcut_set['my_list'][] = array("#markup" =&gt;"&lt;li&gt;&lt;a href='admin/content' class='shlinks'&gt;".t('Find Content')."&lt;/li&gt;");
  $shortcut_set['my_list'][] = array("#markup" =&gt;"&lt;/ul&gt;");
  return $shortcut_set; 
}


function shortcat_toolbar_pre_render() {
  $links = shortcat_renderables();

  $links['#attached'] = array('css' =&gt; array(drupal_get_path('module', 'shortcat') . '/shortcat.css'));
  $links['#prefix'] = '&lt;div class="toolbar-shortcats"&gt;';
  $links['#suffix'] = '&lt;/div&gt;';

  return $links;
}


I know you can make use of:

global $user;
  if ($user-&gt;uid)  {
display it here...
{


but this won't make the user access right accesible in People > Permissions
Since you're defining a permission you can make use of the user_access() function to check that the user is allowed to access the shortcut menu. You can actually then use the #access key on your render array to denote whether or not it should be shown:

function shortcat_toolbar_pre_render() {
  $links = shortcat_renderables();

  $links['#attached'] = array('css' =&gt; array(drupal_get_path('module', 'shortcat') . '/shortcat.css'));
  $links['#prefix'] = '&lt;div class="toolbar-shortcats"&gt;';
  $links['#suffix'] = '&lt;/div&gt;';

  $links['#access'] = user_access('administer shortcat');

  return $links;
}


That code will deny access for anyone who doesn't have the administer shortcat permission. All you need to do is make sure the permission is ticked for the editor role in the admin permissions page.

It's worth bearing in mind that user_access() wil always return TRUE if you are logged in as the super user (ID:1). If you need this to be different then the easiest way would be to check that the user physically has the editor role assigned to their account:

global $user;
if (!in_array('edit', $user-&gt;roles)) {
  $links['#access'] = FALSE;
}


Hope that helps.