Skip to content

Commit

Permalink
Display user ID instead of user_login
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Feb 26, 2024
1 parent 66786b5 commit 06763ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 16 additions & 6 deletions features/super-admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ Feature: Manage super admins associated with a multisite instance
superadmin
"""

When I run `wp super-admin list --format=ids`
Then STDOUT should be:
"""
admin superadmin
"""

When I try `wp super-admin add superadmin`
Then STDERR should be:
"""
Expand Down Expand Up @@ -186,6 +180,22 @@ Feature: Manage super admins associated with a multisite instance
And STDOUT should be empty
And the return code should be 1

Scenario: List super admins in ids format.
Given a WP multisite installation

When I run `wp user get admin --field=ID`
And save STDOUT as {USER_1}

When I run `wp user create admin2 admin2@example.com --porcelain`
And save STDOUT as {USER_2}

When I run `wp super-admin add admin2`
And I run `wp super-admin list --format=ids`
Then STDOUT should be:
"""
{USER_1} {USER_2}
"""

Scenario: Manage a super admin user_login 'admin'
Given a WP multisite installation

Expand Down
8 changes: 7 additions & 1 deletion src/Super_Admin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public function list_subcommand( $_, $assoc_args ) {

if ( ! empty( $assoc_args['format'] ) && 'ids' === $assoc_args['format'] ) {
$formatter = new \WP_CLI\Formatter( $assoc_args );
$formatter->display_items( wp_list_pluck( $output_users, 'user_login' ) );

$user_ids = [];
foreach ( $super_admins as $user_login ) {
$user_obj = get_user_by( 'login', $user_login );
$user_ids[] = $user_obj->ID;
}
$formatter->display_items( $user_ids );
} else {
$formatter = new \WP_CLI\Formatter( $assoc_args, $this->fields );
$formatter->display_items( $output_users );
Expand Down

0 comments on commit 06763ac

Please sign in to comment.