Skip to:
Content
Pages
Categories
Search
Top
Bottom

Removing Settings General tab redirect to Other Tab

  • @kenmcall

    Participant

    Greetings,

    We are using LDAP to populate and maintain our Buddypress members list, and because of this we don’t want people to be able to change their password or email address via the Settings > General tab. We would like to therefore hide the General tab and have Settings redirect to a different tab instead (preferably Settings > Profile)

    I have gone through the forums and have viewed other posts by people dealing with the same issue, specifically this one:

    How to hide / remove the General tab under Settings

    Here’s the code:

    function bpex_change_profile_settings_default_tab() {
    
    	if( bp_is_active( 'xprofile' ) ) :
    
    	$access        = bp_core_can_edit_settings();
    	$slug          = bp_get_settings_slug();
    
    	$args = array(
    		'parent_slug'     => $slug,
    		'subnav_slug'	  => 'notifications',
    		'screen_function' => 'bp_settings_screen_notification',
    		'user_has_access' => $access
    		);
     
    	bp_core_new_nav_default( $args );
    
    	endif;
    
    }
    add_action( 'bp_actions', 'bpex_change_profile_settings_default_tab' );
    
    function bpex_remove_general_item_on_usermenu() {
    global $wp_admin_bar;
    
    	if ( bp_use_wp_admin_bar() ) {
    		$wp_admin_bar->remove_node( 'my-account-settings-general' );
    	}
    
    }
    add_action( 'wp_before_admin_bar_render', 'bpex_remove_general_item_on_usermenu' );
    
    function bpex_remove_profile_settings_general_tab() {
    
    	if( bp_is_active( 'xprofile' ) ) :	
    
    		bp_core_remove_subnav_item( 'settings', 'general' );
    
    	endif;
    
    }
    add_action( 'bp_actions', 'bpex_remove_profile_settings_general_tab' );

    This seems to be the solution I need, but when I add the code to bp-custom.php it does remove the General tab, but now clicking on Settings generates a 404 error. As this post is over a year old, I’m wondering if there have been changes to Buddypress that stops this from working.

    I should mention that I’ve done some (but not a lot) of PHP programming. I did have a co-oworker who is quite proficient at PHP look over this with me, but everything we tried failed to work.

    Thanks for any help anyone can give.

Viewing 5 replies - 1 through 5 (of 5 total)
  • @ripulkr

    Participant

    You need to remove the nav item at the book ‘bp_setup_nav’ hook.

    @kenmcall

    Participant

    Should have mentioned that I’m running WordPress 4.9.7 and Buddypress 3.1, along with the BuddyBoss Boss theme 2.4.3.

    @r-a-y

    Keymaster

    If you remove a main navigation item, you have to replace it with another, otherwise the 404 is expected.

    For now, I would just override the template for the “Settings > General” screen and add some text. The other option is to redirect to another page like “Settings > Email”.

    @kenmcall

    Participant

    That’s what I’m trying to do, and what I believe the function bpex_change_profile_settings_default_tab is supposed to do. And I’m almost positive it was working before the upgrade to Buddypress 3. I had to leave the project for over a month and came back to it after the upgrade. I’ve found multiple sources/tutorials that give instructions on how to accomplish this, but all are pre version 3, and none now seem to work.

    The override Settings > General screen is not my ideal solution, but it might be a good stop-gap. Thanks.

    @r-a-y

    Keymaster

    Got the answer for you.

    In v3.0.0, we conditionally load code depending on the page you are on.

    Since you are manipulating the default nav item, the screen code needs to be available before the call to bp_core_new_nav_default() is made.

    You can use the following code snippet in conjunction with the code snippet you are currently using until v3.2.0 is released to address this issue:

    add_action( 'bp_late_include', function() {
    	// Include Email screen code on Settings component and for default nav action (which is empty).
    	if ( is_user_logged_in() && bp_is_settings_component() && ! bp_current_action() ) {
    		require_once buddypress()->settings->path . 'bp-settings/screens/notifications.php';
    	}
    }, 11 );

    I’ve created a ticket here – https://buddypress.trac.wordpress.org/ticket/7935

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.