Skip to:
Content

Opened 5 years ago

Closed 5 years ago

#5012 closed defect (bug) (invalid)

bp_nav_menu() function problems

Reported by: therearwindow Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.7
Component: Core Keywords: reporter-feedback
Cc:

Description (last modified by boonebgorges)

WP (latest version) & BP (1.7.2) Fresh installation.

Here is the problem with bp_nav_menu()

Default menu for admin user:

<div class="menu-bp-container"><ul id="menu-bp" class="menu"><li id="activity-personal-li"><a href="http://activity/">Activity</a>
<ul class="sub-menu">
	<li id="just-me-personal-li"><a href="http://example.com/wp2/members/admin/activity/">Personal</a></li>
	<li id="activity-mentions-personal-li"><a href="http://example.com/wp2/members/admin/activity/mentions/">Mentions</a></li>
	<li id="activity-favs-personal-li"><a href="http://example.com/wp2/members/admin/activity/favorites/">Favorites</a></li>
	<li id="activity-friends-personal-li"><a href="http://example.com/wp2/members/admin/activity/friends/">Friends</a></li>
	<li id="activity-groups-personal-li"><a href="http://example.com/wp2/members/admin/activity/groups/">Groups</a></li>
</ul>
</li>
<li id="xprofile-personal-li"><a href="http://profile/">Profile</a>
<ul class="sub-menu">
	<li id="public-personal-li"><a href="http://example.com/wp2/members/admin/profile/">View</a></li>
	<li id="edit-personal-li"><a href="http://example.com/wp2/members/admin/profile/edit/">Edit</a></li>
	<li id="change-avatar-personal-li"><a href="http://example.com/wp2/members/admin/profile/change-avatar/">Change Avatar</a></li>
</ul>
</li>
<li id="messages-personal-li"><a href="http://messages/">Messages <span>0</span></a>
<ul class="sub-menu">
	<li id="inbox-personal-li"><a href="http://example.com/wp2/members/admin/messages/">Inbox</a></li>
	<li id="sentbox-personal-li"><a href="http://example.com/wp2/members/admin/messages/sentbox/">Sent</a></li>
	<li id="compose-personal-li"><a href="http://example.com/wp2/members/admin/messages/compose/">Compose</a></li>
	<li id="notices-personal-li"><a href="http://example.com/wp2/members/admin/messages/notices/">Notices</a></li>
</ul>
</li>
<li id="friends-personal-li"><a href="http://friends/">Friends <span>0</span></a>
<ul class="sub-menu">
	<li id="friends-my-friends-personal-li"><a href="http://example.com/wp2/members/admin/friends/">Friendships</a></li>
	<li id="requests-personal-li"><a href="http://example.com/wp2/members/admin/friends/requests/">Requests</a></li>
</ul>
</li>
<li id="groups-personal-li"><a href="http://groups/">Groups <span>0</span></a>
<ul class="sub-menu">
	<li id="groups-my-groups-personal-li"><a href="http://example.com/wp2/members/admin/groups/">Memberships</a></li>
	<li id="invites-personal-li"><a href="http://example.com/wp2/members/admin/groups/invites/">Invitations</a></li>
</ul>
</li>
<li id="settings-personal-li"><a href="http://settings/">Settings</a>
<ul class="sub-menu">
	<li id="general-personal-li"><a href="http://example.com/wp2/members/admin/settings/">General</a></li>
	<li id="notifications-personal-li"><a href="http://example.com/wp2/members/admin/settings/notifications/">Notifications</a></li>
	<li id="capabilities-personal-li"><a href="http://example.com/wp2/members/admin/settings/capabilities/">Capabilities</a></li>
</ul>
</li>
</ul></div>

Default menu for normal user:

<div class="menu-bp-container"><ul class="menu" id="menu-bp"><li id="activity-personal-li"><a href="http://activity/">Activity</a>
<ul class="sub-menu">
	<li id="just-me-personal-li"><a href="http://example.com/wp2/members/antton/activity/">Personal</a></li>
	<li id="activity-mentions-personal-li"><a href="http://example.com/wp2/members/antton/activity/mentions/">Mentions</a></li>
	<li id="activity-favs-personal-li"><a href="http://example.com/wp2/members/antton/activity/favorites/">Favorites</a></li>
	<li id="activity-friends-personal-li"><a href="http://example.com/wp2/members/antton/activity/friends/">Friends</a></li>
	<li id="activity-groups-personal-li"><a href="http://example.com/wp2/members/antton/activity/groups/">Groups</a></li>
</ul>
</li>
<li id="xprofile-personal-li"><a href="http://profile/">Profile</a>
<ul class="sub-menu">
	<li id="public-personal-li"><a href="http://example.com/wp2/members/antton/profile/">View</a></li>
</ul>
</li>
<li id="friends-personal-li"><a href="http://friends/">Friends <span>0</span></a>
<ul class="sub-menu">
	<li id="friends-my-friends-personal-li"><a href="http://example.com/wp2/members/antton/friends/">Friendships</a></li>
</ul>
</li>
<li id="groups-personal-li"><a href="http://groups/">Groups <span>0</span></a>
<ul class="sub-menu">
	<li id="groups-my-groups-personal-li"><a href="http://example.com/wp2/members/antton/groups/">Memberships</a></li>
</ul>
</li>
</ul></div>

Default menu inside a group created by normal user: http://example.com/wp2/groups/example_group/

<div class="menu-bp-container">
<ul class="menu" id="menu-bp">
<li id="groups-personal-li"><a href="http://example_group/">Memberships</a>
<ul class="sub-menu">
	<li id="groups-my-groups-personal-li"><a href="http://example.com/wp2/members/antton/groups/">Memberships</a></li>
