Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

question: I am trying to create a new sub nav item for the groups on buddy press I am using bp_core_new_subnav_item to do it and passing the screen_function, but the tab is not displaying on the group page

Any ideas where I should be looking on this?

Heres our code.

bp_core_new_nav_item( array(
  'name' => 'Document List',
  'slug' => 'group-document-list',
  'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/',
  'parent_slug' => $bp->groups->slug,
  'screen_function' => 'group_document_list_function_to_show_screen',
  'position' => 55 ) );

  function group_document_list_function_to_show_screen() {

   //add title and content here - last is to call the members plugin.php template
   add_action( 'bp_template_title', 'group_document_list_function_to_show_screen_title' );
   add_action( 'bp_template_content', 'group_document_list_function_to_show_screen_content' );
   bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function group_document_list_function_to_show_screen_title() {
    echo 'Documents for this group';
}
function group_document_list_function_to_show_screen_content() {
   display_group_document_list();
}
share|improve this question
1  
Can you please edit your question and add the code that you're using? –  Boone Gorges Mar 21 '12 at 1:51
    
wordpress.stackexchange.com/questions/6719/… this is what we tried and it didnt work. We are thinking maybe its some plugin thats blocking the space where the tab would show up maybe? ok trying to edit my post. –  Joseph Mar 21 '12 at 2:01
    
Hope thats what you needed. Thanks Boone! –  Joseph Mar 21 '12 at 3:04
add comment

1 Answer

up vote 2 down vote accepted

Make sure that you only attempt to set up the items after BP has set up its core navigation. You can ensure this by hooking to bp_setup_nav with a priority higher than 10.

Thus:

function bbg_setup_nav() {
    bp_core_new_subnav_item( array( 
        'name' => 'Document List',
        'slug' => 'group-document-list',
        'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/',
        'parent_slug' => $bp->groups->slug,
        'screen_function' => 'group_document_list_function_to_show_screen',
        'position' => 55
    ) );
}
add_action( 'bp_setup_nav', 'bbg_setup_nav', 100 );

Keep in mind that, as written, this code is intended to add a subnav tab to the Groups subnav of a user profile. If you want to attach it to a single group instead, you need to relativize it to groups, using a different parent_slug and parent_url:

// ...
'parent_slug' => bp_get_current_group_slug(),
'parent_url'  => bp_get_group_permalink( groups_get_current_group() )
// ...

To be honest, though, if you want to be adding subnav items to BP Groups, your best bet is to use the BP Group Extension API http://codex.buddypress.org/developer-docs/group-extension-api/. You just fill in a few methods, and all the BP-specific navigation logic is done for you. If there are methods (like create_screen() you're not going to use, just leave them blank.

share|improve this answer
    
In reviewing your original code, I realized that you used the wrong function - bp_core_new_nav_item() instead of bp_core_new_subnav_item(). The former is used for adding components to user profiles. For groups, the latter must be used. I've updated my answer accordingly. –  Boone Gorges Mar 22 '12 at 1:50
    
Thank you this was very helpful Boone. I am new to this website so I didnt see how to "Accept" answers or I would have before. –  Joseph Apr 4 '12 at 16:00
    
Thank you so much! Took me a while to find this :) –  Norris Jun 16 '12 at 8:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.