[buddypress-trac] [BuddyPress] #4209: bp_get_displayed_user_nav() should have exclusion argument. (code included)

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Thu May 17 06:50:02 UTC 2012


#4209: bp_get_displayed_user_nav() should have exclusion argument. (code included)
--------------------------+----------------------------------------
 Reporter:  DennisSmolek  |      Owner:
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Members       |    Version:  1.5.5
 Severity:  normal        |   Keywords:  needs-testing dev-feedback
--------------------------+----------------------------------------
 I am doing a Nav where I would like to keep the profile and settings
 pages, and in fact call them later, but I am trying to keep them off the
 "Main" Nav.

 Now as a hack I am changing the $bp->bp_nav array and then resetting it
 after my call as in  my case I need it later but that means 2 functions to
 exclude items from this UL list and a lot of janking with the $bp global.

 A simpler approach would be to have the bp_get_user_nav() accept arguments
 including a exclusion array. This way $bp is never effected in any
 subsequent calls (like mine for my "accounts" page)

 This would also have the benefit of allowing things like groups without
 the friends component showing up on the main nav if the owner didn't want
 it or in my case where admins have the ability to edit profiles, but the
 users do not. (a simple conditional)

 I dont have a whole patch file but I do have a working example:

 from bp-members-template.php line 746
 {{{
 function bp_get_displayed_user_nav( $args='' ) {
         global $bp;
         if ($args['exclude']) {
                 foreach ($args['exclude'] as $key => $value) {
                         $exclude[$value] = true;
                 }
         }
         foreach ( (array)$bp->bp_nav as $user_nav_item ) {
                 if ( !$user_nav_item['show_for_displayed_user'] &&
 !bp_is_my_profile() || $exclude[$user_nav_item['slug']] )
                         continue;

                 if ( $bp->current_component == $user_nav_item['slug'] )
                         $selected = ' class="current selected"';
                 else
                         $selected = '';

                 if ( $bp->loggedin_user->domain )
                         $link = str_replace( $bp->loggedin_user->domain,
 $bp->displayed_user->domain, $user_nav_item['link'] );
                 else
                         $link = $bp->displayed_user->domain .
 $user_nav_item['link'];

                 echo apply_filters_ref_array( 'bp_get_displayed_user_nav_'
 . $user_nav_item['css_id'], array( '<li id="' . $user_nav_item['css_id'] .
 '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id']
 . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>',
 &$user_nav_item ) );
         }
 }
 }}}

 And to Call it:


 {{{
 <?php bp_get_displayed_user_nav(array('exclude' => array('profile' ,
 'settings'))); ?>
 }}}


 This example works as expected. Maintains the URL's and Slugs but removes
 the items from the nav menu without effecting $bp.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4209>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list