I am using PODS to add info to a users profile. I want to add data to the usermeta then do something with it right away. One the fields created by PODS is 'estimated_delivery_date'. I have simplified the code as show below.
add_action( 'profile_update', 'initiate_participant_profile_update', 10, 2 );
function initiate_participant_profile_update( $user_id, $old_user_data ) {
$estDD = get_user_meta( $user_id, 'estimated_delivery_date', true );
$pathBodyFile = dirname(__FILE__) . "/$user_id" . "ParticipantData.txt";
$fileBody = fopen($pathBodyFile, "a");
echo fwrite($fileBody, "Estimated Delivery Date: $estDD\n\n");
fclose($fileBody);
}
When I add the info using the Update User profile page $estDD does not appear in the file. But if I go back to the edit profile page and hit Update User again, boom, there it is.
So I am surmising the the action is running before the usermeta is updated. How can I fix this?
I am using PODS to add info to a users profile. I want to add data to the usermeta then do something with it right away. One the fields created by PODS is 'estimated_delivery_date'. I have simplified the code as show below.
add_action( 'profile_update', 'initiate_participant_profile_update', 10, 2 );
function initiate_participant_profile_update( $user_id, $old_user_data ) {
$estDD = get_user_meta( $user_id, 'estimated_delivery_date', true );
$pathBodyFile = dirname(__FILE__) . "/$user_id" . "ParticipantData.txt";
$fileBody = fopen($pathBodyFile, "a");
echo fwrite($fileBody, "Estimated Delivery Date: $estDD\n\n");
fclose($fileBody);
}
When I add the info using the Update User profile page $estDD does not appear in the file. But if I go back to the edit profile page and hit Update User again, boom, there it is.
So I am surmising the the action is running before the usermeta is updated. How can I fix this?
Share Improve this question edited Jul 15, 2020 at 16:15 vancoder 7,92428 silver badges35 bronze badges asked Jun 2, 2020 at 18:32 Johnnyboy GomezJohnnyboy Gomez 333 bronze badges1 Answer
Reset to default 0Not long after posing this question I figured it out. But since I had spent a few hours looking for the awswer I thought maybe it would be worth posting. I hope this does not break any rules. I changed the default priority from 10 to 11. as per:
add_action( 'profile_update', 'initiate_participant_profile_update', 10, 2 );
changed to
add_action( 'profile_update', 'initiate_participant_profile_update', 11, 2 );
So I guess the new function now waits for the user update to finish be fore running.