BuddyDev

Search

Profile Edit Fields / Tabs

  • Participant
    Level: Initiated
    Posts: 15
    enrons on #122

    Hi,

    i hope you can help me. I try many thinks, but nothing should works.

    I try to display only one specific profile fields to edit it.
    In this example codes always the first group show (Base).

    bp_get_template_part( ‘members/single/profile/edit’)
    bp_get_template_part( ‘members/single/profile/edit/group/4’)

    How can i get to output a specific profile tabs in and outside members-loop ?

    Many Thanks !

  • Participant
    Level: Enlightened
    Posts: 22
    Anu Sharma on #123

    Hi Enrons,
    Welcome to the BuddyDev forum.

    To answer your question, let us inspect the edit template. If you open the yourtheme/members/single/profile/edit.php ( or buddypress/members/single/profile/edit.php ), you will see at the top a line, something like this

    
    if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) :
    	while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
    

    bp_has_profile() function is responsible for building the loop. Note that bp_has_profile is passing the ‘profile_group_id’ as argument.

    The function

    
    bp_get_current_profile_group_id()
    

    returns specific group id(if you are viewing edit profile group, e.g. example.com/members/yourname/profile/edit/group/2/ will return 2), in all other cases, the function returns 1.

    So, if you are not on edit profile group, the function always returns 1. 1 is the ID of base profile group, that’s why it is always showing base profile group.

    Note:-
    Please do not use

    
    bp_get_template_part( 'members/single/profile/edit/group/4')
    

    That line assumes you have a file named 4.php in your members/single/profile/edit/group/ folder in your theme( I don’t think that was your intention ).

    Now, let us talk about the solutions to your issue:-

    Method 1:-

    Filter on ‘bp_get_current_profile_group_id’ like this

    
    
    add_filter('bp_get_current_profile_group_id', 'my_profile_group_id');
    
    function my_profile_group_id( $profile_group_id ) {
    
    if( $somecondition & this is my page ) {//replace this line with your condition
    $profile_group_id = 3;//or any other group id
    
    }
    
    return $profile_group_id;
    }
    
    

    Or Method 2:-

    Filter on ‘bp_before_has_profile_parse_args’ or ‘bp_after_has_profile_parse_args’ and modify the group. I prefer the 2nd hook as it gives parsed arguments.

    Example:-

    
    add_filter( 'bp_after_has_profile_parse_args', 'buddydev_modify_profile_edit_loop' );
    
    function buddydev_modify_profile_edit_loop( $args ) {
    
    	//check if it is not our page, just return the args
    	if( ! $my_page ) { //modify it for the condition
    
    		return $args;
    	}
    
    	//it is our page, modify the values
    	$args['profile_group_id'] = 3;//change the profile group id
    
    	//you can change the following fields too
    	//possible fields are
    	//$args['user_id'] = bp_loggedin_user_id();// ,
    	//$args['hide_empty_groups'] = true;// hide empty group?
    	//$args['hide_empty_fields'] = false;
    	//$args['exclude_groups']    = '1,3';//change it, It is comma separated list of profile groups ids to exclude
    	//$args['exclude_fields']   = '';// // Comma-separated list of profile field IDs to exclude
    	
    	return $args;
    }
    

    I have listed all the interesting options it provides and you can uncomment and use any of those to modify the loop

    Method 3:-

    I will personally prefer it as it is much simple.

    Make a copy of yourtheme/members/single/profile/edit.php, include it wherever you want. Just make sure to modify the line

    
    bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) 
    
    

    to anything like this

    
    $args = array(
    'profile_group_id'=> 'some group_id',
    //all other available options are same from the step 2.
    );
    bp_has_profile( $args ) 
    

    Hope you choose the right approach that suits your need. Please do let me now if you need any further help.

    Have a great day.
    Anu

  • Participant
    Level: Initiated
    Posts: 15
    enrons on #124

    Thank you so much for your work !!!!!!!! 🙂 😉

    Now i have to find a way,
    how can i get two conditions in one template-site.

    In Example:

    Button One == open group_id 3
    Button Two == open group_id 6

    But only one condition works.
    I think after .. 😉

  • Participant
    Level: Initiated
    Posts: 15
    enrons on #125

    With php if else conditions ?

    Button One – Button Two .. ?

    I try it later .. 😉

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #126

    Hi Enrons
    Just wanted to put my thoughts on your question.

    Though Anu has gone into details, It is not very clear for what you want to accomplish.

    here is the step you need to do.

    1. There is no way to reuse BuddyPress edit profile template ( without any modification ) to show single field(single group is fine, you can show that).

    2. Your strategy should be create a form and use xprofile_get_field_data to fetch the field data and fillup the form.

    3. Then, you will need to write a custom action handler, that will use xprofile_set_field_data function to update the field.

    To make it easier for the user, you may want to do the update via ajax.

    PS: Are you comfortable with code or do you ant to see a snippet? I will be happy to provide a code snippet( Though I am a little busy, so will need a few days before I can do that ).

  • Participant
    Level: Initiated
    Posts: 15
    enrons on #127

    Hi ! 😉 😉

    Yes, my special requests always, i know 😉

    I will think and test about that, otherwise i write you and pay for that function. Because i need other things, too (little thing). But i try it first of my own.

    Many thanks for the codes (Anu Sharma & Brajesh) !

You must be logged in to reply to this topic.

This topic is: not resolved