Skip to content

Commit

Permalink
Reset user password send error when no user is found (#271)
Browse files Browse the repository at this point in the history
Reset user password send error when no user is found
  • Loading branch information
schlessera committed Nov 12, 2019
2 parents 4ad5a52 + 9f94eca commit 3c31e7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5216,7 +5216,7 @@ wp user reset-password <user>... [--skip-email]
$ wp user reset-password admin editor
Reset password for admin.
Reset password for editor.
Success: Passwords reset.
Success: Passwords reset for 2 users.



Expand Down
4 changes: 2 additions & 2 deletions features/user-reset-password.feature
Expand Up @@ -11,7 +11,7 @@ Feature: Reset passwords for one or more WordPress users.
Then STDOUT should contain:
"""
Reset password for admin.
Success: Password reset.
Success: Password reset for 1 user.
"""
And an email should be sent

Expand All @@ -32,7 +32,7 @@ Feature: Reset passwords for one or more WordPress users.
Then STDOUT should contain:
"""
Reset password for admin.
Success: Password reset.
Success: Password reset for 1 user.
"""
And an email should not be sent

Expand Down
12 changes: 10 additions & 2 deletions src/User_Command.php
Expand Up @@ -1079,7 +1079,7 @@ public function import_csv( $args, $assoc_args ) {
* $ wp user reset-password admin editor
* Reset password for admin.
* Reset password for editor.
* Success: Passwords reset.
* Success: Passwords reset for 2 users.
*
* @subcommand reset-password
*/
Expand All @@ -1102,7 +1102,15 @@ public function reset_password( $args, $assoc_args ) {
if ( $skip_email ) {
remove_filter( 'send_password_change_email', '__return_false' );
}
WP_CLI::success( count( $users ) > 1 ? 'Passwords reset.' : 'Password reset.' );

$reset_user_count = count( $users );
if ( 1 === $reset_user_count ) {
WP_CLI::success( "Password reset for {$reset_user_count} user." );
} elseif ( $reset_user_count > 1 ) {
WP_CLI::success( "Passwords reset for {$reset_user_count} users." );
} else {
WP_CLI::error( 'No user found to reset password.' );
}
}

/**
Expand Down

0 comments on commit 3c31e7e

Please sign in to comment.