Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile field groups tabs while editing profile


  • amkh
    Participant

    @amkh

    Please help me with the code to show different profile field groups in Tabs. When the member edits his profile containing multiple profile groups then I wan the profile fields groups to arranged in Tabs.

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

  • amkh
    Participant

    @amkh

    Additionally I want each “tab” to show “Save and Continue” button. So when the member finishes editing profile fields in Group 2 then once he clicks “Save and Continue” then he should be taken to profile group 3.


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    It will need custom coding. Profile groups are already there and one can edit but save and continue will require custom coding.

    Thanks


    Prashant Singh
    Participant

    @prashantvatsh

    You can use this hook ‘xprofile_data_after_save’ to do it. Just have to redirect to next profile group.

    Thanks


    amkh
    Participant

    @amkh

    Thank you very much for your suggestion. Do I need to insert this hook in the edit.php template? Probably I will have to modify template because I would like to label the “Save” button to “Save & Continue”. Correct me if I am wrong. Also kindly know that I have 5 profile field groups. Out of these 5 the first group is hidden so only 4 groups are visible on edit page. Thus I will need group increments from group 2-4 for ‘xprofile_data_after_save’ to act and then on the last group i.e. group 4 it should exit with some message. Your expert opinion / help is highly needed.


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    No need to edit any template. I have created a snippet for you. Please paste the following snippet in your child theme’s functions.php file:

    function ps_redirect_next_group() {
    	
       	if ( ! bp_is_user_profile_edit() || ! bp_is_my_profile() ) {
    		return;
    	}
    	
    	$group_id = bp_get_current_profile_group_id()+1;
    	if ( bp_get_current_profile_group_id()==4 ) {
    			bp_core_redirect(bp_displayed_user_domain()."profile/");
    	}else{
    		bp_core_redirect(bp_displayed_user_domain()."profile/edit/group/$group_id/");
    	}
    	
    }
    add_action( 'xprofile_data_after_save', 'ps_redirect_next_group' );
    
    add_filter( 'gettext', 'ps_change_save_button_text', 20, 3 );
    
    function ps_change_save_button_text( $translated_text, $text, $domain ) {
    
       if ( ! bp_is_user_profile_edit() || ! bp_is_my_profile() ) {
    		return $translated_text;
    	}
    
        switch ( $translated_text ) {
            case 'Save Changes' :
            	$translated_text = __( 'Save and Continue', $domain );
            break;
        }
        
        return $translated_text;
    }

    If there is no child theme then create a file bp-custom.php in wp-content/plugins/ folder and paste this there. https://codex.buddypress.org/themes/bp-custom-php/

    If not possible to create bp-custom.php file then third and easy solution is to install the plugin code snippets https://wordpress.org/plugins/code-snippets/ and there add a snippet and paste the code and save.

    Hopefully, it will help you.

    Thanks


    amkh
    Participant

    @amkh

    Hi Prashant,

    Thank you very much for quickly responding with the code above. I tested your code, it is what I was looking for except that it is not saving the changes in profile. The “Save & continue” button works perfectly advancing to the next profile group however the button does not actually save the changes.


    amkh
    Participant

    @amkh

    Let me correct of what I mentioned in my reply above. I tested again and noticed it does not save while shifting/increment from profile group tab to tab but it does save on the last tab. Ideally as the button text says “Save and Continue” should first save changes and then proceed to next group tab.


    amkh
    Participant

    @amkh

    Now it does not even save even on the last profile group tab. I am lost now.


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Please comment out the code. I will check back what’s the issue there.


    amkh
    Participant

    @amkh

    Hi Prashant,
    I tried your code by replacing it with xprofile_updated_profile instead of xprofile_data_after_save. It worked perfectly.


    amkh
    Participant

    @amkh

    Thank you for your efforts and your excellent code. Is it possible to add an additional button called “Exit” next to “Save and Continue”? This will provide the ability to the users to exit at any stage instead of forcing them to complete the profile.


    Prashant Singh
    Participant

    @prashantvatsh

    Glad that it helped you 🙂

    Yes, please use this snippet:

    add_action('member-profile-edit', 'ps_exit_button');
    function ps_exit_button(){
    ?>
    <button type="button" name='exit' class='edit-exit' value="Exit"> Exit </button>
    <?php
    }
    add_action('wp_footer','ps_redirect_exit_profile');
    
    function ps_redirect_exit_profile(){
    ?>
    <script>
    	jQuery(document).ready(function(){
    		jQuery('.ps_exit_button').on('click',function(){
    			window.location.href= '<?php bp_displayed_user_domain()."profile/" ?>';
    		});
    	});
    </script>
    <?php
    }

    Hopefully, it will help you.

    Thanks


    amkh
    Participant

    @amkh

    I tried above code but the button does not appear.


    Prashant Singh
    Participant

    @prashantvatsh

    Which template pack of BuddyPress you are using? You can override edit.php and then after submit/save button add your HTML.

    Thanks


    amkh
    Participant

    @amkh

    I am using legacy template. I will edit edit.php and will get back to you.


    amkh
    Participant

    @amkh

    Hi Prashant,
    I added in child theme edit.php below submit button. It did’nt worked. However I tried this in edit.php below submit button and it worked.

    <input type="button" name="profile" id="profile" onClick="window.location.href='<?php echo bp_displayed_user_domain()."profile/";?>'" value="Exit"/>

    Can I know what is the advantage of using jQuery that you used in your snippet? If there is benefit then I would prefer to use your snippet.


    Prashant Singh
    Participant

    @prashantvatsh

    I am using legacy template. I will edit edit.php and will get back to you.

    That’s why code did not worked because it was for new template pack. Anyways, it’s ok your code is fine. For legacy we have do_action( 'bp_after_profile_field_content' ); and do_action( 'bp_after_profile_edit_content' ); hooks.

    Thanks


    amkh
    Participant

    @amkh

    Hi
    I would prefer to use your code instead of modifying the template. The reason is I do not want the exit button to be displayed on 2nd and 3rd profile group tabs. While I want it to be shown from profile group 4 onward. I have more than 6 profile group tabs now. Request you to kindly re-write the code for legacy template and taking above point into consideration that the button should only showup after group 4.
    Thank you very much in advance.


    Prashant Singh
    Participant

    @prashantvatsh

    First replace the code for redirection with this code, remember that we have to just change the redirect code not the translation code.

    function ps_redirect_next_group() {
    	
       	if ( ! bp_is_user_profile_edit() || ! bp_is_my_profile() ) {
    		return;
    	}
    	
    	$group_id = bp_get_current_profile_group_id()+1;
    	if ( bp_get_current_profile_group_id()==6 ) { 
                   // 6 is the last group id, please change if it is anything else
    		bp_core_redirect(bp_displayed_user_domain()."profile/");
    	}else{
    		bp_core_redirect(bp_displayed_user_domain()."profile/edit/group/$group_id/");
    	}
    	
    }
    add_action( 'xprofile_updated_profile', 'ps_redirect_next_group' );

    And now to show the button:

    add_action( 'bp_after_profile_edit_content' , 'ps_show_button_after_step');
    
    function ps_show_button_after_step(){
       if ( bp_get_current_profile_group_id()==4 ) {
        ?>
          <input type="button" name="profile" id="profile" onClick="window.location.href='<?php echo 
          bp_displayed_user_domain()."profile/";?>'" value="Exit"/>
        <?php
       }
    }

    Thanks


    amkh
    Participant

    @amkh

    It worked perfectly. Thanks


    Prashant Singh
    Participant

    @prashantvatsh

    Glad to know that it worked for you 🙂 Always welcome 🙂

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