Skip to:
Content
Pages
Categories
Search
Top
Bottom

hiding groups and forums from members page

  • @paragbhagwat

    Participant

    Hello,

    I am trying to hide the groups and forums tabs from all users except admin and the logged in users own profile. The slugs i want to hide are
    /members/betauser/forums/
    /members/betauser/groups/

    I am writing the code as shown below to get this to work but it seems i am always using the logged in user to create the /members/xxx slug where as i may need the user that was clicked.. Any ideas on what i am doing wrong here?

    
    add_action( 'bp_actions', 'RECN_CUSTOM_MEMBER_REMOVE_SUBNAV' );
    function RECN_CUSTOM_MEMBER_REMOVE_SUBNAV()
    {
        bp_core_add_message(' ok i222n the mnethod','error');
        if(is_super_admin() || bp_is_my_profile())
        {
            bp_core_add_message(' ok in the mnethod 1','error');
            return;
        }
    
        $hide_tabs = array(
            'forums'=>1,
            'groups'=>1,
        );
    
        $username = bp_core_get_username( bp_loggedin_user_id() );
    
        //$parent_nav_slug =bp_get_members_root_slug() . '/' . $username;
        $parent_nav_slug =bp_get_members_root_slug();
    
        bp_core_add_message(' ok in the mnethod 2'.$parent_nav_slug,'error');
        foreach ( array_keys( $hide_tabs ) as $tab ) {
            bp_core_remove_subnav_item( $parent_nav_slug, $tab );
        }
    
        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() ) );
        }
    
    }
    

    Thanks,
    Parag Bhagwat

Viewing 3 replies - 1 through 3 (of 3 total)
  • @paragbhagwat

    Participant

    Hello,

    Anyone has any idea on how to resolve this?

    Thanks,
    Parag

    @danbp

    Participant

    Try

    function bpfr_hide_tabs() {
    global $bp;
    	 /**
    	 * class_exists() & bp_is_active are recommanded to avoid problems during updates 
    	 * or when Component is deactivated
    	 */
    
    	if( class_exists( 'bbPress' ) || bp_is_active ( 'groups' ) ) :
    
    	if ( bp_is_user() && !is_super_admin() && !bp_is_my_profile() ) {
    		bp_core_remove_nav_item( 'groups' );
    		bp_core_remove_nav_item( 'forums' );
    		bp_core_remove_subnav_item( 'activity', 'groups' );
    	}
    	endif;
    }
    add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );

    @paragbhagwat

    Participant

    @danbp that worked thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘hiding groups and forums from members page’ is closed to new replies.
Skip to toolbar