Creating a menu link programatically for certain roles

by user3718920   Last Updated May 24, 2017 18:07 PM

My goal is to create links directly to main profile and edit pages when using profile2. I couldn't find how to do this so I found some code that I think would let me make my own links...

$item = array(
    'link_path' => "users/{$GLOBALS['user']->name}",
    'link_title' => $GLOBALS['user']->name,
    'menu_name' => 'main-menu',
    'weight' => 48,
    'expanded' => 1
);
$item_id = menu_link_save($item);
$item = array(
    'link_path' => "user/{$GLOBALS['user']->uid}/edit/main",
    'link_title' => 'Edit',
    'menu_name' => 'main-menu',
    'plid' => $item_id;
);
menu_link_save($item);

In addition to "does this work?", the 2 things I need now are...

How do I make the links only visible to authenticated users?

What other things do I need to do to make this a module or run it in some other way?

Tags : hooks navigation


Related Questions


Edit account menu item in user menu

Updated May 03, 2017 12:07 PM

Access to menu in drupal

Updated May 29, 2017 11:07 AM


Menu link that is author nodeid specific

Updated June 22, 2017 20:07 PM

How to edit element in footer menu

Updated June 28, 2017 14:07 PM