phpcsswordpressbuddypress

Wordpress - Buddypress plugin


I want to hide sub-nav in profile settings

enter image description here

I hide sub-nav comment "wp-content\plugins\buddypress\bp-settings\bp-settings-loader.php"

// Add General Settings nav item
    $sub_nav[] = array(
        'name'            => __( 'General', 'buddypress' ),
        'slug'            => 'general',
        'parent_url'      => $settings_link,
        'parent_slug'     => $this->slug,
        'screen_function' => 'bp_settings_screen_general',
        'position'        => 10,
        'user_has_access' => bp_core_can_edit_settings()
    );

Solution

  • What sub-nav item are you referring to? If you want to remove the Settings menu option entirely you can do this in a plugin or functions.php

    function my_admin_bar_mod(){
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu( 'my-account-settings' );
    }
    add_action('wp_before_admin_bar_render','my_admin_bar_mod');
    

    To remove just the Profile option under Settings use this instead:

    $wp_admin_bar->remove_menu( 'my-account-settings-profile' );
    

    UPDATE:

    The following code will remove the General tab; I believe that is what you want. Correct? This code does that but I am seeing a problem. It might be a rewrite problem on my dev site where the Settings tab causes a 4040 error. Can you try this on your site and let me know?

    function mcs_bp_remove_nav() {
        global $bp;
        bp_core_remove_subnav_item( $bp->settings->slug, 'general' );
    }
    add_action( 'bp_setup_nav', 'mcs_bp_remove_nav', 99);
    

    Finally:

    This code is needed in addition to the above. It changes Settings to point to the Email tab. It was defaulting to General and since that was removed we see a 404. This hook must fire earlier than the code that removes 'general'.

    function mcs_bp_change_settings() {
        global $bp;
        // point setting to Email page (aka 'notifications')
        $args = array(  'parent_slug' => 'settings',
            'screen_function' => 'bp_core_screen_notification_settings',
            'subnav_slug' => 'notifications'
        );
        bp_core_new_nav_default( $args );
    }
    add_action( 'bp_setup_nav','mcs_bp_change_settingst', 5);