Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Removing nav & subnav item in groups


  • gerwinb
    Participant

    @gerwinb

    For our site we use buddypress. In the groups we removed the subnav ‘admin/group-settings’, but in 2.6 this item is visible again. How can I remove it in this new version?

    I used:

    function gwb_remove_group_admin_tab() {
    	if ( ! bp_is_group() || ! ( bp_is_current_action( 'admin' ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
    		return;
    	}
    
    	// Add the admin subnav slug you want to hide in the
    	// following array
    	$hide_tabs = array(
    		'group-settings' => 1,
    		'delete-group' => 1,
    	);
    
    	$parent_nav_slug = bp_get_current_group_slug() . '_manage';
    
    	// Remove the nav items
    	foreach ( array_keys( $hide_tabs ) as $tab ) {
    		bp_core_remove_subnav_item( $parent_nav_slug, $tab );
    	}
    
    add_action( 'bp_actions', 'gwb_remove_group_admin_tab', 9 );

    With the last update this code doesn’t work anymore so I tried:

    
    function gwb_remove_group_admin_tab() {
       bp_core_remove_subnav_item( 'admin', 'group-settings', 'groups' );
    }
    add_action('bp_actions', 'gwb_remove_group_admin_tab',9);

    What did I do wrong?

    Thanks!

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

  • danbp
    Moderator

    @danbp


    gerwinb
    Participant

    @gerwinb

    Thanks for your reaction. I changed the code according to “Removing nav & subnav item in profile page”, into:


    function gwb_remove_group_admin_tab() {
    global $bp;
    bp_core_remove_subnav_item( 'admin', 'group-settings', 'groups' );
    }
    add_action( 'bp_init', 'gwb_remove_group_admin_tab');

    However it is not working for me


    danbp
    Moderator

    @danbp

    @gerwinb, use this snippet for 2.6 +. Corrected, tested and approved by @imath

    function gwb_remove_group_admin_tab() {
    	if ( ! bp_is_group() || ! ( bp_is_current_action( 'admin' ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
    		return;
    	}
    	// Add the admin subnav slug you want to hide in the
    	// following array
    	$hide_tabs = array(
    		'group-avatar' => 1,
    		'delete-group' => 1,
    	);
    	$parent_nav_slug = bp_get_current_group_slug() . '_manage';
    	// Remove the nav items
    	foreach ( array_keys( $hide_tabs ) as $tab ) {
    	  // Since 2.6, You just need to add the 'groups' parameter at the end of the bp_core_remove_subnav_item
    		bp_core_remove_subnav_item( $parent_nav_slug, $tab, 'groups' );
    	}
    	// You may want to be sure the user can't access
    	if ( ! empty( $hide_tabs[ bp_action_variable( 0 ) ] ) ) {
    		bp_core_add_message( 'Sorry buddy, but this part is restricted to super admins!', 'error' );
    		bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) );
    	}
    }
    add_action( 'bp_actions', 'gwb_remove_group_admin_tab', 9 );

    gerwinb
    Participant

    @gerwinb

    Thanks again!,

    Unfortunately it is still not working… The lower part is working, but both links are still visible. I really don’t have a clue how to fix this.

    Regards,
    Gerwin


    gerwinb
    Participant

    @gerwinb

    Can somebody please help me with this problem? For some reason I can’t remove the subnav-item. I added the ‘groups’ parameter, but it still is not working.

    Thanks!


    danbp
    Moderator

    @danbp

    Do you use the correct action hook ? bp_actions instead bp_init


    gerwinb
    Participant

    @gerwinb

    yes, i do… I’ll try again with an empty buddypress website to see if that is working.


    gerwinb
    Participant

    @gerwinb

    It is working! Accually I did something wrong. Script @danbp is the right solution. Thanks!


    javierllinas
    Participant

    @javierllinas

    Hello,

    Working perfect for subnav items, but not for main nav in my case. Can’t get this to work:

    function my_remove_group_tab() {
    
        bp_core_remove_nav_item( 'send-invites', 'groups' );
    
    }
    add_action( 'bp_actions', 'my_remove_group_tab', 9 ); 

    I don’t now what I’m missing here.

    Appreciate any help.


    danbp
    Moderator

    @danbp

    @javierllinas,

    please don’t jump into topics marked as resolved! Open your own, for more clarity

    How to remove group tabs since 2.6

    function bpex_remove_group_tabs() {  
    
    /**
     * @since 2.6.0 Introduced the $component parameter.
     *
     * @param string $slug      The slug of the primary navigation item.
     * @param string $component The component the navigation is attached to. Defaults to 'members'.
     * @return bool Returns false on failure, True on success.
     */ 
    
    	if ( ! bp_is_group() ) {
    		return;
    	}
    
    	$slug = bp_get_current_group_slug();
            // all existing default group tabs are listed here. Uncomment or remove.
    	//	bp_core_remove_subnav_item( $slug, 'members' );
    		bp_core_remove_subnav_item( $slug, 'send-invites' );
    	//	bp_core_remove_subnav_item( $slug, 'admin' );
    	//	bp_core_remove_subnav_item( $slug, 'forum' );
    
    }
    add_action( 'bp_actions', 'bpex_remove_group_tabs' );

    javierllinas
    Participant

    @javierllinas

    I’m really sorry @danbp, I did it because the title of the topic not only refers to subnav items, but to main nav also. From now on, I’ll do as you stated.
    Really appreciate your valuable help.

    Best,
    J

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] Removing nav & subnav item in groups’ is closed to new replies.
Skip to toolbar