Skip to:
Content
Pages
Categories
Search
Top
Bottom

Unable to Add Profile Tab

  • Avatar of optiqal
    optiqal
    Participant

    @optiqal

    I am trying to add a tab to bp but the content of the tab never displays, regardless of how many code samples I put in. I am adding the code to bp-custom.php and I have no custom template overrides in my WP theme. The tab gets added and there is no 404 error but nothing I put in the content function shows up. Here is a code example:

    function my_test_setup_nav2() {
    global $bp;
    bp_core_new_nav_item( array(
    'name' => 'My New Page',
    'slug' => 'my-new-page',
    'screen_function' => 'my_members_page_function_to_show_screen',
    'position' => 40 ) );
    }

    add_action( 'bp_setup_nav', 'my_test_setup_nav2', 25 );

    function my_members_page_function_to_show_screen() {

    add_action( 'bp_template_title', 'my_members_page_function_to_show_screen_title' );
    add_action( 'bp_template_content', 'my_members_page_function_to_show_screen_content' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/profile' ) );
    }

    function my_members_page_function_to_show_screen_title() {
    echo 'My Page Title';
    }
    function my_members_page_function_to_show_screen_content() {

    echo "<h1>TEST</h1>";
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of optiqal
    optiqal
    Participant

    @optiqal

    I should clarify that I have also tried:

    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }

    Avatar of danbp
    danbp
    Participant

    @danbp

    hello @optiqal,
    using snippets from 2012 leads to errors in many case. ;-)

    Here’s a new version of what you used. I tested it on BP 2.1 and 2013 theme.
    (original code comes from here) As it contained errors i corrected them and adjusted the code to get content everywhere.

    /* we're building the nav button and add it to the profile main menu */
    function mb_bp_profile_menu_posts() {
    	global $bp;
    	bp_core_new_nav_item(
    	array(
    	'name' => 'My Posts',
    	'slug' => 'posts', 
    	'position' => 11, 
    	'default_subnav_slug' => 'published', 
    	'screen_function' => 'mb_author_posts'
    	)
    	);
    }
    add_action('bp_setup_nav', 'mb_bp_profile_menu_posts', 301 );
    
    /* we're building 2 sub item
     * the first is the one showing by default
     */
    
    function mb_bp_profile_submenu_posts() {
    	global $bp;
    	if(!is_user_logged_in()) return '';
    	bp_core_new_subnav_item( array( 
    	'name' => 'Published',
    	'slug' => 'published', 
    	'parent_url' => $bp->loggedin_user->domain . $bp->bp_nav['posts']['slug'] . '/' ,
    	'parent_slug' => $bp->bp_nav['posts']['slug'],
    	'position' => 10,
    	'screen_function' => 'mb_author_posts' //the function is declared below
    	) 
    	); 
    	bp_core_new_subnav_item( array( 
    	'name' => 'Drafts',
    	'slug' => 'drafts', 
    	'parent_url' => $bp->loggedin_user->domain . $bp->bp_nav['posts']['slug'] . '/' ,
    	'parent_slug' => $bp->bp_nav['posts']['slug'],
    	'position' => 20,
    	'screen_function' => 'mb_author_drafts' //the function is declared below
    	) 
    	); 
    }
    add_action('bp_setup_nav', 'mb_bp_profile_submenu_posts', 302 );
    
    /* here we control our 1st sub item
     * first function is the screen_function
     * second function displays the content
    */
    function mb_author_posts(){	
    	add_action( 'bp_template_content', 'mb_show_posts' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    function mb_show_posts() {
    	echo 'Function to Generate the displayed users posts.';
    	// add yout stuff here
    }
    
    /* here we control our 2nd sub item
     * first function is the screen_function
     * second function displays the content
     */
    function mb_author_drafts() {
    	add_action( 'bp_template_content', 'mb_show_drafts' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    function mb_show_drafts() {
    	echo 'Another function to Generate the displayed users drafts.';
    	// add yout stuff here
    }
Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.