Title: wp_update_user
Last modified: August 21, 2016

---

# wp_update_user

 *  [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/)
 * Hey guys,
 * Seems like I’ve got a bit of a problem with wp_update_user. What I’ve got is 
   some code to insert a new value into the db using wp_update_user, then afterwards
   I’m getting the current user information. Problem is the query to get the current
   user information seems to be 1 behind when it comes to the email address, everything
   else is fine however the email address is always incorrect. I refresh and the
   information is correct.
 * Any ideas?

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/wp_update_user-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp_update_user-1/page/2/?output_format=md)

 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852024)
 * You need to “hook” to an earlier hook. Probably “init” or “plugins_init”… depending
   on your circumstances.
 * Without seeing the code, that’s the best I can do 🙂
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852025)
 * Thanks for the response Josh. Hook what? profile update?
 * Cheers,
    S
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852027)
 * What is the code you are trying to use? Is it a custom function in a child theme?
   Or a plugin?
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852028)
 * It’s a custom plugin. Basically displaying bits of the current user info and 
   allowing them to change certain bits. everything else is cool, it’s just the 
   email address seems to lag one behind. If I submit then refresh, it’s all good.
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852030)
 * And just for good measure:
 *     ```
       if($differences != NULL){
       	foreach($differences as $diffkey=>$diffval){
       		if($diffkey == "user_email" || $diffkey == "user_pass"){
       			wp_update_user( array('ID' => $current_userq->ID, 'user_email' => esc_attr($diffval)) );
       			wp_update_user( array('ID' => $current_userq->ID, 'user_pass' => esc_attr($diffval)) );
       		}else{
       			update_user_meta($current_userq->ID, esc_attr($diffkey), esc_attr($diffval));
       		}
       	}
       ...
       ```
   
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852031)
 * Okay, let me see the rest of that function. Also, what “hook” are you using for
   the function? Are you using “add_action()”?
 * If the function is too big, please use pastebin.com and include a link here to
   the code.
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852032)
 * Nah, its a shortcode. after the wp_update_user, should I be calling anything?
   Everything else seems to update fine, just that email address thing is weird.
   Here’s the link: [http://pastebin.com/i01tzqe1](http://pastebin.com/i01tzqe1)
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852048)
 * Hmmm… everything looks okay.
 * Let’s try hooking the entire function to the “init” hook.
 * So, add this line either directly above the function, or directly after the function:
 *     ```
       add_action('init', 'test_merchant_store_settings');
       ```
   
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852049)
 * Nope, still an issue. Seems like a weird one to me. I’ve tried wp_create_user
   too but to no avail. It’s a tricky one.
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852052)
 * If you try to update the password, does it update correctly?
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852054)
 * indeed it does. Weird thing is, sometimes the email address field goes blank 
   and even although I’ve put a catch in to check for null password fields, it goes
   through sometimes as blank. Could be related.
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852056)
 * Okay… let’s try changing this code:
 *     ```
       if($diffkey == "user_email" || $diffkey == "user_pass"){
   
            wp_update_user( array('ID' => $current_userq->ID, 'user_email' => esc_attr($diffval)) );
   
            wp_update_user( array('ID' => $current_userq->ID, 'user_pass' => esc_attr($diffval)) );
       ```
   
 * To this:
 *     ```
       if($diffkey == "user_email") {
           wp_update_user( array('ID' => $current_userq->ID, 'user_email' => esc_attr($diffval)) );
       }
       elseif($diffkey == "user_pass") {
            wp_update_user( array('ID' => $current_userq->ID, 'user_pass' => esc_attr($diffval)) );
       }
       ```
   
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852058)
 * Hold on.. lemme think… lol
 *  Thread Starter [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * (@scottmcgready)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852059)
 * It’s a weird one!
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/#post-3852060)
 * Okay… try this:
 *     ```
       if($diffkey == "user_email") {
           wp_update_user( array('ID' => $current_userq->ID, 'user_email' => esc_attr($diffval)) );
       }
       if($diffkey == "user_pass") {
           wp_update_user( array('ID' => $current_userq->ID, 'user_pass' => esc_attr($diffval)) );
       }
       if($diffkey != "user_email" || $diffkey != "user_pass") {
           update_user_meta($current_userq->ID, esc_attr($diffkey), esc_attr($diffval));
       }
       ```
   

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/wp_update_user-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp_update_user-1/page/2/?output_format=md)

The topic ‘wp_update_user’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 16 replies
 * 2 participants
 * Last reply from: [ScottMcGready](https://wordpress.org/support/users/scottmcgready/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/wp_update_user-1/page/2/#post-3852062)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
