Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] the right way to remove nav items

  • @willenglishiv

    Participant

    howdy all

    WP is 4.5.3
    BP is 2.6.0

    I recently saw a warning about using $bp globally with the new version, and a small wiki on the new BP Navigation API

    // add_action('bp_setup_nav', 'we4_profile_menu_tabs', 201);
    function we4_profile_menu_tabs(){
    	global $bp;
    	$bp->bp_nav['activity']['position'] = 100;
      $bp->bp_nav['Photos']['position'] = 10;
    
      unset( $bp->bp_nav['groups'] );
      unset( $bp->bp_nav['notifications'] );
      unset( $bp->bp_nav['messages'] );
      unset( $bp->bp_nav['settings'] );
    }
    

    What I tried to do was remove groups, notifications, messages and settings from the nav bar but still have them work in other areas. I tried replacing the previous function with the following one:

    add_action('bp_setup_nav', 'we4_profile_menu_tabs_two', 100 );
    function we4_profile_menu_tabs_two(){
    
      buddypress()->members->nav->edit_nav( array( 
        'position' => 100, 
      ), 'activity' );
      buddypress()->members->nav->edit_nav( array( 
        'position' => 1, 
      ), 'photos' );
      bp_core_remove_nav_item('groups');
      bp_core_remove_nav_item('notifications');
      bp_core_remove_nav_item('messages');
      bp_core_remove_nav_item('settings');
      
    }
    

    The research I saw said this was the right way to remove them, however in doing so, notifications and messages will return 404 pages. I ran into a similar problem trying to work on this last time.

    Is there a correct way to remove the buttons without affecting other pages? doing groups in way #2 seems to be fine.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @danbp

    Participant

    Hi,

    two snippets to remove profile and group items.

    function bpex_hide_profile_menu_tabs() {
    
    	if( bp_is_active( 'xprofile' ) ) :
    
    	if ( bp_is_user() && !is_super_admin() && !bp_is_my_profile() ) {
    	//	BP's profile main menu items. Comment those to show.
    	//	bp_core_remove_nav_item( 'activity' );
    		bp_core_remove_nav_item( 'profile' );
    		bp_core_remove_nav_item( 'friends' );
    		bp_core_remove_nav_item( 'groups' );
    	//	exist only if you use bbPress
    		bp_core_remove_nav_item( 'forums' ); 
    
    	//	BP's profile main menu items. Comment those to show.
    	//	bp_core_remove_subnav_item( 'activity', 'personnal' );
    		bp_core_remove_subnav_item( 'activity', 'mentions' );
    		bp_core_remove_subnav_item( 'activity', 'favorites' );
    		bp_core_remove_subnav_item( 'activity', 'friends' );
    		bp_core_remove_subnav_item( 'activity', 'groups' );
    	}
    	endif; 
    }
    add_action( 'bp_setup_nav', 'bpex_hide_profile_menu_tabs', 15 );
    
    function bpex_remove_group_tabs() {  
    
    	if ( ! bp_is_group() ) {
    		return;
    	}
    
    	$slug = bp_get_current_group_slug();
    
    		// hide items to all users except site admin
    	if ( !is_super_admin() ) {
    
    	//	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' );

    @tendigit

    Participant

    I’d like to restrict the submenus used in profile views to show only if a user is on their own profile or if they are an admin. I think this thread speaks to that. Please let me know if I’m wrong…

    I tried using @danbp ‘s code, but I get a “page not found” on pages that should just be removing the submenu. Logging in as a test user with no admin abilities, I can view my own profile with all tabs intact – but if I go to another user page, I get a 404.

    Assuming I understand the intent of the code, does it need to be adjusted?

    @tendigit

    Participant

    I asked a bit too soon… A little more searching and I found your explanation here. Setting the default component seems to have done the trick. Thanks for the code samples!

    @danbp

    Participant

    @tendigit, glad you got it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] the right way to remove nav items’ is closed to new replies.
Skip to toolbar