Forum Replies Created
-
To achieve this functionality, you can redefine the bp_setup_nav function by hooking it into the bp_actions action. Within your custom function, check if the user is viewing their profile using bp_is_my_profile(), and verify if a specific main menu item is active using bp_is_current_component(). Based on these checks, you can add the required submenu items with a default subnav slug.
Here’s an example implementation:
php
Copy code
function custom_bp_setup_nav() {
if ( bp_is_my_profile() ) {
// Check if the ‘settings’ menu item is active
if ( bp_is_current_component( ‘settings’ ) ) {
bp_core_new_subnav_item( array(
‘name’ => __( ‘My Email’, ‘text-domain’ ),
‘slug’ => ‘my-email’,
‘default_subnav_slug’ => ‘my-email’,
‘parent_url’ => bp_loggedin_user_domain() . ‘settings/’,
‘parent_slug’ => ‘settings’,
‘screen_function’ => ‘bp_settings_screen_my_email’,
‘position’ => 30,
‘user_has_access’ => bp_is_my_profile()
));
}// Check if the ‘xprofile’ menu item is active
if ( bp_is_current_component( ‘xprofile’ ) ) {
bp_core_new_subnav_item( array(
‘name’ => __( ‘Change Avatar’, ‘text-domain’ ),
‘slug’ => ‘change-avatar’,
‘default_subnav_slug’ => ‘change-avatar’,
‘parent_url’ => bp_loggedin_user_domain() . ‘profile/’,
‘parent_slug’ => ‘profile’,
‘screen_function’ => ‘bp_xprofile_screen_change_avatar’,
‘position’ => 30,
‘user_has_access’ => bp_is_my_profile()
));
}
}
}
add_action( ‘bp_actions’, ‘custom_bp_setup_nav’, 999 );
In this code:The custom_bp_setup_nav function checks if the user is on their profile page using bp_is_my_profile().
It validates if the ‘settings’ or ‘xprofile’ main menu item is active with bp_is_current_component().
Depending on the conditions, it adds submenu items using bp_core_new_subnav_item().
Customize the slugs (settings, xprofile, my-email, change-avatar) and parameters like screen_function to match your specific menu structure and requirements.