Create user menu

So I have been doing some searching around with no luck. What I am looking for is a way to make a user menu like what Facebook has that will allow you to selecet a group you are members of and also to hose the links for Administration (Admins option only), User Settings and the Log out option.

I know how to make an Elgg menu but how do I hide the current options from users.

  • Ok so looking at the links you have given me this will hide links on the standered elgg theme where they ran across the blue bar. What I need is a way to over ride the calls for the menu items Administration, Settings and Log out so I can hide this from all users and place them in a new Menu which says "Hi <User Name>" and will have a pull down list.

    And depending if the user is of Admin or just User will show the different menu items for that user.

  • The above links are references to universal functions.

    You're talking about topbar's menu items.

    So, if you want to hide some items, just do it:

    elgg_unregister_menu_item('topbar', 'usersettings');

    elgg_unregister_menu_item('topbar', 'logout');

    e t c

  • using the above code does not remove the Administration, Settings or Logout they leave it all there. But UI have managed to remvoe Profile, Message and Friends with this code


    //Used to remove all links on the topbar from elgg install
    function custom_topbarmenu_setup ($hook, $type, $return, $params) {
     $remove = array('profile', 'friends', 'messages');
        foreach($return as $key => $item) {
            if (in_array($item->getName(), $remove)) {
                unset($return[$key]);
            }
        }
        return $return;
    }   

     

  • It depends on how the menu items are registered by the other plugin (or Elgg core).

    If they are registed using elgg_register_menu_item() you can unregister the menu item again with elgg_unregister_menu_item() as RvR explained.

    If the menu item is registed using a plugin hook (i.e. 'register', 'menu:<MENU NAME>') then you can unregister the plugin hook handler that was defined in the other plugin (or Elgg core) using elgg_unregister_plugin_hook_handler().

    For reference of the functions' parameters check out http://reference.elgg.org.

  • @iionly

    Thanks for that but then where are Administration, Settings and Log Off actuall called then as they are core elgg things I am thinking but have no clue where to find them with in the code

  • ;) It'll be work if you register your pagesetup handler:

    elgg_register_event_handler('pagesetup', 'system', 'my_super_theme_pagesetup_handler');

     

    function my_super_theme_pagesetup_handler() {

      elgg_unregister_menu_item('topbar', 'usersettings');

      elgg_unregister_menu_item('topbar', 'logout');

    }

  • Thank you very much for your help @RvR. I now have all things working and now need to move on to only showing Administrators the Admin link which is well a lot of work now on my end.

     

  • What's about:

    if (!elgg_is_admin_logged_in()) {

    elgg_unregister_menu_item('topbar', 'administration');

    }

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking