How to create a new tab in buddypress member page

Buddypress is a popular WordPress plugin which is used for social networking. This plugin can be used to share messages, invite friends and for many other functionality which a social network do.

In Buddypress member page, there are lot of tabs for friends, messages, profile etc.
In this post we deal with how to add a new tab in the member page.

Here is the code to create a new tab in Buddypress member page.
Use this code in your theme’s functions.php file.


<?php
function my_bp_nav_adder()
{
    bp_core_new_nav_item(
        array(
            'name' => __('New Tab Button', 'buddypress'),
            'slug' => 'all-conversations',
            'position' => 75,
            'show_for_displayed_user' => true,
            'screen_function' => 'all_conversations_link',
            'item_css_id' => 'all-conversations'
        ));
        print_r($wp_filter);
}
function all_conversations_link () {
    //add title and content here - last is to call the members plugin.php template
    add_action( 'bp_template_title', 'my_groups_page_function_to_show_screen_title' );
    add_action( 'bp_template_content', 'my_groups_page_function_to_show_screen_content' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

function my_groups_page_function_to_show_screen_title() {
    echo 'My new Page Title';
}
function my_groups_page_function_to_show_screen_content() {
    echo 'My Tab content here';

}
add_action( 'bp_setup_nav', 'my_bp_nav_adder' );
?>