do_action( ‘wp_update_user’, int $user_id, array $userdata, array $userdata_raw )

Fires after the user has been updated and emails have been sent.


The ID of the user that was just updated.
The array of user data that was updated.
The unedited array of user data that was updated.


do_action( 'wp_update_user', $user_id, $userdata, $userdata_raw );



User Contributed Notes

  1. Skip to note 2 content

    Here’s an example code snippet to demonstrate the usage of the do_action function with the 'wp_update_user' action in a WordPress context:

    // Define a function that will be executed when 'wp_update_user' action is triggered
    function custom_user_update_action($user_id, $userdata, $userdata_raw) {
        // You can add your custom code here
        // For example, let's log the user ID and updated email address
        error_log('User ID ' . $user_id . ' updated their email to: ' . $userdata['user_email']);
    // Hook the custom function to the 'wp_update_user' action
    add_action('wp_update_user', 'custom_user_update_action', 10, 3);
    // Simulate an update to user information (this would be an actual user update)
    $user_id = 123;
    $updated_userdata = array(
        'user_email' => '',
        // Other updated user data fields go here...
    // Trigger the 'wp_update_user' action with the simulated update
    do_action('wp_update_user', $user_id, $updated_userdata, $updated_userdata);

    Explanation of the code:

    1. We define a custom function custom_user_update_action that takes three parameters: $user_id, $userdata, and $userdata_raw. Inside this function, you can write any custom code you want to execute when a user’s information is updated. In this example, we’re just logging the user ID and the updated email address.
    2. We use the add_action function to attach our custom function custom_user_update_action to the 'wp_update_user' action. This means that whenever the ‘wp_update_user’ action is triggered, our custom function will be called.
    3. In this simulated example, we set the $user_id to 123 (which would be the actual user ID) and create an array $updated_userdata containing the updated user data. This could include changes to the user’s email, display name, or any other relevant fields.
    4. Finally, we use the do_action function to manually trigger the 'wp_update_user' action with the provided parameters. This simulates an update to the user’s information and will cause our custom function to be executed.

    Remember that in a real WordPress environment, these actions and hooks are automatically triggered by various processes within WordPress, and developers can use them to add their own custom functionality at specific points in the system’s execution.

You must log in before being able to contribute a note or feedback.