Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How Do I Reorder Group Tabs in BuddyPress?

  • @logicwolf

    Participant

    Hi there,

    Hoping somebody can help. I’m trying to change the order of the Group tabs in BuddyPress.

    I have been successful reordering the Profile tabs using bp_nav. It’s the Group tabs that are eluding me.

    I was able to move the Home tab in Groups with this code in functions.php:

    if (isset($bp->groups->current_group->slug) && $bp->groups->current_group->slug == $bp->current_item) {
              $bp->bp_options_nav[$bp->groups->current_group->slug]['home']['position'] = '99';
          }

    But when I look at the array like this:`foreach ( (array)$bp->bp_options_nav[$bp->groups->current_group->slug] as $key => $value ) {
    echo '<pre>';
    echo '<strong>' . $key . ': </strong><br />';
    print_r( $value );
    echo '</pre>';
    }`
    I only see hooks for Home, Forum, Members, and Admin tabs. For some reason:

    1. I can’t seem to control anything besides the Home tab (for example when I try to change the order of Forum it doesn’t work – this code does now work)
    $bp->bp_options_nav[$bp->groups->current_group->slug]['forum']['position'] = '99';

    2. I don’t see hooks for other tabs added by plugins (like Calendar, Newsletter, etc.)

    I would appreciate any help! Where are these tabs hiding???

    (Also happy to share the code I have to modify Profile tabs if anyone needs that.)

    Looks like I am using BuddyPress version 1.6.4

    Thank you in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • @logicwolf

    Participant

    To clarify on my type above:

    This code does NOT work (can’t reorder the forums tab):

    $bp->bp_options_nav[$bp->groups->current_group->slug]['forum']['position'] = '99';

    But this code DOES work (I can reorder the Home tab)

    $bp->bp_options_nav[$bp->groups->current_group->slug]['home']['position'] = '99';

    Thank you again for any help you can provide!

    @logicwolf

    Participant

    Not much luck with this so far 🙁

    I can track down the creation of new Group tabs in the plugins by looking for extensions of BP_Group_Extension. So for some of the tabs at least, in a pinch, I can edit the plugin code directly but this is a messy solution in my opinion…

    Any suggestions on how I might find the Group tab hooks would greatly be appreciated!

    @logicwolf

    Participant

    Ok, an update. I did manage to track down the objects where this information is stored. It’s not handed to you on a plate by any means!

    I will post the code after I clean it up a bit, but if anybody is suffering through this here is a hint:

    1. Hooks are in different places for core vs plugin Group tabs

    2. Controls for the core “built in” tabs are handled and stored in bp_options_nav

    3. Group tabs added by plugins, if done properly, are created by extending BP_Group_Extension. The extended objects are added to the action stack via add_action. This places references to the instantiated object in the $wp_filter global. So… to change attributes like nav position, you have to crawl through the $wp_filter array, find the objects, check the class, and make the change right there in $wp_filter.

    Messy! I feel like I just took apart a car engine just to turn the windshield wipers off. But the dang Group tabs are reordered and renamed.

    @davesharpedotcom

    Participant

    Hi there,

    Did you ever get your code cleaned up enough to post? I’m having a similar issue, but not able to follow the hints enough to find my own solution.

    Thanks for any help you can offer.

    @logicwolf

    Participant

    Hi David,

    Hoping I’ll be able to help. I’ve seen alot of questions on the topic of How To Change and Reorder BuddyPress Group tabs and not much great direction. Hopefully you won’t be saying that after my posts… What I’m really hoping is someone comes in with a simpler, more elegant solution 🙂

    Were you able to control the standard tabs?

    For the standard group tabs, you can control them directly like this:

    if (isset($bp->groups->current_group->slug) && $bp->groups->current_group->slug == $bp->current_item) 
    {
            $bp->bp_options_nav[$bp->groups->current_group->slug]['home']['position'] = 10;
            $bp->bp_options_nav[$bp->groups->current_group->slug]['members']['position'] = 60;
            $bp->bp_options_nav[$bp->groups->current_group->slug]['notifications']['position'] = 110;
    }

    So the code to put in functions.php might look like this:

    function whff_setup_nav() 
    {
    
      if (isset($bp->groups->current_group->slug) && $bp->groups->current_group->slug == $bp->current_item) 
      {
         $bp->bp_options_nav[$bp->groups->current_group->slug]['home']['position'] = 10;
         $bp->bp_options_nav[$bp->groups->current_group->slug]['members']['position'] = 60;
         $bp->bp_options_nav[$bp->groups->current_group->slug]['notifications']['position'] = 110;
    }
    
    } 
    add_action( 'bp_setup_nav', 'whff_setup_nav', 100000 );

    CUSTOM BUDDYPRESS GROUP TABS
    Now, the non-standard tabs are the tricky ones. You can’t access them through $bp->bp_options_nav (at least I couldn’t figure out how to do this.)

    Nonstandard Group tabs through the $wp_filter global. A good starting point is to dump the $wp_filter variable and get a look at it’s guts. Add this code in functions.php:

    global $wp_filter;
        
    foreach ( (array)$wp_filter as $key => $value ) 
    {
       echo '<pre>';
       echo '<strong>' . $key . ': </strong><br />';
       print_r( $value );
       echo '</pre>';
    }
    

    $wp_filter is a bunch of nested arrays. Search through the output for your Group Tab Names (i.e. search for “Calendar”) and you will find something like this:

    [00000000746c6153000000004e38ec1f_register] => Array
                    (
                        [function] => Array
                            (
                                [0] => BP_Group_Calendar_Extension Object
                                    (
                                        [visibility] => private
                                        [enable_create_step] => 
                                        [enable_nav_item] => 1
                                        [enable_edit_item] => 
                                        [name] => Calendar
                                        [slug] => calendar
                                        [admin_name] => 
                                        [admin_slug] => 
                                        [create_name] => 
                                        [create_slug] => 
                                        [create_step_position] => 81
                                        [nav_item_position] => 40
                                        [nav_item_name] => 
                                        [display_hook] => groups_custom_group_boxes
                                        [template_file] => groups/single/plugins
                                    )
    
                                [1] => _register
                            )
    
                        [accepted_args] => 1
                    )
    

    That’s your Group tab and all the hooks you need to change attributes (in this case it’s the tab that says “Calendar”.)

    But… unfortunately you can’t use the [00000000746c6153000000004e38ec1f_register] as a handle — that string is random and changes every time. But, now you know the class name is BP_Group_Calendar_Extension Object and you can search for that in the $wp_filter array and make the changes.

    Hope this gets you closer, let me know how you make out. Cheers David!

    @wiste

    Participant

    @logicwolf, I tried your code out and unfortunately it seems to have no effect on y site. Is this solution still working for you? Any thoughts on why it might not be working for me? I copied exactly what you wrote and added it to functions.php in my child theme. I tried changing the values for the position but that also had no effect.

    @wiste

    Participant

    I fixed it using the advice from this blog post.

    function whff_setup_nav() 
    {
    
    global $bp;
    
      if (isset($bp->groups->current_group->slug) && $bp->groups->current_group->slug == $bp->current_item) 
      {
         $bp->bp_options_nav[$bp->groups->current_group->slug]['home']['position'] = 10;
         $bp->bp_options_nav[$bp->groups->current_group->slug]['members']['position'] = 60;
         $bp->bp_options_nav[$bp->groups->current_group->slug]['notifications']['position'] = 110;
    }
    
    } 
    add_action( 'bp_setup_nav', 'whff_setup_nav', 100000 );

    I added “global $bp;” at the top of the function. Now works like a charm. Thank you for your hard work in sussing this out!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] How Do I Reorder Group Tabs in BuddyPress?’ is closed to new replies.
Skip to toolbar