BuddyDev

Search

[Resolved] Move BuddyPress Tab

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #4807

    Hi, there
    Thank you for previous helps. It helps me a lot.

    I’m wondering that is there any way to move one of BuddyPress sub-Tab from one Tab to another?
    For example,
    I want to move Activity -> Personal
    http://imgur.com/dcVeDLD

    to Profile ->
    http://imgur.com/cE2nE9W

    Thanks a lot.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #4808

    Hi Dandy,
    thank you for posting. It is a little bit complicated.

    You need to remove the nav item and then re register. Also, in most of the case, you will have to rewrite the screen handler for the page. I will advise avoiding it unless it is absolute necessary for your site.

    If you need only a few tabs, I will be happy to provide specific code.

    thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #4827

    Hi, Brajesh

    Thanks for your reply and explanation.

    I’m afraid that I have to do in this way because most of users like to.

    So, what I want to do are only few tabs.

    1. Remove “Activity -> Personal” from nav item like below:
    http://imgur.com/dcVeDLD

    2. Add “Personal” to “Profile” tab and put it at the first place, like below:
    http://imgur.com/cE2nE9W

    Additionally, could you also tell me how to hide specific tab and sub-tab at BuddyPress nav?

    Thanks a lot.

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

    Hi Dandy,

    Please place the following code in your bp-custom.php file and let me know if It is working or not.

    
    function buddydev_setup_modified_nav() {
    
    	bp_core_remove_subnav_item( buddypress()->activity->id, 'just-me' );
    
    	bp_core_new_nav_default (
    		array(
    			'parent_slug'       => buddypress()->activity->id,
    			'subnav_slug'       => 'mentions',
    			'screen_function'   => 'bp_activity_screen_mentions'
    		)
    	);
    
    	if ( bp_displayed_user_domain() ) {
    		$user_domain = bp_displayed_user_domain();
    	} elseif ( bp_loggedin_user_domain() ) {
    		$user_domain = bp_loggedin_user_domain();
    	} else {
    		return;
    	}
    
    	$parent_slug          = bp_get_profile_slug();
    	$slug = trailingslashit( $user_domain . $parent_slug );
    
    	bp_core_new_subnav_item( array(
    		'name'          => __( 'Personal' ),
    		'slug'          => 'just-me',
    		'parent_slug'   => $parent_slug,
    		'parent_url'    => $slug,
    		'position'      => 0,
    		'screen_function' => 'buddydev_show_activity'
    	));
    
    }
    
    add_action( 'bp_setup_nav', 'buddydev_setup_modified_nav', 20 );
    
    function buddydev_show_activity() {
    
    	add_action( 'bp_template_content', 'buddydev_render_screen_my_activity' );
    	bp_core_load_template( 'members/single/plugins' );
    
    }
    
    function buddydev_render_screen_my_activity() {
    
    	?>
    
    	<div class="item-list-tabs no-ajax" id="subnav" role="navigation">
    		<ul>
    			
    			<li id="activity-filter-select" class="last">
    				<label for="activity-filter-by"><?php _e( 'Show:', 'buddypress' ); ?></label>
    				<select id="activity-filter-by">
    					<option value="-1"><?php _e( '&mdash; Everything &mdash;', 'buddypress' ); ?></option>
    
    					<?php bp_activity_show_filters(); ?>
    
    					<?php
    
    					/**
    					 * Fires inside the select input for member activity filter options.
    					 *
    					 * @since 1.2.0
    					 */
    					do_action( 'bp_member_activity_filter_options' ); ?>
    
    				</select>
    			</li>
    		</ul>
    	</div><!-- .item-list-tabs -->
    
    <?php
    	if( is_user_logged_in() && bp_is_my_profile() ) {
    		bp_get_template_part( 'activity/post-form' );
    	}
    	echo "<div class='activity'>";
    	bp_get_template_part( 'activity/activity-loop' );
    	echo "</div>";
    }
    
    

    For hiding specific tab use buddypress function “bp_core_remove_subnav_item()” as I have used to remove the menu.
    Make sure the tab You want to remove should not be default tab of its parent. If it is a default nav than you have to register new default tab of that menu for that you can refer the following link

    https://buddydev.com/buddypress/changing-default-subnav-buddypress-component/

    Thank you
    Ravi

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #4882
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #4934

    Hi, there

    I’m sorry to bother you again about this question. I’m wondering that could you spare a little time to solve this issue for me, please?

    Thank you very much.

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

    Hi Dandy,

    Please replace the old code with the following code and let me know if it works or not.

    
    add_action( 'bp_setup_nav', 'buddydev_setup_modified_nav', 20 );
    function buddydev_setup_modified_nav() {
    
    	$bp = buddypress();
    
    	bp_core_remove_subnav_item( buddypress()->activity->id, 'just-me' );
    
    	$bp->members->nav->{'activity/mentions'}->position = 40;
    	$bp->members->nav->{'activity/favorites'}->position = 30;
    
    	if ( bp_is_active('groups') ) {
    		$bp->members->nav->{'activity/groups'}->position = 20;
    	}
    
    	if ( bp_is_active('friends') ) {
    		$bp->members->nav->{'activity/friends'}->position = 10;
    	}
    
    	bp_core_new_nav_item( array(
    			'name'		                => __('Home','buddypress'), //replace with your name
    			'slug'		                => 'home', // slug must be unique
    			'screen_function'	        => 'buddydev_show_activity',
    			'position'                  => 1, // unique
    			'default_subnav_slug'       => false,
    			'show_for_displayed_user'   => true, //Whether the nav item should be visible when viewing a member profile other than your own
    		)
    	);
    
    	bp_core_new_nav_default (
    		array(
    			'parent_slug'       => buddypress()->activity->id,
    			'subnav_slug'       => 'friends',
    			'screen_function'   => 'bp_activity_screen_friends'
    		)
    	);
    
    	if ( bp_displayed_user_domain() ) {
    		$user_domain = bp_displayed_user_domain();
    	} elseif ( bp_loggedin_user_domain() ) {
    		$user_domain = bp_loggedin_user_domain();
    	} else {
    		return;
    	}
    
    	$parent_slug          = bp_get_profile_slug();
    	$slug = trailingslashit( $user_domain . $parent_slug );
    
    	bp_core_new_subnav_item( array(
    		'name'          => __( 'Personal' ),
    		'slug'          => 'just-me',
    		'parent_slug'   => $parent_slug,
    		'parent_url'    => $slug,
    		'position'      => 0,
    		'screen_function' => 'buddydev_show_activity'
    	));
    
    }
    
    function buddydev_show_activity() {
    
    	add_action( 'bp_template_content', 'buddydev_render_screen_my_activity' );
    	bp_core_load_template( 'members/single/plugins' );
    
    }
    
    function buddydev_render_screen_my_activity() {
    
    	?>
    
    	<div class="item-list-tabs no-ajax" id="subnav" role="navigation">
    		<ul>
    
    			<li id="activity-filter-select" class="last">
    				<label for="activity-filter-by"><?php _e( 'Show:', 'buddypress' ); ?></label>
    				<select id="activity-filter-by">
    					<option value="-1"><?php _e( '&mdash; Everything &mdash;', 'buddypress' ); ?></option>
    
    					<?php bp_activity_show_filters(); ?>
    
    					<?php
    
    					/**
    					 * Fires inside the select input for member activity filter options.
    					 *
    					 * @since 1.2.0
    					 */
    					do_action( 'bp_member_activity_filter_options' ); ?>
    
    				</select>
    			</li>
    		</ul>
    	</div><!-- .item-list-tabs -->
    
    	<?php
    	if( is_user_logged_in() && bp_is_my_profile() ) {
    		bp_get_template_part( 'activity/post-form' );
    	}
    	echo "<div class='activity'>";
    	bp_get_template_part( 'activity/activity-loop' );
    	echo "</div>";
    }
    
    

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #4944

    Hi, Ravi

    Thank you so much for updating. It works perfectly. I’m really appreciated at that.

    There are only two questions left:
    1. In “Activity” Tab, it seems like the order of Sub tab is still “Mentions, Favourites, Friends, Groups”. I realize the default one already changed to “Friends”. But could you find a way to put the order as “Friends, Groups, Mentions, Favorites”, also the default one is “Friends”?

    2. In “Profile” Tab, the default sub tab is still “View”. Could you change it into “Personal”? Thanks.

    Thank you very much.

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

    Hello Dandy,

    Please let me know which version of BudddyPress you are using.

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #4947

    Hi, Ravi

    I’m using BuddyPress 2.5.3.

    Thanks.

The topic ‘ [Resolved] Move BuddyPress Tab’ is closed to new replies.

This topic is: resolved