最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

user meta - profile_update works on second update only

programmeradmin4浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Not 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.

发布评论

评论列表(0)

  1. 暂无评论