Skip to:
Content
Pages
Categories
Search
Top
Bottom

default_subnav_slug


  • eluyawi
    Participant

    @eluyawi

    I need to redefine the bp_setup_nav function because I need that the following submenu items to load by default

    If it is bp_is_my_profile() and it is active in the main menu (‘settings’), I need to add to it the element
    default_subnav_slug’ => ‘my-email’.

    If bp_is_my_profile() and is active in the main menu (‘xprofile’), I need to add to it the element
    default_subnav_slug’ => ‘change-avatar’.

    How can I do this?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

  • jack5253
    Participant

    @jack5253

    To achieve this functionality, you can redefine the bp_setup_nav function by hooking into the bp_actions action. Inside your custom function, you can check if the user is on their own profile page (bp_is_my_profile()) and if a specific main menu item is active. Based on these conditions, you can add the desired submenu items with the default subnav slug.

    Here’s an example of how you can implement this:

    `php
    function custom_bp_setup_nav() {
    if ( bp_is_my_profile() ) {
    // Check if ‘settings’ main 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 ‘xprofile’ main 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:

    – We define the custom_bp_setup_nav function to check if the user is on their own profile page using bp_is_my_profile().
    – We then check if the ‘settings’ or ‘xprofile’ main menu items are active using bp_is_current_component().
    – Based on these conditions, we add the desired submenu items with the default subnav slug using bp_core_new_subnav_item().

    Make sure to replace 'settings', 'xprofile', 'my-email', and 'change-avatar' with the actual slugs of your main menu items and submenu items. Additionally, adjust the screen_function and other parameters as needed to match your implementation.


    jack5253
    Participant

    @jack5253

    Pittythings is a dynamic platform offering diverse content on lifestyle, fashion, beauty, travel, entertainment, and technology. With informative articles and engaging topics, it caters to a broad audience seeking insights and inspiration across various aspects of daily life and interests.


    tom5333
    Participant

    @tom5333

    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.

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