HELP! Frontend User Profile Edit Won’t Update Email

Your code looks ok.

Maybe this line:

elseif(email_exists(esc_attr( $_POST['email'] )) != $current_user->id )

Should be

elseif(email_exists(esc_attr( $_POST['email'] )) != $current_user->ID )

Every developer should start with learning how to debug code.

Otherwise you’re just trying stuff like a headless chicken ;-).


WP Debugging
In your wp-config.php, change:

define( "WP_DEBUG", false );

Into:

define( "WP_DEBUG", true );// just toggle this line to false to turn off
if ( WP_DEBUG ) {
    define( "WP_DEBUG_DISPLAY", false );
    define( "WP_DEBUG_LOG", true );
    @ini_set( "display_errors", 0 );
    define( "SCRIPT_DEBUG", true );
}

Then install a debug log viewer plugin.


When you got the debug log up and running. Add error_log('debug log is working'); directly to your functions.php and check if it’s working.

Next, debug your code and check everything.

Example:

/* First check if the email is set correctly */
error_log('email: '.$_POST['email']);

/* Update user information. */
if ( !empty( $_POST['url'] ) )
   wp_update_user( array( 'ID' => $current_user->ID, 'user_url' => esc_url( $_POST['url'] ) ) );
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'] )));
  }
}

/* Check if there's an error */
error_log('error array: <pre>'.print_r($error,true).'</pre>'); 

Check everything untill you find the problem.

You can report back if you found something and you don’t know how to fix it.

Regards, Bjorn