I am trying push user update fields to an api via user profile edit or admin user edit.
I have successfully allowed user to update their own profile and have it also update the remote api with same (new) update data.
I have had less success getting the admin side to work correctly.
if ( is_admin () ) {
add_action ( 'profile_update', 'myplugin_admin_update', 10, 2 );
//add_action ( 'edit_user_profile_update', 'myplugin_admin_update', 10, 2 );
// ^ Fires before form submit. Don't think I can use it.
...
}
function myplugin_admin_update ($user_id, $old_user_data) {
$user_meta = array_map( function( $a ){ return $a[0]; }, get_user_meta( $user_id ) );
...
}
I then basically send this meta off to another routine to be processed and sent. That part works fine.
The problem is the data is 'old'. Oddly, the data I pull from DB using hook profile_update is not the submitted/new data but the old data - contrary to description in api codex. I understand the hook delivers $old_data but I am not interested in that - just when it fires. I only need a hook that fires immediately after the admin updates a user. Not before. I need the newly submitted data.
profile_update This hook allows you to access data for a user immediately after their database information is updated
What am I doing wrong? I get 'old data' when i query DB on this hook.
EDIT:
I was only testing certain meta-fields as it turned out. I updated 'First Name' and it was the new value being posted to API. Other fields show old data sent to api as mentioned above.
I didn't mention in original post that these meta fields reading as old data are 'WP Member' plugin fields (added via plugin). They are still stored in usermeta in DB, though.
If I click 'Update' twice on the user I am able to update API all with new values but, this seems a feeble work-around.
So, now the question is: Why are only some meta values reading as new values?