• 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)
  • 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

    (@scottmcgready)

    Thanks for the response Josh. Hook what? profile update?

    Cheers,
    S

    What is the code you are trying to use? Is it a custom function in a child theme? Or a plugin?

    Thread Starter ScottMcGready

    (@scottmcgready)

    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

    (@scottmcgready)

    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));
    		}
    	}
    ...

    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

    (@scottmcgready)

    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: https://pastebin.com/i01tzqe1

    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

    (@scottmcgready)

    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.

    If you try to update the password, does it update correctly?

    Thread Starter ScottMcGready

    (@scottmcgready)

    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.

    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)) );
    }

    Hold on.. lemme think… lol

    Thread Starter ScottMcGready

    (@scottmcgready)

    It’s a weird one!

    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)
  • The topic ‘wp_update_user’ is closed to new replies.