2

With code below I try to update the email address of a user. The $_POST is correct, but the data is not saved into wp_users table.

    $user_id = $_POST['ID']; // correct ID
    wp_update_user( $user_id, 'user_email', $_POST['user_email']); // correct email address

Also tried this with success:

    wp_update_user( array( $user_id, 'user_email', $_POST['user_email']) );         

What is wrong with this update?

6

The function needs an array with the parameters. See The Codex. Also, you map the parameter with the value: ex. 'user_email' => $_POST['user_email'].

In your example the code would look like this:

    $user_id = (int) $_POST[ 'ID' ]; // correct ID
    wp_update_user( array(
        'ID' => $user_id,
        'user_email' => $_POST[ 'user_email' ]
   ) );  // correct email address

Also, the important hint: you should validate the data. Especially the data from the $_POST array. Maybe you're doing this and it is not in your example source.

1
  • If it works, the right answer, you should add the hook to the answer to help other users, there have the same problem, topic. Best. – bueltge Jul 5 '16 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.