BuddyDev

Search

moving/deleting/renaming tabs and subnavs

Tagged: , ,

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #24546

    Hi Gijs,
    Thank you for the patience.
    Achieving what you are looking for can be divided into 3 parts:-

    1. Adding new tabs under profile and removing it from settings
    2. setting up action handler to handle the form submission
    3. template loading for settings and modifying form urls to point to the new url.

    You will need some custom code and a few template page editing. I will explain below.

    1. Custom code:- Please put this in your bp-custom.php

    
    
    /**
     * When we are on profile component,
     * If someone asks it is settings component, say yes. This is not the best strategy but helps remove remove the action handler barrier.
     */
    add_filter( 'bp_is_current_component', function ( $is_current_component, $component ) {
    	if ( 'settings' == $component && bp_is_current_component( 'profile' ) ) {
    		$is_current_component = true;
    	}
    
    	return $is_current_component;
    }, 10, 2 )
    
    /**
     * Add some of the settings sub nav as xprofile sub nav.
     */
    function buddydev_custom_setup_xprofile_settings_nav() {
    // Determine user to use.
    	if ( bp_displayed_user_domain() ) {
    		$user_domain = bp_displayed_user_domain();
    	} elseif ( bp_loggedin_user_domain() ) {
    		$user_domain = bp_loggedin_user_domain();
    	} else {
    		return;
    	}
    	$access        = bp_core_can_edit_settings();
    	$slug          = bp_get_profile_slug();
    	$settings_link = trailingslashit( $user_domain . $slug );
    	$sub_nav       = array();
    	$sub_nav []    = array(
    		'name'            => _x( 'Profile Visibility', 'Profile settings sub nav', 'buddypress' ),
    		'slug'            => 'profile',
    		'parent_url'      => $settings_link,
    		'parent_slug'     => $slug,
    		'screen_function' => 'bp_xprofile_screen_settings',
    		'position'        => 110,
    		'user_has_access' => bp_core_can_edit_settings()
    	);
    	$sub_nav[]     = array(
    		'name'            => __( 'Export Data', 'buddypress' ),
    		'slug'            => 'data',
    		'parent_url'      => $settings_link,
    		'parent_slug'     => $slug,
    		'screen_function' => 'bp_settings_screen_data',
    		'position'        => 120,
    		'user_has_access' => $access,
    	);
    
    	$sub_nav[] = array(
    		'name'            => __( 'Delete Account', 'buddypress' ),
    		'slug'            => 'delete-account',
    		'parent_url'      => $settings_link,
    		'parent_slug'     => $slug,
    		'screen_function' => 'bp_settings_screen_delete_account',
    		'position'        => 130,
    		'user_has_access' => ! is_super_admin( bp_displayed_user_id() )
    	);
    
    	foreach ( $sub_nav as $su ) {
    		bp_core_new_subnav_item( $su, 'members' );
    	}
    }
    
    /**
     * After settings nav is registered, let us reorganize.
     */
    function buddydev_custom_reorganize_settings_nav() {
    	bp_core_remove_subnav_item('settings', 'delete-account');
    	bp_core_remove_subnav_item('settings', 'data');
    	bp_core_remove_subnav_item('settings', 'profile');
    	buddydev_custom_setup_xprofile_settings_nav();
    }
    add_action( 'bp_settings_setup_nav', 'buddydev_custom_reorganize_settings_nav', 300 );
    
    

    That is part 1. You will need to edit the profile templates to include the settings form and will also need to update the settings template to submit to profile page.

    here is the code I added in my profile template(switch part)

    
    	case 'delete-account':
    		bp_get_template_part( 'members/single/settings/delete-account' );
    		break;
    
    	case 'profile':
    		bp_get_template_part( 'members/single/settings/profile' );
    		break;
    
    	case 'data':
    		bp_get_template_part( 'members/single/settings/data' );
    		break;
    

    I hope you can take it from here.

    If you are not comfortable with editing php files, please consider our customization service

    https://buddydev.com/buddypress-plugin-customization-service/

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved