Reputation: 21
I am trying to make an extra tab in the User Profile menu in BuddyPress. So far, i can see the tab in the menu, but when i click the tab, i am being directed to a another page where i can see the content on top of everything and a list with user Activity, instead of seeing seeing the content under the menu (like when you click Activity, Friends, Messages, ect.) I hope that made sense... Here is my code:
function my_setup_nav() {
global $bp;
bp_core_new_nav_item( array(
'name' => __( 'Tester', 'buddypress' ),
'slug' => 'tester',
'position' => 30,
'screen_function' => 'test_template',
) );
}
function test_template() {
add_action( 'bp_template_content', 'test_template_two' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function test_template_two() {
locate_template( array( 'buddypress/members/single/tester.php' ), true );
}
So, i can see the tab with the text "Tester", but when i click i'm getting directed to another page (http://localhost/my-site/members/my-user/tester/) where the content from 'tester.php' is displayed above the user activity.
Thank you in advance.
Upvotes: 1
Views: 4853
Reputation: 2392
Checkout the BuddyPress Custom Profile Menu plugin. It allows you to append regular WordPress menus to the BuddyPress user profile page.
Upvotes: 0
Reputation: 11808
This will help,
function profile_new_nav_item() {
global $bp;
bp_core_new_nav_item(
array(
'name' => 'Extra Tab',
'slug' => 'extra_tab',
'default_subnav_slug' => 'extra_sub_tab', // We add this submenu item below
'screen_function' => 'view_manage_tab_main'
)
);
}
add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );
function view_manage_tab_main() {
add_action( 'bp_template_content', 'bp_template_content_main_function' );
bp_core_load_template( 'template_content' );
}
function bp_template_content_main_function() {
if ( ! is_user_logged_in() ) {
wp_login_form( array( 'echo' => true ) );
}
}
function profile_new_subnav_item() {
global $bp;
bp_core_new_subnav_item( array(
'name' => 'Extra Sub Tab',
'slug' => 'extra_sub_tab',
'parent_url' => $bp->loggedin_user->domain . $bp->bp_nav[ 'extra_tab' ][ 'slug' ] . '/',
'parent_slug' => $bp->bp_nav[ 'extra_tab' ][ 'slug' ],
'position' => 10,
'screen_function' => 'view_manage_sub_tab_main'
) );
}
add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );
function view_manage_sub_tab_main() {
add_action( 'bp_template_content', 'bp_template_content_sub_function' );
bp_core_load_template( 'template_content' );
}
function bp_template_content_sub_function() {
if ( is_user_logged_in() ) {
//Add shortcode to display content in sub tab
} else {
wp_login_form( array( 'echo' => true ) );
}
}
Upvotes: 7