To update a user's password, you need to:
- Set up an ACF field so the user can enter their password.
- Hook into the af/form/editing/user_updated filter to get the value from the designated field using af_get_field('FIELD_NAME').
- 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
Feedback sent
We appreciate your effort and will try to fix the article