Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Profile menu


  • barodscheff
    Participant

    @barodscheff

    After last time no one could help me I try it today in another way.

    I have the following code to display a custom menu tab in the profile menu:

    function my_bp_nav() {
    	
          global $bp;
    
          bp_core_new_nav_item( 
    		array( 
                'name' => __( 'Contact Athlete', 'buddypress' ), 
                'slug' => 'contact-athlete', 
                'position' => 30,
    			'screen_function' => 'my_contact_athlete_template', 			
    		) 
    	  );
    
    }
    
    add_action( 'bp_setup_nav', 'my_bp_nav' );
    
    	function my_contact_athlete_template() {
    		bp_get_template_part( 'contact-athlete' );
    	}

    What happens: The template ‘contact-athlete.php’ is loaded above the content and under it a 404 page is shown.

    What I’d like to achieve:
    The ‘contact-athlete.php’ should be loaded within the normal profile template. So everything should look like a normal profile page and inside I would like to call my custom template with a contact form.

    Any suggestions?
    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

  • r-a-y
    Keymaster

    @r-a-y

    Your screen function needs to look something like this:

    	function my_contact_athlete_template() {
    		add_action( 'bp_template_content', create_function( '', "
    			bp_get_template_part( 'contact-athlete' );
    		" ) );
    		bp_core_load_template( 'members/single/plugins' );
    	}
    

    barodscheff
    Participant

    @barodscheff

    Thank you but your solution is outdated. I’ve found it also while searching.
    And thats the big problem with buddypress. There was an update about one year ago and everything changed. So nearly all common customizations do not work any more.

    Thats the reason why the plugin ‘buddypress custom profile menu’ also doesn’t function anymore.

    Fortunately I found the solution. It looks like this:

    function profile_new_nav_item() {
    
    		global $bp;
    
    		bp_core_new_nav_item(
    			array(
    				'name'                => 'Contact Athlete',
    				'slug'                => 'contact_athlete',
    				'default_subnav_slug' => 'extra_sub_tab',
    				'position'            => 160,
    				'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[ 'contact_athlete' ][ 'slug' ] . '/',
    				'parent_slug'     => $bp->bp_nav[ 'contact_athlete' ][ '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() ) {
    			bp_get_template_part('my-contact-form');
    		} else {
    			wp_login_form( array( 'echo' => true ) );
    		}
    	}

    I hope it helps anyone.

    Finally I’d like to say that I have never seen such a bad documentation in development as in buddypress. I know buddypress is free but WordPress is free too and they have a great doc.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Profile menu’ is closed to new replies.
Skip to toolbar