wp cli - How to change user password with wp-cli?

admin2025-01-08  5

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.

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jun 30, 2015 at 15:27 thethe 1,5382 gold badges13 silver badges32 bronze badges 1
  • I have found that sudo definitely changes the path, so I have tried using --allow-root without sudo and the commands work – Ricardo Bolivia Commented Jun 15, 2020 at 21:01
Add a comment  | 

4 Answers 4

Reset to default 60

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.
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736269546a1360.html

最新回复(0)