Skip to content

Commit 1ad2a97

Browse files
Copilotswissspidy
andauthored
Fix ability run input handling without schema
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 99c8084 commit 1ad2a97

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

features/ability.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ Feature: Manage abilities registered via the WordPress Abilities API.
191191
},
192192
'permission_callback' => '__return_true',
193193
) );
194+
195+
wp_register_ability( 'test-plugin/simple-no-input', array(
196+
'label' => 'Simple No Input',
197+
'description' => 'Returns an empty array.',
198+
'category' => 'test-category',
199+
'output_schema' => array(
200+
'type' => 'array',
201+
),
202+
'execute_callback' => function() {
203+
return array();
204+
},
205+
'permission_callback' => '__return_true',
206+
) );
194207
} );
195208
"""
196209

@@ -224,6 +237,12 @@ Feature: Manage abilities registered via the WordPress Abilities API.
224237
{"sum":30}
225238
"""
226239

240+
When I run `wp ability run test-plugin/simple-no-input`
241+
Then STDOUT should be:
242+
"""
243+
[]
244+
"""
245+
227246
When I run `wp ability run test-plugin/get-site-title --format=yaml`
228247
Then STDOUT should contain:
229248
"""

src/Ability_Command.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ private function build_input( $assoc_args ) {
593593
* Builds input data from associative arguments with stdin support.
594594
*
595595
* @param array $assoc_args Associative arguments.
596-
* @return array<string,mixed> The input data.
596+
* @return array<string,mixed>|null The input data, or null if none provided.
597597
*/
598598
private function build_input_with_stdin( $assoc_args ) {
599599
$input = [];
@@ -626,7 +626,8 @@ private function build_input_with_stdin( $assoc_args ) {
626626
$input[ $key ] = $value;
627627
}
628628

629-
return $input;
629+
// Return null if no input provided (for abilities without input schema).
630+
return empty( $input ) ? null : $input;
630631
}
631632

632633
/**

0 commit comments

Comments
 (0)