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