Feature: Manage WordPress users
- Scenario: Creating/updating/deleting users
+ Scenario: User CRUD operations
Given a WP install
When I run `wp user create testuser testuser@example.com --porcelain`
When I try the previous command again
Then the return code should be 1
- When I run `wp user update {USER_ID} --displayname=Foo`
- Then STDOUT should be:
- """
- Success: Updated user {USER_ID}.
- """
+ When I run `wp user update {USER_ID} --display_name=Foo`
+ And I run `wp user get {USER_ID}`
+ Then STDOUT should be a table containing rows:
+ | Field | Value |
+ | ID | {USER_ID} |
+ | display_name | Foo |
When I run `wp user delete {USER_ID}`
Then STDOUT should not be empty
--- /dev/null
+## OPTIONS
+
+* `[--format=<format>]`:
+
+ The format to use when printing the user; acceptable values:
+
+ **table**: Outputs all fields of the user as a table.
+
+ **json**: Outputs all fields in JSON format.
+
+* `<user>`:
+
+ User ID or user login.
+
+## EXAMPLES
+
+ wp user get 12
+
+ wp user get bob --format=json > bob.json
}
/**
+ * Get a single user.
+ *
+ * @synopsis [--format=<format>] <user>
+ */
+ public function get( $args, $assoc_args ) {
+ $assoc_args = wp_parse_args( $assoc_args, array(
+ 'format' => 'table'
+ ) );
+
+ $user = self::get_user( $args[0] )->to_array();
+
+ switch ( $assoc_args['format'] ) {
+
+ case 'table':
+ $this->assoc_array_to_table( $user );
+ break;
+
+ case 'json':
+ WP_CLI::print_value( $user, $assoc_args );
+ break;
+
+ default:
+ \WP_CLI::error( "Invalid value for format: " . $format );
+ break;
+
+ }
+ }
+
+ /**
* Delete one or more users.
*
* @synopsis <user>... [--reassign=<id>]