Issue with wp_update_user
-
I have some custom code where I allow an user to change his name, lastname and email through a form.
On form submission, I handle the _POST data to set the desired values for the current_user, but this seems to work only with custom metadata and update_user_meta(). These values do get changed and stay with the new setting.
Any call to wp_update_user() causes a weird “temporary” update, showing the updated values only the first time that the page handling _POST data is loaded. Any subsequent loading of that same page shows the original values. This means I change say the firstname from John to Peter and I see Peter only when I load the page for the first time. Then John comes back.
This is the code of the handler:
/* get current user and set up script vars */ $current_user = wp_get_current_user(); $id = $current_user->ID; $key = ''; $value = ''; /* update custom meta field phonenumber */ if(isset($_POST['updated_phone'])) { $key = 'user_customfield_phonenumber'; $value = $_POST['updated_phone']; update_user_meta($id,$key,$value); } /* update field firstname */ if(isset($_POST['updated_name'])) { $value = $_POST['updated_name']; wp_update_user( array ( 'ID' => $id, 'user_firstname' => $value ) ) ; }
This is how I show the user’s details after calling the handler, the code is clean of all the formatting:
/* get current user and set up script vars */ $current_user = wp_get_current_user(); $id = $current_user->ID; $tempkey = ''; $single = true; /* display users firstname */ echo 'First Name: ' . $current_user->user_firstname; /* display users custom meta phone */ $tempkey = 'user_customfield_phonenumber'; echo $current_user->__get($tempkey);
Any ideas?
- The topic ‘Issue with wp_update_user’ is closed to new replies.