Update Mail from Frontend Profile Page

Hi there, I’m trying to create a frontend profile page for users in WordPress following this post: How to edit a user profile on the front end?

So far everything is working, however I can’t make the mail field to update. Here’s the current code I’m dealing with:

if ( !empty( $_POST['email'] ) ){ if (!is_email(esc_attr( $_POST['email'] ))){ $error[] = __('The Email you entered is not valid. please try again.', 'profile'); } elseif (email_exists(esc_attr( $_POST['email'] )) != $current_user->id ) { $error[] = __('This email is already used by another user. try a different one.', 'profile'); } else { wp_update_user( array ('ID' => $current_user->ID, 'user_email' => esc_attr( $_POST['email'] ))); } }

And the form has this:

`


<?php _e('E-mail *', 'profile'); ?>

`

So, when you load up the page it shows the current mail assigned to your user ID.
If you place something else that’s not a mail in the field, you get the error of having it wrong.

That works perfectly, however when you type any other mail it displays the error that ‘This email is already used by another user. try a different one.’ and that’s the error. There’re no other users besides a dummy one and my admin account. So no matter what type of mail you get there you’re stuck with that error.
And when you get that, the field is autopopulated to the “old” mail.

Any hints/clues/comments?

Thanks in advance!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.