WordPress hook fires before, not after the call
-
What I’m triyng to achieve is working with the WP REST API and hooking the user meta data update.
Here’s the link to the action reference:
https://codex.wordpress.org/Plugin_API/Action_Reference/updated_%28meta_type%29_metawhere it says:
“This hook is called after a call to update_metadata succeeds. ”
This is the code:
add_action( 'updated_user_meta', 'second_otp', 10, 4 ); function second_otp($meta_id, $object_id, $meta_key, $_meta_value) { $otp = $_meta_value; $message = "Your OTP =" . get_user_meta($object_id, "otp", true ) . get_user_meta($object_id, "nickname", true ); $to = 'myemail@msn.com'; $subject = 'OTP'; $body = $message; $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail( $to, $subject, $body, $headers ); };But the action “updated_user_meta” is triggered BEFORE the meta field is written. E.g. if the user has the OTP=”1111″, and I send this json
{ "id": "31", "roles": "verified", "meta": {"otp":"2222"} }to the
http://MYSITE/dev/index.php/wp-json/wp/v2/users/31/endpoint
I will get an email with the body:“Your OTP = 1111”
Is there anything I haven’t counted, that would help me to email the new OTP of the user, that I’m sending via REST api, and not the old one?
The topic ‘WordPress hook fires before, not after the call’ is closed to new replies.