File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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( $input = null ) {
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 """
Original file line number Diff line number Diff line change @@ -369,6 +369,9 @@ public function run( $args, $assoc_args ): void {
369369
370370 // Build input data (with stdin support).
371371 $ input = $ this ->build_input_with_stdin ( $ assoc_args );
372+ if ( null === $ input && [] !== $ ability ->get_input_schema () ) {
373+ $ input = [];
374+ }
372375
373376 // Execute the ability.
374377 $ result = $ ability ->execute ( $ input );
@@ -593,7 +596,7 @@ private function build_input( $assoc_args ) {
593596 * Builds input data from associative arguments with stdin support.
594597 *
595598 * @param array $assoc_args Associative arguments.
596- * @return array<string,mixed> The input data.
599+ * @return array<string,mixed>|null The input data, or null if none provided .
597600 */
598601 private function build_input_with_stdin ( $ assoc_args ) {
599602 $ input = [];
@@ -626,7 +629,8 @@ private function build_input_with_stdin( $assoc_args ) {
626629 $ input [ $ key ] = $ value ;
627630 }
628631
629- return $ input ;
632+ // Return null only when no input was provided (no --input flag and no field args).
633+ return ( empty ( $ input ) && null === $ json_input ) ? null : $ input ;
630634 }
631635
632636 /**
You can’t perform that action at this time.
0 commit comments