Add an Action when Profile field is updated
-
Hi.
So I’m using Gravity Forms User Add On and Autochimp. What was happening was that Gravity Forms updated buddypress profile fields using the function: xprofile_set_field_data() but Autochimp was not updating the subscribers list with this information.
Autochimp updates your subscriber list with buddypress profile fields when the buddypress profile fields are updated, it uses this action: xprofile_updated_profile
However, this action: “xprofile_updated_profile” is only available here: bp-xprofile-admin.php line 659 in function user_admin_load() and here: bp-xprofile-screens.php in line 134 in function xprofile_screen_edit_profile(). It is not available in the function xprofile_set_field_data() that Gravity Forms and many other plugins use.
The action should also exist in the function xprofile_set_field_data() in the file bp-xprofile-functions.php .
However, my php level is 5 out of 10 and the format of filters/hooks and object programming is still not 100% clear to me.
If I add the action below “return $field->save();” I assume it won’t happen since the function ends at return, yes?
But I also can’t add it before because the data has not saved and there might be some errors. I saw there were 3 save() functions in bp-xprofile-clases.php and couldn’t figure out which one was being called.
All 3 functions do have this action: “xprofile_data_after_save” but it’s an array and I have no idea how to manage that.
This is how Mailchimp calls the action:
add_action('xprofile_updated_profile', array( $this, 'OnBuddyPressUserUpdate' ), 101 );
inside this function
public function SyncBuddyPress() { // Used to sync users with MailChimp add_action('xprofile_updated_profile', array( $this, 'OnBuddyPressUserUpdate' ), 101 ); add_action('bp_core_signup_user', array( $this, 'OnBuddyPressUserUpdate' ), 101 ); }
And the function the action calls is this:
public function OnBuddyPressUserUpdate( $user_id = 0 ) { if ( 0 == $user_id ) { // Get the current user $user = wp_get_current_user(); } else { $user = get_userdata( $user_id ); } // Pass their ID to the function that does the work. AC_OnUpdateUser( $user->ID, $user, TRUE ); }
I have multiple questions:
– why does the action get called with an array? what’s $this?
– how can I make Autochimp update when this function is called: xprofile_set_field_data()Thank you in advance!
- The topic ‘Add an Action when Profile field is updated’ is closed to new replies.