Skip to content

Commit

Permalink
Warn when deleting multisite user with no blog roles (#408)
Browse files Browse the repository at this point in the history
* Show error message when multisite user to delete has no blog roles(#403)

* Fix tests and phpcs

* Replace --yes removed to test

* Specify expected output on subsite user delete

* Make subsite user delete test less specific
  • Loading branch information
MannyAdumbire authored Jun 9, 2023
1 parent 1f013e1 commit 5c14109
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() . '.';
Expand Down

0 comments on commit 5c14109

Please sign in to comment.