Skip to content

Commit 3c31e7e

Browse files
authored
Reset user password send error when no user is found (#271)
Reset user password send error when no user is found
2 parents 4ad5a52 + 9f94eca commit 3c31e7e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5216,7 +5216,7 @@ wp user reset-password <user>... [--skip-email]
52165216
$ wp user reset-password admin editor
52175217
Reset password for admin.
52185218
Reset password for editor.
5219-
Success: Passwords reset.
5219+
Success: Passwords reset for 2 users.
52205220

52215221

52225222

features/user-reset-password.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Feature: Reset passwords for one or more WordPress users.
1111
Then STDOUT should contain:
1212
"""
1313
Reset password for admin.
14-
Success: Password reset.
14+
Success: Password reset for 1 user.
1515
"""
1616
And an email should be sent
1717

@@ -32,7 +32,7 @@ Feature: Reset passwords for one or more WordPress users.
3232
Then STDOUT should contain:
3333
"""
3434
Reset password for admin.
35-
Success: Password reset.
35+
Success: Password reset for 1 user.
3636
"""
3737
And an email should not be sent
3838

src/User_Command.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ public function import_csv( $args, $assoc_args ) {
10791079
* $ wp user reset-password admin editor
10801080
* Reset password for admin.
10811081
* Reset password for editor.
1082-
* Success: Passwords reset.
1082+
* Success: Passwords reset for 2 users.
10831083
*
10841084
* @subcommand reset-password
10851085
*/
@@ -1102,7 +1102,15 @@ public function reset_password( $args, $assoc_args ) {
11021102
if ( $skip_email ) {
11031103
remove_filter( 'send_password_change_email', '__return_false' );
11041104
}
1105-
WP_CLI::success( count( $users ) > 1 ? 'Passwords reset.' : 'Password reset.' );
1105+
1106+
$reset_user_count = count( $users );
1107+
if ( 1 === $reset_user_count ) {
1108+
WP_CLI::success( "Password reset for {$reset_user_count} user." );
1109+
} elseif ( $reset_user_count > 1 ) {
1110+
WP_CLI::success( "Passwords reset for {$reset_user_count} users." );
1111+
} else {
1112+
WP_CLI::error( 'No user found to reset password.' );
1113+
}
11061114
}
11071115

11081116
/**

0 commit comments

Comments
 (0)