diff --git a/features/user.feature b/features/user.feature index 8e93ca370..3537f0899 100644 --- a/features/user.feature +++ b/features/user.feature @@ -152,6 +152,26 @@ Feature: Manage WordPress users Then STDERR should not be empty And the return code should be 1 + Scenario: Trying to delete existing user with no roles from a subsite + Given a WP multisite install + + When I run `wp user create bobjones bob@example.com --role=author --url=https://example.com --porcelain` + And save STDOUT as {BOB_ID} + + When I run `wp user delete bobjones --yes` + Then STDOUT should contain: + """ + Success: Removed user + """ + And STDERR should be empty + + When I try `wp user delete bobjones --yes` + Then STDERR should be: + """ + Warning: No roles found for user {BOB_ID} on https://example.com, no users deleted. + """ + And the return code should be 1 + @require-wp-4.0 Scenario: Trying to delete super admin Given a WP multisite install diff --git a/src/User_Command.php b/src/User_Command.php index 1ba1d6db0..baf7a72c5 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -295,6 +295,9 @@ function ( $user ) use ( $network, $reassign ) { if ( $network ) { $result = wpmu_delete_user( $user_id ); $message = "Deleted user {$user_id}."; + } elseif ( is_multisite() && empty( $user->roles ) ) { + $message = "No roles found for user {$user_id} on " . home_url() . ', no users deleted.'; + return [ 'error', $message ]; } else { $result = wp_delete_user( $user_id, $reassign ); $message = "Removed user {$user_id} from " . home_url() . '.';