[wp-hackers] Can you merge two menus? [SOLVED]

Andrew Nacin wp at andrewnacin.com
Thu Jun 16 11:46:47 UTC 2011


On Wed, Jun 15, 2011 at 5:55 PM, Peter van der Does
<peter at avirtualhome.com>wrote:

> On Wed, 15 Jun 2011 15:52:40 -0400
> Peter van der Does <peter at avirtualhome.com> wrote:
>
> > Hi,
> >
> > I want to have two menus
> > - Guests Menu
> > - Members Menu
> >
> > The members menu is an exact copy of Guest plus some extra items.
> >
> > I know you can create two menus in admin but I would like to know
> > if it's possible to create a Members menu which only holds those
> > items available for members and merge these menu items with the guest
> > menu when needed.
> >
> Here's what I did and it seems to work:
>
> if (is_user_logged_in()){
>    add_filter('wp_nav_menu_objects', 'members_menu', 10, 2);
> }
> function rps_members_menu($sorted_menu_items, $args)
> {
>    $header_members = wp_get_nav_menu_items('Header_members');
>    _wp_menu_item_classes_by_context( $header_members );
>    foreach ($header_members as $item) {
>        $sorted_menu_items[]=$item;
>    }
>    return $sorted_menu_items;
> }
>
> The Header_members only contains items for members.
>
> Thanks to Mike Schinkel for getting me on the right track.
>

I just replied to this, with a solution. Next time, please keep the email
headers intact, including the subject line, unless you are actually changing
the topic. Those of us who consume mailing lists in conversation format
appreciate it.

I will point out however, that you should wait to use is_user_logged_in()
until the init hook. Or simply throw is_user_logged_in() into the callback
and short-circuit the filter if you don't need to process anything.

Cheers,
Nacin


More information about the wp-hackers mailing list