I am trying to update a BuddyBoss Profile when a users wordpress profile is updated in the user edit page from the backend/admin. (Basically I want to sync the data). I have this function:
function BB_WP_SYNC_update_BB_profile( $user_id ) {
// Get user information
$country = get_user_meta($user_id, 'ofc_country', true);
error_log($country);
$region = get_user_meta($user_id, 'ofc_regional_organisation', true);
error_log($region);
$gender = get_user_meta($user_id, 'ofc_gender', true);
error_log($gender);
$dob = get_user_meta($user_id, 'ofc_date_of_birth', true);
$timestamp = strtotime(str_replace('/', '-', $dob));
$date = date('Y-m-d H:i:s', $timestamp);
//Update BuddyBoss Profile
xprofile_set_field_data('Country', $user_id, $country, true);
xprofile_set_field_data('Regional Organisation', $user_id, $region, true);
xprofile_set_field_data('Gender', $user_id, $gender, true);
xprofile_set_field_data('Date of Birth', $user_id, $date, true);
}
add_action( 'edit_user_profile_update', 'BB_WP_SYNC_update_BB_profile');
add_action( 'personal_options_update', 'BB_WP_SYNC_update_BB_profile');
The user information this function gets is the old information, prior to it being updated. For example, if I change the Country from Australia to Tahiti, then $country in my function is set to Australia.
I have to click the update profile button a second time for it to get the new value (which has obviously been set from the first click), and then it updates BuddyBoss correctly.
It seems that 'edit_user_profile_update' & 'personal_options_update' hook in before the user meta fields are updated.
Is there something else I can use to ensure both user meta fields & user fields are updated before the hook fires?