Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions features/ability.feature
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ Feature: Manage abilities registered via the WordPress Abilities API.
},
'permission_callback' => '__return_true',
) );

wp_register_ability( 'test-plugin/simple-no-input', array(
'label' => 'Simple No Input',
'description' => 'Returns an empty array.',
'category' => 'test-category',
'output_schema' => array(
'type' => 'array',
),
'execute_callback' => function() {
return array();
},
Comment thread
Copilot marked this conversation as resolved.
Outdated
'permission_callback' => '__return_true',
) );
} );
"""

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

When I run `wp ability run test-plugin/simple-no-input`
Then STDOUT should be:
"""
[]
"""

When I run `wp ability run test-plugin/get-site-title --format=yaml`
Then STDOUT should contain:
"""
Expand Down
5 changes: 3 additions & 2 deletions src/Ability_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ private function build_input( $assoc_args ) {
* Builds input data from associative arguments with stdin support.
*
* @param array $assoc_args Associative arguments.
* @return array<string,mixed> The input data.
* @return array<string,mixed>|null The input data, or null if none provided.
*/
private function build_input_with_stdin( $assoc_args ) {
$input = [];
Expand Down Expand Up @@ -626,7 +626,8 @@ private function build_input_with_stdin( $assoc_args ) {
$input[ $key ] = $value;
}

return $input;
// Return null if no input provided (for abilities without input schema).
return empty( $input ) ? null : $input;
Comment thread
Copilot marked this conversation as resolved.
Outdated
}

/**
Expand Down
Loading