BuddyDev

Search

Changing fields from profile page to settings page

Tagged: ,

  • Participant
    Level: Initiated
    Posts: 2
    Manoj Kumar on #48089

    I managed to include the profile tabs on the settings page: https://nimb.ws/rC14lV

    The only problem is that the styling is not correct and when the changes are made, it redirects to the profile page: https://nimb.ws/sY0W4C Can I know how I can correct it? Here is the custom code that I am using for it:

    /* Add profile tabs to settings page */
    
    function custom_settings_nav_test() {
        if ( ! bp_is_active( 'settings' ) ) {
            return;
        }
     
        // 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;
        }
     
        // Get the settings slug.
        $settings_slug = bp_get_settings_slug();
     
        // Add edit profile option.
        bp_core_new_subnav_item( array(
            'name'            => __( 'Edit Profile', 'buddyboss' ),
            'slug'            => 'edit-profile',
            'parent_url'      => trailingslashit( $user_domain . $settings_slug ),
            'parent_slug'     => $settings_slug,
            'screen_function' => 'edit_profile_screen_function',
            'position'        => 100,
            'user_has_access' => bp_core_can_edit_settings()
        ), 'members' );
    
        // Add Profile photo option.
        bp_core_new_subnav_item( array(
            'name'            => __( 'Profile Photo', 'buddyboss' ),
            'slug'            => 'profile-photo',
            'parent_url'      => trailingslashit( $user_domain . $settings_slug ),
            'parent_slug'     => $settings_slug,
            'screen_function' => 'change_profile_picture_screen_function',
            'position'        => 100,
            'user_has_access' => bp_core_can_edit_settings()
        ), 'members' );
    }
    
    add_action( 'bp_setup_nav', 'custom_settings_nav_test');
    
    function edit_profile_screen_function() {
        bp_core_load_template( 'members/single/profile/edit' );
    }
    
    function change_profile_picture_screen_function() {
        add_action( 'bp_template_content', 'change_profile_picture_screen_content' );
        bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/plugins' ) );
    }
    
    function change_profile_picture_screen_content() {
        bp_get_template_part( 'members/single/profile/change-avatar' );
    }

    What am I missing?

  • Keymaster
    (BuddyDev Team)
    Posts: 22498
    Brajesh Singh on #48096

    Hi Manoj,
    Welcome to BuddyDev support forums.

    There are two issues with your approach.

    You have changed the location where the edit profile field shows but you haven’t changed the submission/update handler.

    1. You will need to copy the “buddypress/members/single/profile/edit.php” to your theme or child theme and edit the action for the form element to point to your current settings page.

    2. You will need to copy the code from xprofile update handler and use that to handle the form submission.

    I hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Manoj Kumar on #48098

    Thank you very much, Brajesh!

    1. I copied the file to my child theme but can’t find the necessary action for the settings page: https://nimb.ws/J9TFXh Does it just have to be the URL to the settings page?

    2. Will the profile update handler replace this? https://nimb.ws/UykNsq or should it be done through the functions.php file?

    3. If the above ones are solved, will the stylesheets and javascript appear just like they are on the profile page, or do I need to edit it through custom CSS and JS?

    Is this the best way to include the profile fields in settings or are there others?

    Thanks,
    Manoj

  • Keymaster
    (BuddyDev Team)
    Posts: 22498
    Brajesh Singh on #48099

    Hi Manoj,
    You are welcome.

    1. Yes, you can either remove that completely and put

    
    <form action="" method="post" id="profile-edit-form" class="standard-form profile-edit <?php bp_the_profile_group_slug(); ?>">
    
    

    or you can put the url of that settings page

    2. No.
    Look for this function ‘xprofile_screen_edit_profile’. It is in buddypress/bp-xprofile/screens/edit.php

    It is indirectly attached to ‘bp_screens’ on priority 3. One you change the form’s action, It won’t be called.

    You can handle the update in your edit_profile_screen_function function that you have put while registering the nav.

    PS:- BuddyPress handles 1 group of profile field at a time. If you have multiple profile field groups, Please consider either putting them on a single page or handling them as BuddyPress does.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Manoj Kumar on #48100

    1. I replace the first function with: https://www.buddyboss.com/resources/reference/functions/bp_get_requested_url/ and it works, need to update the form handler.

You must be logged in to reply to this topic.

This topic is: not resolved