Advertisement
vapvarun

Save xProfile values as user meta whenever a profile is updated

Jun 25th, 2024
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | Source Code | 0 0
  1. function wbcom_save_xprofile_to_usermeta_on_update($user_id) {
  2.     // Define the xProfile field names
  3.     $field_name_gender = 'Gender'; // Replace with your actual xProfile field name
  4.     $field_name_location = 'Location'; // Replace with your actual xProfile field name
  5.  
  6.     // Get the xProfile field values
  7.     $gender_value = xprofile_get_field_data($field_name_gender, $user_id);
  8.     $location_value = xprofile_get_field_data($field_name_location, $user_id);
  9.  
  10.     // Save the xProfile values as user meta with prefix 'xprofile_'
  11.     if ( ! empty( $gender_value ) ) {
  12.         update_user_meta($user_id, 'xprofile_gender', $gender_value);
  13.     }
  14.  
  15.     if ( ! empty( $location_value ) ) {
  16.         update_user_meta($user_id, 'xprofile_location', $location_value);
  17.     }
  18. }
  19.  
  20. // Hook the function to the xprofile_updated_profile action
  21. add_action('xprofile_updated_profile', 'wbcom_save_xprofile_to_usermeta_on_update', 10, 1);
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement