diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aee2cfc..1b2f65e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,7 @@ jobs: steps: - name: Cancel previous runs of this workflow (pull requests only) if: ${{ github.event_name == 'pull_request' }} - uses: styfle/cancel-workflow-action@0.5.0 + uses: styfle/cancel-workflow-action@0.12.0 with: access_token: ${{ github.token }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 319f799..dec311e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C * Support for the `--format` flag of the `generate` commands. One can render an output in a particular format. * New commands: * `wp bp notice` - Use it to manage Sitewide notices. - * `wp bp tool reinstall` - Alias of the `wp bp email reinstall` command, we will deprecate the latter in the future. * `delete-comment` and `remove-comment` aliases added for the `wp bp activity` command. ### Changed @@ -19,21 +18,24 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C * Prefer short array syntax (This is different from WCS supports) * Composer packages upgraded to their latest versions * Several linting updates -* CI tests against PHP 8.3 now +* CI tests against PHP 8.3 * Updated deprecated function from `bp_get_group_permalink` into `bp_get_group_url` -* Activity command: make tests more deterministic +* Activity command: made tests more deterministic * PHPDoc improvements * All `generate` commands' output were standardized * All `create` commands' output were standardized * All `delete` commands' output were standardized * All `delete` commands' alias were standardized + * All `list` commands were standardized * Invalid `format` option `haml` removed - * `post-update` command updated to remove mention of default text creation + * `wp bp activity post-update`: removed mention of default text creation + * Removed `user_items` and `items` aliases from the `wp bp activity favorite list` command * Confirmation message updated for `delete` commands that accepts multiple values * `wp bp group invite remove` updated to `wp bp group invite uninvite` to avoid conflict with the `delete/remove` command * `wp bp activity delete_comment` updated to `wp bp activity delete-comment` * `generate` commands: avoid refetching user objects * All `generate` command pass the `silent` flag +* Upgraded the `styfle/cancel-workflow-action` Github Action. ## 2.0.2 diff --git a/composer.json b/composer.json index 1f201d7..9a153ae 100644 --- a/composer.json +++ b/composer.json @@ -78,6 +78,7 @@ "wp bp tool", "wp bp signup", "wp bp xprofile", + "wp bp notice", "wp bp xprofile field", "wp bp xprofile group", "wp bp xprofile data", diff --git a/features/group-member.feature b/features/group-member.feature index ee83aeb..7ec1b67 100644 --- a/features/group-member.feature +++ b/features/group-member.feature @@ -28,9 +28,9 @@ Feature: Manage BuddyPress Group Members Success: Added user #{MEMBER_ID} to group #{GROUP_ID} as member. """ - When I run `wp bp group member list {GROUP_ID} --fields=user_id` + When I run `wp bp group member list {GROUP_ID} --fields=id` Then STDOUT should be a table containing rows: - | user_id | + | id | | {CREATOR_ID} | | {MEMBER_ID} | @@ -40,9 +40,9 @@ Feature: Manage BuddyPress Group Members Success: Member promoted to new role successfully. """ - When I run `wp bp group member list {GROUP_ID} --fields=user_id --role=mod` + When I run `wp bp group member list {GROUP_ID} --fields=id --role=mod` Then STDOUT should be a table containing rows: - | user_id | + | id | | {MEMBER_ID} | When I run `wp bp group member demote --group-id={GROUP_ID} --user-id={MEMBER_ID}` @@ -79,8 +79,3 @@ Feature: Manage BuddyPress Group Members """ Success: Member #{MEMBER_ID} removed from the group #{GROUP_ID}. """ - - When I run `wp bp group member list {GROUP_ID} --fields=user_id --role=member,admin,mod,banned` - Then STDOUT should be a table containing rows: - | user_id | - | {CREATOR_ID} | diff --git a/features/message.feature b/features/message.feature index 1f6857e..2b328f7 100644 --- a/features/message.feature +++ b/features/message.feature @@ -81,6 +81,7 @@ Feature: Manage BuddyPress Messages | sender_id | | {BOB_ID} | | {SALLY_ID} | + | {BOB_ID} | When I run `wp bp message list --user-id={SALLY_ID} --fields=thread_id,sender_id,subject,message` Then STDOUT should be a table containing rows: diff --git a/features/tool.feature b/features/tool.feature index ef66fdc..10f3506 100644 --- a/features/tool.feature +++ b/features/tool.feature @@ -21,9 +21,3 @@ Feature: Manage BuddyPress Tools """ Success: Signup tool updated. """ - - When I run `wp bp tool reinstall --yes` - Then STDOUT should contain: - """ - Success: Emails have been successfully reinstalled. - """ diff --git a/readme.md b/readme.md index 3e9136e..7b659e3 100644 --- a/readme.md +++ b/readme.md @@ -2,8 +2,6 @@ Manage BuddyPress through the command-line. -Quick links: [Installing](#installing) | [Using](#using) | [Support](#support) - ## Installing The `wp-cli-buddypress` comes installed by default with BuddyPress. So if you need to use the latest version, run: @@ -12,7 +10,7 @@ The `wp-cli-buddypress` comes installed by default with BuddyPress. So if you ne wp package install git@github.com:buddypress/wp-cli-buddypress.git ``` -In many cases the default memory limit will not be enough to run composer so running the following instead is generally recommended: +In many cases the default memory limit will not be enough to run composer, so running the following instead is generally recommended: ```bash php -d memory_limit=512M "$(which wp)" package install git@github.com:buddypress/wp-cli-buddypress.git diff --git a/src/activity-favorite.php b/src/activity-favorite.php index 1a2e828..734d941 100644 --- a/src/activity-favorite.php +++ b/src/activity-favorite.php @@ -72,8 +72,9 @@ public function create( $args ) { $activity = bp_activity_get_specific( [ - 'activity_ids' => $activity_id, - 'spam' => null, + 'activity_ids' => $activity_id, + 'spam' => null, + 'display_comments' => true, ] ); @@ -127,8 +128,9 @@ public function delete( $args, $assoc_args ) { $activity = bp_activity_get_specific( [ - 'activity_ids' => $activity_id, - 'spam' => null, + 'activity_ids' => $activity_id, + 'spam' => null, + 'display_comments' => true, ] ); @@ -159,6 +161,12 @@ public function delete( $args, $assoc_args ) { * [--=] * : One or more parameters to pass to \BP_Activity_Activity::get() * + * [--count=] + * : How many activity favorites to list. + * --- + * default: 50 + * --- + * * [--format=] * : Render output in a particular format. * --- @@ -172,23 +180,15 @@ public function delete( $args, $assoc_args ) { * - yaml * --- * - * [--count=] - * : How many activity favorites to list. - * --- - * default: 50 - * --- - * * ## EXAMPLE * * # Get a user's favorite activity items. * $ wp bp activity favorite list 315 * * @subcommand list - * @alias items - * @alias user_items * @alias user-items */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $user = $this->get_user_id_from_identifier( $args[0] ); $favorites = bp_activity_get_user_favorites( $user->ID ); @@ -208,6 +208,8 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho WP_CLI::error( 'No favorite found for this user.' ); } - $this->get_formatter( $assoc_args )->display_items( $activities['activities'] ); + $activities = $activities['activities']; + $formatter = $this->get_formatter( $assoc_args ); + $formatter->display_items( 'ids' === $formatter->format ? wp_list_pluck( $activities, 'id' ) : $activities ); } } diff --git a/src/activity.php b/src/activity.php index 466da10..ac64ddc 100644 --- a/src/activity.php +++ b/src/activity.php @@ -260,7 +260,7 @@ public function create( $args, $assoc_args ) { * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); $r = wp_parse_args( @@ -612,11 +612,11 @@ public function ham( $args ) { * ## EXAMPLES * * # Post an activity update. - * $ wp bp activity post_update --user-id=50 --content="Content to update" + * $ wp bp activity post-update --user-id=50 --content="Content to update" * Success: Successfully updated with a new activity item (ID #13165) * * # Post an activity update. - * $ wp bp activity post_update --user-id=140 + * $ wp bp activity post-update --user-id=140 * Success: Successfully updated with a new activity item (ID #4548) * * @alias post-update @@ -774,6 +774,8 @@ protected function get_random_type_from_component( $component ) { /** * Generate item details. * + * @global wpdb $wpdb WordPress database abstraction object. + * * @since 1.1 * * @param array $r Params. @@ -852,7 +854,7 @@ protected function generate_item_details( $r ) { } if ( is_multisite() ) { - $r['item-id'] = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} ORDER BY RAND() LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $r['item-id'] = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} ORDER BY RAND() LIMIT 1" ); } else { $r['item-id'] = 1; } @@ -864,7 +866,7 @@ protected function generate_item_details( $r ) { switch_to_blog( $r['item-id'] ); } - $comment_info = $wpdb->get_results( "SELECT comment_id, comment_post_id FROM {$wpdb->comments} ORDER BY RAND() LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $comment_info = $wpdb->get_results( "SELECT comment_id, comment_post_id FROM {$wpdb->comments} ORDER BY RAND() LIMIT 1" ); $comment_id = $comment_info[0]->comment_id; $comment = get_comment( $comment_id ); diff --git a/src/command.php b/src/command.php index 2ac0955..4a62385 100644 --- a/src/command.php +++ b/src/command.php @@ -38,13 +38,15 @@ protected function get_formatter( &$assoc_args ) { /** * Get a random user id. * + * @global wpdb $wpdb WordPress database abstraction object. + * * @since 1.1 * * @return int */ protected function get_random_user_id() { global $wpdb; - return $wpdb->get_var( "SELECT ID FROM $wpdb->users ORDER BY RAND() LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + return (int) $wpdb->get_var( "SELECT ID FROM $wpdb->users ORDER BY RAND() LIMIT 1" ); } /** diff --git a/src/components.php b/src/components.php index 17fa8a0..1755bf2 100644 --- a/src/components.php +++ b/src/components.php @@ -211,7 +211,7 @@ public function deactivate( $args ) { * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); // Get type. diff --git a/src/email.php b/src/email.php index 718d161..94075f4 100644 --- a/src/email.php +++ b/src/email.php @@ -91,7 +91,7 @@ public function create( $args, $assoc_args ) { if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'edit' ) ) { $input = \WP_CLI\Utils\get_flag_value( $assoc_args, 'content', '' ); - $output = $this->_edit( $input, 'WP-CLI: New BP Email Content' ); + $output = $this->edit_email( $input, 'WP-CLI: New BP Email Content' ); $assoc_args['content'] = ( $output ) ? $output : $input; } @@ -229,7 +229,7 @@ public function reinstall( $args, $assoc_args ) { * @param string $title Post title. * @return mixed */ - protected function _edit( $content, $title ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + protected function edit_email( $content, $title ) { $content = apply_filters( 'the_editor_content', $content ); $output = \WP_CLI\Utils\launch_editor_for_input( $content, $title ); diff --git a/src/friends.php b/src/friends.php index f84b88e..4585aba 100644 --- a/src/friends.php +++ b/src/friends.php @@ -247,6 +247,12 @@ public function check( $args ) { * [--fields=] * : Fields to display. * + * [--count=] + * : How many user's friends to list. + * --- + * default: 50 + * --- + * * [--format=] * : Render output in a particular format. * --- @@ -272,10 +278,16 @@ public function check( $args ) { * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); $user = $this->get_user_id_from_identifier( $args[0] ); - $friends = \BP_Friends_Friendship::get_friendships( $user->ID ); + $friends = \BP_Friends_Friendship::get_friendships( + $user->ID, + [ + 'page' => 1, + 'per_page' => $assoc_args['count'], + ] + ); if ( empty( $friends ) ) { WP_CLI::error( 'This member has no friends.' ); @@ -289,18 +301,18 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho * * ## OPTIONS * - * [--count=] - * : How many friendships to generate. - * --- - * default: 100 - * --- - * * [--initiator=] * : ID of the first user. Accepts either a user_login or a numeric ID. * * [--friend=] * : ID of the second user. Accepts either a user_login or a numeric ID. * + * [--count=] + * : How many friendships to generate. + * --- + * default: 100 + * --- + * * [--format=] * : Render output in a particular format. * --- diff --git a/src/group-invite.php b/src/group-invite.php index 5b8866b..8bd45fe 100644 --- a/src/group-invite.php +++ b/src/group-invite.php @@ -148,25 +148,33 @@ public function uninvite( $args, $assoc_args ) { * --user-id= * : Identifier for the user. Accepts either a user_login or a numeric ID. * + * [--count=] + * : How many invitations to list. + * --- + * default: 50 + * --- + * * [--format=] * : Render output in a particular format. * --- * default: table * options: * - table - * - ids * - csv + * - ids + * - json * - count * - yaml * --- * * ## EXAMPLE * - * $ wp bp group invite list --user-id=30 --group-id=56 + * # Get a list of invitations from a group. + * $ wp bp group invite list --group-id=56 --user-id=30 * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $group_id = $this->get_group_id_from_identifier( $assoc_args['group-id'] ); $user = $this->get_user_id_from_identifier( $assoc_args['user-id'] ); $user_id = $user->ID; @@ -175,6 +183,7 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho $invite_query = new \BP_Group_Member_Query( [ 'is_confirmed' => false, 'group_id' => $group_id, + 'per_page' => $assoc_args['count'], ] ); $invites = $invite_query->results; @@ -209,26 +218,17 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho $assoc_args['fields'] = $fields; } - - $formatter = $this->get_formatter( $assoc_args ); - $formatter->display_items( $invites ); } else { - $invite_query = groups_get_invites_for_user( $user_id ); + $invite_query = groups_get_invites_for_user( $user_id, $assoc_args['count'], 1 ); $invites = $invite_query['groups']; if ( empty( $assoc_args['fields'] ) ) { - $fields = [ - 'id', - 'name', - 'slug', - ]; - - $assoc_args['fields'] = $fields; + $assoc_args['fields'] = [ 'id', 'name', 'slug' ]; } - - $formatter = $this->get_formatter( $assoc_args ); - $formatter->display_items( $invites ); } + + $formatter = $this->get_formatter( $assoc_args ); + $formatter->display_items( 'ids' === $formatter->format ? wp_list_pluck( $invites, 'id' ) : $invites ); } /** diff --git a/src/group-member.php b/src/group-member.php index 99bae48..e9b427b 100644 --- a/src/group-member.php +++ b/src/group-member.php @@ -143,6 +143,26 @@ public function delete( $args, $assoc_args ) { * [--fields=] * : Limit the output to specific signup fields. * + * [--=] + * : One or more parameters to pass. See groups_get_group_members() + * + * [--role=] + * : Limit the output to members with a specific role. + * --- + * default: members + * options: + * - members + * - mod + * - admin + * - banned + * --- + * + * [--count=] + * : How many members to list. + * --- + * default: 50 + * --- + * * [--format=] * : Render output in a particular format. * --- @@ -156,34 +176,42 @@ public function delete( $args, $assoc_args ) { * - yaml * --- * - * [--=] - * : One or more parameters to pass. See groups_get_group_members() + * ## AVAILABLE FIELDS * - * ## EXAMPLES + * These fields will be displayed by default for each group member: + * + * * id + * * user_login + * * fullname + * * date_modified + * * role * + * ## EXAMPLE + * + * # Get a list of group members. * $ wp bp group member list 3 - * $ wp bp group member list my-group + * +---------+------------+----------+---------------------+-------+ + * | id | user_login | fullname | date_modified | role | + * +---------+------------+----------+---------------------+-------+ + * | 1 | user | User | 2022-07-04 02:12:02 | admin | + * +---------+------------+----------+---------------------+-------+ + * + * # Get a list of group members and get the count. + * $ wp bp group member list 65465 --format=count + * 100 * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $group_id = $this->get_group_id_from_identifier( $args[0] ); - $roles = [ 'members' ]; - if ( isset( $assoc_args['role'] ) ) { - if ( is_string( $assoc_args['role'] ) ) { - $roles = explode( ',', $assoc_args['role'] ); - } else { - $roles = $assoc_args['role']; - } - } - // Get our members. $members_query = groups_get_group_members( [ + 'per_page' => $assoc_args['count'], 'group_id' => $group_id, 'exclude_admins_mods' => false, - 'group_role' => $roles, + 'group_role' => [ $assoc_args['role'] ], ] ); @@ -207,7 +235,7 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho if ( empty( $assoc_args['fields'] ) ) { $assoc_args['fields'] = [ - 'user_id', + 'id', 'user_login', 'fullname', 'date_modified', @@ -215,7 +243,8 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho ]; } - $this->get_formatter( $assoc_args )->display_items( $members ); + $formatter = $this->get_formatter( $assoc_args ); + $formatter->display_items( 'ids' === $formatter->format ? wp_list_pluck( $members, 'user_id' ) : $members ); } /** diff --git a/src/group.php b/src/group.php index e52681c..4bdd5c7 100644 --- a/src/group.php +++ b/src/group.php @@ -406,13 +406,11 @@ function ( $group_id, $fields = [] ) { * - last_activity * - total_member_count * - * [--order=] - * : Whether to sort results ascending or descending. + * [--count=] + * : Number of group to list. + * --- + * default: 50 * --- - * default: ASC - * options: - * - ASC - * - DESC * * [--format=] * : Render output in a particular format. @@ -427,12 +425,16 @@ function ( $group_id, $fields = [] ) { * - yaml * --- * - * [--count=] - * : Number of group items to list. - * --- - * default: 50 - * --- - + * ## AVAILABLE FIELDS + * + * These fields will be displayed by default for each group: + * + * * id + * * name + * * slug + * * status + * * date_created + * * ## EXAMPLES * * # List groups and get the count. @@ -443,20 +445,27 @@ function ( $group_id, $fields = [] ) { * $ wp bp group list --format=ids * 70 71 72 73 74 * + * # List groups. + * $ wp bp group list + * +----+------------+---------+---------+---------------------+ + * | id | name | slug | status | date_created | + * +----+------------+---------+---------+---------------------+ + * | 1 | Group - #0 | group-0 | hidden | 2022-07-04 02:12:02 | + * | 2 | Group - #1 | group-1 | hidden | 2022-07-04 02:12:02 | + * | 4 | Group - #3 | group-3 | private | 2022-07-04 02:12:02 | + * | 5 | Group - #4 | group-4 | private | 2022-07-04 02:12:02 | + * | 3 | Group – #2 | group-2 | public | 2022-07-04 02:12:02 | + * +----+------------+---------+---------+---------------------+ + * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); - $query_args = wp_parse_args( - $assoc_args, - [ - 'count' => 50, - 'show_hidden' => true, - 'orderby' => $assoc_args['orderby'], - 'order' => $assoc_args['order'], - 'per_page' => $assoc_args['count'], - ] - ); + $query_args = [ + 'show_hidden' => true, + 'orderby' => $assoc_args['orderby'], + 'per_page' => $assoc_args['count'], + ]; if ( isset( $assoc_args['user-id'] ) ) { $user = $this->get_user_id_from_identifier( $assoc_args['user-id'] ); diff --git a/src/messages.php b/src/messages.php index 534b5d5..56f98aa 100644 --- a/src/messages.php +++ b/src/messages.php @@ -247,12 +247,6 @@ public function get( $args, $assoc_args ) { * [--fields=] * : Fields to display. * - * [--count=] - * : How many messages to list. - * --- - * default: 10 - * --- - * * [--box=] * : Box of the message. * --- @@ -273,6 +267,12 @@ public function get( $args, $assoc_args ) { * - all * --- * + * [--count=] + * : How many messages to list. + * --- + * default: 50 + * --- + * * [--format=] * : Render output in a particular format. * --- @@ -286,6 +286,17 @@ public function get( $args, $assoc_args ) { * - yaml * --- * + * ## AVAILABLE FIELDS + * + * These fields will be displayed by default for each message: + * + * * id + * * subject + * * message + * * thread_id + * * sender_id + * * date_sent + * * ## EXAMPLES * * # Get a list of messages for a specific user. @@ -296,25 +307,27 @@ public function get( $args, $assoc_args ) { * $ wp bp message list --user-id=user_login --count=3 --format=ids * 5454 45454 4545 465465 * + * # Get a list of messages. + * # wp bp message list --user-id=1 --count=2 + * +----+----------------------+--------------------------+-----------+-----------+---------------------+ + * | id | subject | message | thread_id | sender_id | date_sent | + * +----+----------------------+--------------------------+-----------+-----------+---------------------+ + * | 35 | Another Thread |

Another thread

| 2 | 1 | 2022-10-27 16:29:29 | + * | 37 | Message Subject - #0 | Here is some random text | 2 | 7 | 2022-10-27 19:06:54 | + * +----+----------------------+--------------------------+-----------+-----------+---------------------+ + * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); - - $r = wp_parse_args( - $assoc_args, - [ 'search' => '' ] - ); - - $user = $this->get_user_id_from_identifier( $assoc_args['user-id'] ); - - $inbox = new \BP_Messages_Box_Template( + $user = $this->get_user_id_from_identifier( $assoc_args['user-id'] ); + $inbox = new \BP_Messages_Box_Template( [ - 'user_id' => $user->ID, - 'box' => $r['box'], - 'type' => $r['type'], - 'max' => $r['count'], - 'search_terms' => $r['search'], + 'user_id' => $user->ID, + 'box' => $assoc_args['box'], + 'type' => $assoc_args['type'], + 'messages_page' => 1, + 'messages_per_page' => $assoc_args['count'], ] ); diff --git a/src/notification.php b/src/notification.php index 886a872..31e3eec 100644 --- a/src/notification.php +++ b/src/notification.php @@ -374,7 +374,7 @@ function ( $assoc_args, $format ) use ( $user_id ) { * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); $query_args = [ 'update_meta_cache' => false, diff --git a/src/signup.php b/src/signup.php index 96bb81d..2358c95 100644 --- a/src/signup.php +++ b/src/signup.php @@ -329,10 +329,10 @@ public function resend( $args, $assoc_args ) { * [--fields=] * : One or more parameters to pass. See \BP_Signup::get() * - * [--number=] + * [--count=] * : How many signups to list. * --- - * default: 20 + * default: 50 * --- * * [--format=] @@ -341,28 +341,27 @@ public function resend( $args, $assoc_args ) { * default: table * options: * - table + * - csv * - ids + * - json * - count - * - csv + * - yaml * --- * * ## EXAMPLES * + * # List signups and get the IDs. * $ wp bp signup list --format=ids + * 70 71 72 73 74 + * + * # List 100 signups and return the count. * $ wp bp signup list --number=100 --format=count - * $ wp bp signup list --number=5 --activation_key=ee48ec319fef3nn4 + * 100 * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore - $formatter = $this->get_formatter( $assoc_args ); - $assoc_args = wp_parse_args( - $assoc_args, - [ - 'number' => 20, - 'fields' => 'all', - ] - ); + public function list_( $args, $assoc_args ) { + $formatter = $this->get_formatter( $assoc_args ); if ( in_array( $formatter->format, [ 'ids', 'count' ], true ) ) { $assoc_args['fields'] = 'ids'; diff --git a/src/sitewide-notice.php b/src/sitewide-notice.php index 341f04e..00a284f 100644 --- a/src/sitewide-notice.php +++ b/src/sitewide-notice.php @@ -328,7 +328,7 @@ public function deactivate( $args ) { * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); $query_args = [ 'pag_num' => (int) $assoc_args['count'] ]; diff --git a/src/tool.php b/src/tool.php index 8cb24f2..94d93cc 100644 --- a/src/tool.php +++ b/src/tool.php @@ -122,23 +122,4 @@ public function signup( $args ) { WP_CLI::success( 'Signup tool updated.' ); } - - /** - * Reinstall BuddyPress default emails. - * - * ## OPTIONS - * - * [--yes] - * : Answer yes to the confirmation message. - * - * ## EXAMPLE - * - * # Reinstall BuddyPress default emails. - * $ wp bp tool reinstall --yes - * Success: Emails have been successfully reinstalled. - */ - public function reinstall( $args, $assoc_args ) { - $command_class = new Email(); - $command_class->reinstall( $args, $assoc_args ); - } } diff --git a/src/xprofile-field.php b/src/xprofile-field.php index 1f4c6a6..596b910 100644 --- a/src/xprofile-field.php +++ b/src/xprofile-field.php @@ -33,13 +33,43 @@ class XProfile_Field extends BuddyPressCommand { * [--=] * : One or more parameters to pass. See bp_xprofile_get_groups() * + * [--format=] + * : Render output in a particular format. + * --- + * default: table + * options: + * - table + * - csv + * - ids + * - json + * - count + * - yaml + * --- + * + * * ## AVAILABLE FIELDS + * + * These fields will be displayed by default for each field: + * + * * id + * * name + * * description + * * type + * * group_id + * * is_required + * * ## EXAMPLE * + * # List XProfile fields. * $ wp bp xprofile field list + * +----+------+-------------+---------+----------+-------------+ + * | id | name | description | type | group_id | is_required | + * +----+------+-------------+---------+----------+-------------+ + * | 1 | Name | | textbox | 1 | 1 | + * +----+------+-------------+---------+----------+-------------+ * * @subcommand list */ - public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + public function list_( $args, $assoc_args ) { $args = array_merge( $assoc_args, [ @@ -58,9 +88,8 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho } } - ksort( $fields ); - - $this->get_formatter( $assoc_args )->display_items( $fields ); + $formatter = $this->get_formatter( $assoc_args ); + $formatter->display_items( 'ids' === $formatter->format ? wp_list_pluck( $fields, 'id' ) : $fields ); } /**