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?

1 Answer
1

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' ];
    wp_update_user( array(
        'ID' => $user_id,
        'user_email' => $_POST[ 'user_email' ]
   ) );

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *