Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xprofile_get_field_data is getting empty string from "date" field when used in "profile_update" hook #6

Open
newjie opened this issue Mar 6, 2023 · 0 comments

Comments

@newjie
Copy link

newjie commented Mar 6, 2023

 add_action('profile_update',function($user_id,$oldData,$newData){
   require_once('updateUsersToSheet.php');
   updateUsersToSheet($api_url,$user_id);
 },10,3);

I am using the above code to send user data to a google sheet when the profile is updated. I have a "date" field which allows user to choose their birthday, and its field_id is 33.
In updateUsersToSheet.php,if I do
var_dump(xprofile_get_field_data(33,$user_id));

It will output an empty string. However, if I put
var_dump(xprofile_get_field_data(33,$user_id)); in function.php, it will correctly output the users' birthday.

I also tried to get this data from custom api

// get User bDay
add_action( 'rest_api_init', 'returnUserBday' );
function returnUserBday(){
  register_rest_route( 'wsk/v1', '/userBday/', array(
      'methods' => 'GET',
      'callback' => 'getUserBday',
  ) );
}
function getUserBday( $request ) {
  $id = $request->get_param('id');
  $bday = xprofile_get_field_data(33,$id);

  $response = array(
      'bday' => $bday
  );
  return rest_ensure_response( $response );
}

It also outputs an empty string.

I have tried create another "html5 date picker" field, and it doesn't have this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant