Skip to content

Commit 87e8e59

Browse files
authored
Fix wp ability list --format=ids output (#16)
The `ids` format of the formatter expects plain values, but the ability rows were passed as arrays, which printed "Array" once per ability and an "Array to string conversion" warning each. Pass the ability names instead, the same way `wp cron event list` passes the hook names.
1 parent 80f10dc commit 87e8e59

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎features/ability.feature‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ Feature: Manage abilities registered via the WordPress Abilities API.
9595
"name":"test-plugin\/get-site-title"
9696
"""
9797

98+
When I run `wp ability list --category=test-category --format=ids`
99+
Then STDOUT should be:
100+
"""
101+
test-plugin/get-site-title test-plugin/echo-input
102+
"""
103+
And STDERR should be empty
104+
98105
@require-wp-6.9
99106
Scenario: Get ability details.
100107
Given a wp-content/mu-plugins/test-ability.php file:

‎src/Ability_Command.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ public function list_( $args, $assoc_args ): void {
242242
}
243243

244244
$formatter = $this->get_formatter( $assoc_args, $this->default_fields );
245+
246+
// The ids format expects plain values, so pass the ability names.
247+
if ( 'ids' === $formatter->format ) {
248+
$items = wp_list_pluck( $items, 'name' );
249+
}
250+
245251
$formatter->display_items( $items );
246252
}
247253

0 commit comments

Comments
 (0)