How to update a user's password from a form field

Created by Phil Kurth, Modified on Fri, 04 Nov 2022 at 05:12 PM by Phil Kurth

To update a user's password, you need to:


  1. Set up an ACF field so the user can enter their password.
  2. Hook into the af/form/editing/user_updated filter to get the value from the designated field using af_get_field('FIELD_NAME').
  3. Set the new password using the wp_set_password() function.


add_action( 'af/form/editing/user_updated', function ( $user, $form, $args ) {

  // If we aren't handling the desired form, return early.
  if ( $form['key'] !== 'FORM_KEY_HERE' ) {
    return;
  }

  // Get the password from the submitted field.
  $password = af_get_field( 'password_field' );

  // Set the password for the user. Note that this will log the user out.
  wp_set_password( $password, $user->ID );

  // Set the auth cookie so the user is logged back in immediately.
  wp_set_auth_cookie( $user->ID );

}, 10, 3 );

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article