Skip to content

Commit 1f2a6dc

Browse files
Copilotswissspidy
andcommitted
Improve robustness and fix test scenarios
Co-authored-by: swissspidy <[email protected]>
1 parent 783e899 commit 1f2a6dc

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

features/ability-category.feature

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ Feature: Manage WordPress ability categories
33
Background:
44
Given a WP install
55

6-
@require-wp-6.9
6+
@less-than-wp-6.9
77
Scenario: Ability category commands require WordPress 6.9+
8-
When I try `wp core download --version=6.8 --force`
9-
And I run `wp core version`
10-
Then STDOUT should contain:
11-
"""
12-
6.8
13-
"""
14-
158
When I try `wp ability category list`
169
Then STDERR should contain:
1710
"""

features/ability.feature

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ Feature: Manage WordPress abilities
33
Background:
44
Given a WP install
55

6-
@require-wp-6.9
6+
@less-than-wp-6.9
77
Scenario: Ability commands require WordPress 6.9+
8-
When I try `wp core download --version=6.8 --force`
9-
And I run `wp core version`
10-
Then STDOUT should contain:
11-
"""
12-
6.8
13-
"""
14-
158
When I try `wp ability list`
169
Then STDERR should contain:
1710
"""

src/Ability_Category_Command.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ class Ability_Category_Command extends WP_CLI_Command {
8181
public function list_( $args, $assoc_args ) {
8282
$formatter = $this->get_formatter( $assoc_args );
8383

84-
$categories = wp_get_ability_categories();
84+
// Get all registered ability categories
85+
if ( function_exists( 'wp_get_ability_categories' ) ) {
86+
$categories = wp_get_ability_categories();
87+
} elseif ( function_exists( 'wp_ability_categories' ) ) {
88+
$registry = wp_ability_categories();
89+
$categories = $registry->get_all();
90+
} else {
91+
$categories = array();
92+
}
8593

8694
if ( empty( $categories ) ) {
8795
$categories = array();

src/Ability_Command.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@ class Ability_Command extends WP_CLI_Command {
101101
public function list_( $args, $assoc_args ) {
102102
$formatter = $this->get_formatter( $assoc_args );
103103

104-
$abilities = wp_get_abilities();
104+
// Get all registered abilities
105+
if ( function_exists( 'wp_get_abilities' ) ) {
106+
$abilities = wp_get_abilities();
107+
} elseif ( function_exists( 'wp_abilities' ) ) {
108+
$registry = wp_abilities();
109+
$abilities = $registry->get_all();
110+
} else {
111+
$abilities = array();
112+
}
105113

106114
if ( empty( $abilities ) ) {
107115
$abilities = array();
@@ -291,7 +299,16 @@ public function execute( $args, $assoc_args ) {
291299
}
292300

293301
// Execute the ability
294-
$result = wp_execute_ability( $ability_name, $input );
302+
// First try wp_execute_ability if it exists, otherwise call the callback directly
303+
if ( function_exists( 'wp_execute_ability' ) ) {
304+
$result = wp_execute_ability( $ability_name, $input );
305+
} else {
306+
$ability = wp_get_ability( $ability_name );
307+
if ( ! $ability || ! is_callable( $ability->callback ) ) {
308+
WP_CLI::error( "Cannot execute ability {$ability_name}." );
309+
}
310+
$result = call_user_func( $ability->callback, $input );
311+
}
295312

296313
if ( is_wp_error( $result ) ) {
297314
WP_CLI::error( $result->get_error_message() );

0 commit comments

Comments
 (0)