wp-cli is great. But it's not clear how I can quickly change a user password with it.
How to change a user's password programatically can probably help to figure this out.
Although wp user update username --field=password
is not gonna cut it, apparently md5
is deprecated so it should go through wp_set_password
.
wp-cli is great. But it's not clear how I can quickly change a user password with it.
How to change a user's password programatically can probably help to figure this out.
Although wp user update username --field=password
is not gonna cut it, apparently md5
is deprecated so it should go through wp_set_password
.
This does the trick:
wp user update USERNAME --user_pass="PASSWORD"
(Found it here.)
first check the user name:
wp user list
then change password without leaving traces in history
wp user update admin --prompt=user_pass
Just to append one minor thing; sometimes the password may start with the = character. I prefer using this notation, just because of that.
wp user update USERNAME --user_pass="PASSWORD"
It's strange that no one mentioned about wp user reset-password
. Ref: https://developer.wordpress.org/cli/commands/user/reset-password/
By using wp user reset-password
, the new password is auto-generated (by WP). This method also helps to reset the password for all users (or users with a particular role).
Examples from the aforementioned link...
# Reset the password for two users and send them the change email.
$ wp user reset-password admin editor
Reset password for admin.
Reset password for editor.
Success: Passwords reset for 2 users.
# Reset and display the password.
$ wp user reset-password editor --show-password
Reset password for editor.
Password: N6hAau0fXZMN#rLCIirdEGOh
Success: Password reset for 1 user.
# Reset the password for one user, displaying only the new password, and not sending the change email.
$ wp user reset-password admin --skip-email --porcelain
yV6BP*!d70wg
# Reset password for all users.
$ wp user reset-password $(wp user list --format=ids)
Reset password for admin.
Reset password for editor.
Reset password for subscriber.
Success: Passwords reset for 3 users.
# Reset password for all users with a particular role.
$ wp user reset-password $(wp user list --format=ids --role=administrator)
Reset password for admin.
Success: Password reset for 1 user.