BuddyDev

Search

[Resolved] Hook when profile fields are updated from specific group.

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #47460

    Hello great team 🙂

    I am using the xprofile_updated_profile hook to pass an action but i would like to know if it is possible to pass the action:
    1. only when fields from one specific field group are getting updated
    2. when the fields are actually with new values.

    Something like:
    `add_action( ‘xprofile_updated_profile’, ‘my_action’ );
    function my_action {
    if ( group of fields with id || group of fields with id ) {
    //do action
    }`

    I don’t want to trigger my action just when user is clicking the save button in general.

    Thank you for your help.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #47462

    Hello Lefteris,

    Thank you for posting. BuddyPress does not provide any specific hook for specific field group update. But you can check field group updates in the following way:

    
    add_action( 'xprofile_updated_profile', function ( $user_id, $post_field_ids, $errors, $old_values, $new_values ) {
    
    	// Check the field group exists.
    	if ( ! bp_is_action_variable( 'group' ) || ! bp_action_variable( 1 ) ) {
    		return;
    	}
    
    	$group_id = bp_action_variable( 1 );
    
    	// Check for your field group ids.
    	$check_for_ids = array( 2 );
    
    	if ( in_array( $group_id, $check_for_ids ) ) {
              // work with your code here.
    	}
    }, 10, 5 );
    
    

    Please try it and let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #47469

    Thank you so much Ravi,

    It works as it should!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #47489

    Hello Lefteris,

    Thank you for the acknowledgment. I am glad that I could help.

    Regards
    Ravi

The topic ‘ [Resolved] Hook when profile fields are updated from specific group.’ is closed to new replies.

This topic is: resolved