BuddyDev

Search

[Resolved] Adding menu items

  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3762

    Hello,

    I’m trying to add a new link to the menu on my BuddyPress profile page. I’ve looked through the BuddyPress codex and forums and I’ve just about given up on receiving any support from their website as no one replies.

    Here is my code

    function bp_core_new_nav_item( $args = array( 
            'name' => __('community', 'buddypress'), 
            'slug' => $bp->community->slug, 
            'position' => 50, 
            'show_for_displayed_user' => false, 
            'screen_function' => false, 
            'default_subnav_slug' => 'community', 
            'item_css_id' => $bp->community->id 
        ));
     
      
    $result = bp_core_new_nav_item($args);

    I’m given the following error

    Parse error: syntax error, unexpected '(', expecting ')' in C:\xampp\htdocs\wordpress\wp-content\plugins\bp-custom.php on line 25

    Am I using this wrong? could someone explain it please? as I say I’ve given up on the buddy press website itself.

    Thanks

    Phil

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3763

    Hi Phill

    Thank you for posting. You can refer the following URL to create a new nav item for BuddyPress Profile Tab.

    https://buddydev.com/support/forums/topic/move-subnav-tabs/#post-3296

    Thank You
    Ravi

    • This reply was modified 8 years, 7 months ago by Ravi.
  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3765

    Hi Ravi,

    Thank you for your speedy reply. Its appreciated. I’ve read through that topic and it looks like the person there was wanting to move a menu item. I’m trying to add a new one.

    I’m really struggling to change the default forum feed in the activity section, so I thought if I do away with that feed and added a custom page with the BBPress shortcode in there and then link to that page instead. Seemed simple enough until I started trying to add the link. If that topic you posted will do what I want then thank you very much, il read through it all again and see if I can get it to work.

    I just wanted to check it will do that before I spend time trying to fix it. My PHP is probably < novice level at the moment which is quickly becoming and issue haha!

    Thanks Ravi, hope to hear from you soon.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3766

    Hi Phill,

    I have tried to fix problem by adding a new menu to Buddypress profile page that render shortcode content. Please try it in your bp-custom.php file and let me know if it works or not.

    
    function buddydev_modify_user_profile_tab() {
    
    	$bp = buddypress();
    	
    	$user_url = bp_loggedin_user_domain();
    	// add 'Change profile picture' sub-menu tab
    	bp_core_new_subnav_item( array(
    			'name'		=> 'Community', //replace with your name
    			'slug'		=> 'community', // slug must be unique
    			'parent_url'	=> trailingslashit( $user_url . $bp->profile->slug ),
    			'parent_slug'	=> $bp->profile->slug,
    			'screen_function'	=> 'buddydev_screen_profile_community',
    			'position'          => 30,
    			'user_has_access'   => bp_is_my_profile()
    		)
    	);
    
    }
    add_action( 'bp_setup_nav', 'buddydev_modify_user_profile_tab', 100 );
    
    function buddydev_screen_profile_community() {
    
    	add_action( 'bp_template_content', 'buddydev_load_content' );
    
    	bp_core_load_template( 'members/single/settings/general' );
    }
    
    function buddydev_load_content() {
    
    	echo do_shortcode( '[mpp-show-gallery id=303]' ); // replace by Your shortcode
    }
    
    

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3767

    Thanks Ravi! absolute legend!

    One more small question. If I wanted to move the ‘community’ link into the top level of the menu next to ‘Activity’ ‘Profile’ and so on?

    My intention is to set it as a top level link, that when a member goes to that page the default view is the ‘community’ page. Just so my members don’t need to click about too much really. Id like it to be the first thing they see. I’ve learnt how to change the default component loaded so that’s not a worry.

    I was just wandering which part of the code you posted I would need to alter to achieve this.

    Many Thanks Ravi,

    PhilB

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3768

    Hi Phill,

    Thank you for your appreciation. Please remove the previous code and try the following code in your bp-custom.php file.

    
    function buddydev_modify_user_profile_tab() {
    	
    	bp_core_new_nav_item( array(
    			'name'		                => 'Community', //replace with your name
    			'slug'		                => 'community', // slug must be unique
    			'screen_function'	        => 'buddydev_screen_profile_community',
    			'position'                  => 11, // unique
    			'default_subnav_slug'       => 'community-sub',
    			'show_for_displayed_user'   => true, //Whether the nav item should be visible when viewing a member profile other than your own
    		)
    	);
    
    }
    add_action( 'bp_setup_nav', 'buddydev_modify_user_profile_tab', 8 );
    
    function buddydev_screen_profile_community() {
    
    	add_action( 'bp_template_content', 'buddydev_load_content' );
    	bp_core_load_template( 'members/single/plugins'  );
    
    }
    
    function buddydev_load_content() {
    
    	echo do_shortcode( '[mpp-show-gallery id=303]' ); // replace by Your shortcode
    
    }
    
    

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3769

    Thanks again Ravi, that worked great. Il save the other piece of code you sent before as I think that might come in useful in the future.

    Again, thanks!

    Regards

    PhilB

You must be logged in to reply to this topic.

This topic is: resolved