</ul>
</li>
<li id="activity-personal-li"><a href="http://activity/">Activity</a>
<ul class="sub-menu">
	<li id="just-me-personal-li"><a href="http://example.com/wp2/members/antton/activity/">Personal</a></li>
	<li id="activity-mentions-personal-li"><a href="http://example.com/wp2/members/antton/activity/mentions/">Mentions</a></li>
	<li id="activity-favs-personal-li"><a href="http://example.com/wp2/members/antton/activity/favorites/">Favorites</a></li>
	<li id="activity-friends-personal-li"><a href="http://example.com/wp2/members/antton/activity/friends/">Friends</a></li>
	<li id="activity-groups-personal-li"><a href="http://example.com/wp2/members/antton/activity/groups/">Groups</a></li>
</ul>
</li>
<li id="xprofile-personal-li"><a href="http://profile/">Profile</a>
<ul class="sub-menu">
	<li id="public-personal-li"><a href="http://example.com/wp2/members/antton/profile/">View</a></li>
</ul>
</li>
<li id="friends-personal-li"><a href="http://friends/">Friends <span>0</span></a>
<ul class="sub-menu">
	<li id="friends-my-friends-personal-li"><a href="http://example.com/wp2/members/antton/friends/">Friendships</a></li>
</ul>
</li>
<li id="groups-personal-li"><a href="http://groups/">Groups <span>1</span></a></li>
<li class="current-menu-item" id="home-personal-li"><a href="http://example.com/wp2/groups/example_group/">Home</a></li>
<li id="members-personal-li"><a href="http://example.com/wp2/groups/example_group/members/">Members <span>1</span></a></li>
<li id="invite-personal-li"><a href="http://example.com/wp2/groups/example_group/send-invites/">Send Invites</a></li>
<li id="admin-personal-li"><a href="http://example.com/wp2/groups/example_group/admin/">Admin</a></li>
</ul></div>

As you can see the top level URLs are broken. Also groups-personal-li id is used twice, and I really can't appreciate the difference between Memberships or Groups Top levels, there are more problems as you can see that the Messages Top level menu disappear, and except the submenus of the TopLevel Activity the others doesn't have all their sub-menus.

About the submenus html structure of the groups submenu It's quite obvious that we need to rewrite.

I found a 'solution' about missing submenu items, but I'm not sure if it's gonna be soo good. Change the following function the menu works properly. Messages toplevel appear and load all submenu items as well.

function bp_core_can_edit_settings() {
        if ( bp_is_my_profile() )
                return true;

        //if ( bp_current_user_can( 'bp_moderate' ) || current_user_can( 'edit_users' ) )         
        if ( bp_current_user_can( 'bp_moderate' ) || !current_user_can( 'edit_users' ) )  // Maybe I'm opening a new bug :(
                return true;
        
        return false;
}

Change History (3)

#1 @boonebgorges
5 years ago

  • Description modified (diff)
  • Keywords reporter-feedback added

As you can see the top level URLs are broken

I see that in the markup you've pasted here, but I can't reproduce it on my current setup. What URL are you looking at when the nav menu is rendered? Is it a user page (example.com/members/foo/)?

groups-personal-li id is used twice

Confirmed. This does look like a bug. It looks like bp_nav_menu() has code that's supposed to prevent these sorts of duplicates, but I guess it's not working.

I really can't appreciate the difference between Memberships or Groups Top levels

I don't believe that Memberships is supposed to be a top level item - I think it's supposed to fall under Groups. I'm guessing that the nesting is breaking because of whatever's causing your top-level URLs to break.

the Messages Top level menu disappear, and except the submenus of the TopLevel? Activity the others doesn't have all their sub-menus.

Ditto. I'm guessing that something funny is happening because of where you are loading the menu, and this is the single cause of several of these issues. If you can provide more info about how you're using bp_nav_menu(), it'd be helpful.

found a 'solution' about missing submenu items, but I'm not sure if it's gonna be soo good.

You're right, it's not good :) It will allow anyone to edit anyone else's settings.

#2 @therearwindow
5 years ago

Hi Boone,

I'm gonna try to explain something deeper the problem.

  • What URL are you looking at when the nav menu is rendered? Is it a user page (example.com/members/foo/)?

The first one "that workins properly" is a user page,so you are right!

The other code it's rendered in a group page.

Here is how I implement the bp_nav_menu function in my theme:

I just took the default installation and add it in header.php file of twentytwelve default template. That's it without any other change in any other files.

I let you the real URL on which you can see the problem. I'll open as well the registration if you want to check properly.

http://geragaitezen.com/wp2/

#3 @boonebgorges
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Thanks for the feedback, therearwindow.

I've done some digging into the way that bp_nav_menu() works. It looks like you are trying to use it in a way it's not designed to be used. It gets its nav items using bp_get_nav_menu_items(), which fetches menu items from $bp->bp_options_nav. As things currently stand in BuddyPress, bp_options_nav is built by each component on each pageload, and is very context-specific. Thus, for the same user, the options nav will be different when looking at one's own profile, vs when looking at another person's profile, vs looking at a group page, etc.

This is a design limitation in the current implementation. In the long run, it would be great for bp_nav_menu() (or something like it) to be able to output, say, the current user's main nav menu, and to do it on any page of a BP installation. But at the moment, the function (and our entire menu system) is not designed to be context-independent in this way.

I'm going to close this ticket as invalid, because it's not really a bug so much as the way things work. If you would like to see a context-independent user menu function in BP, please feel free to open an enhancement ticket, and describe in detail what items you think would/should appear on that menu. Thanks!

Note: See TracTickets for help on using tickets.