function wbcom_save_xprofile_to_usermeta_on_update($user_id) {
// Define the xProfile field names
$field_name_gender = 'Gender'; // Replace with your actual xProfile field name
$field_name_location = 'Location'; // Replace with your actual xProfile field name
// Get the xProfile field values
$gender_value = xprofile_get_field_data($field_name_gender, $user_id);
$location_value = xprofile_get_field_data($field_name_location, $user_id);
// Save the xProfile values as user meta with prefix 'xprofile_'
if ( ! empty( $gender_value ) ) {
update_user_meta($user_id, 'xprofile_gender', $gender_value);
}
if ( ! empty( $location_value ) ) {
update_user_meta($user_id, 'xprofile_location', $location_value);
}
}
// Hook the function to the xprofile_updated_profile action
add_action('xprofile_updated_profile', 'wbcom_save_xprofile_to_usermeta_on_update', 10, 1);
Comments