Title: Abilities without `input_schema` return an error when run via the CLI · Issue #6 · wp-cli/ability-command · GitHub
Open Graph Title: Abilities without `input_schema` return an error when run via the CLI · Issue #6 · wp-cli/ability-command
X Title: Abilities without `input_schema` return an error when run via the CLI · Issue #6 · wp-cli/ability-command
Description: Bug Report Yes, I reviewed the contribution guidelines. Yes, more specifically, I reviewed the guidelines on how to write clear bug reports. Describe the current, buggy behavior The input_schema is optional, and I think for "simple" abil...
Open Graph Description: Bug Report Yes, I reviewed the contribution guidelines. Yes, more specifically, I reviewed the guidelines on how to write clear bug reports. Describe the current, buggy behavior The input_schema is...
X Description: Bug Report Yes, I reviewed the contribution guidelines. Yes, more specifically, I reviewed the guidelines on how to write clear bug reports. Describe the current, buggy behavior The input_schema is...
Opengraph URL: https://github.com/wp-cli/ability-command/issues/6
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Abilities without `input_schema` return an error when run via the CLI","articleBody":"## Bug Report\n\n- [x] Yes, I reviewed the [contribution guidelines](https://make.wordpress.org/cli/handbook/contributing/).\n- [x] Yes, more specifically, I reviewed the guidelines on [how to write clear bug reports](https://make.wordpress.org/cli/handbook/bug-reports/).\n\n**Describe the current, buggy behavior**\n\nThe `input_schema` is optional, and I think for \"simple\" abilities, it's fairly common to skip it, especially for those that are \"just\" returning data.\n\nhttps://github.com/WordPress/WordPress/blob/24dac1cd906af3e6c06a5c52b5ca8629b4c91080/wp-includes/abilities-api/class-wp-ability.php#L148\n\nHowever, when I run the ability for an ability that doesn't have an input schema defined, e.g. `wp ability run foo/simple-no-input`, I get the following error:\n\n```\nError: Ability \"foo/simple-no-input\" does not define an input schema required to validate the provided input.\n```\n\n**Describe how other contributors can replicate this bug**\n\nRegister an ability as follows:\n\n```php\nadd_action(\n 'wp_abilities_api_categories_init',\n function () {\n wp_register_ability_category(\n 'foo',\n [\n 'label' => 'Foo',\n 'description' => 'Foo...',\n ],\n );\n },\n);\n\nadd_action(\n 'wp_abilities_api_init',\n function () {\n wp_register_ability(\n 'foo/simple-no-input',\n [\n 'label' => 'Simple No Input',\n 'description' => 'Simple No Input...',\n 'category' => 'foo',\n 'output_schema' => [\n 'type' => 'array',\n ],\n 'execute_callback' => function () {\n return [];\n },\n 'permission_callback' => '__return_true',\n ],\n );\n },\n);\n```\n\nThen run the `wp ability run foo/simple-no-input` via the CLI.\n\n**Describe what you would expect as the correct outcome**\n\nI would expect that if I register an ability without an input schema and call it with the CLI, I would receive an output, in this case `[]`.\n\n`wp_get_ability('foo/simple-no-input')->execute()` works perfectly.\n\n**Let us know what environment you are running this on**\n\n```\nPHP version: 8.4.22\nWP-CLI version: 2.13.0-alpha-c807ba0\nWP version: 7.0\n```\n\n**Provide a possible solution**\n\n...\n\n**Provide additional context/Screenshots**\n\nAfter a quick look, the problem seems to be that an empty array is passed to execute rather than `null` which is the default of the `execute` method:\n\nhttps://github.com/wp-cli/ability-command/blob/9e2b34eca6a37ec5d4aed9b73cbd14873a997c66/src/Ability_Command.php#L370-L374\n\nhttps://github.com/WordPress/WordPress/blob/24dac1cd906af3e6c06a5c52b5ca8629b4c91080/wp-includes/abilities-api/class-wp-ability.php#L734\n\nTo make a \"simple\" ability work with the CLI the following `input_schema` can be added:\n\n```php\n[\n 'input_schema' => [\n 'type' => 'object',\n ],\n \n],\n```\n\nHowever, the consequence of this is that when `wp_get_ability` is used, it has to be executed with an input:\n\n```php\nwp_get_ability('foo/simple-no-input')->execute([]);\n```\n\nThe following would result in an error, even though for a \"simple\" ability this would be the ideal situation:\n\n```php\nwp_get_ability('foo/simple-no-input')->execute();\n```\n\n```\nobject(WP_Error)#1124 (3) {\n [\"errors\"]=>\n array(1) {\n [\"ability_invalid_input\"]=>\n array(1) {\n [0]=>\n string(85) \"Ability \"foo/simple-no-input\" has invalid input. Reason: input is not of type object.\"\n }\n }\n [\"error_data\"]=>\n array(0) {\n }\n [\"additional_data\":protected]=>\n array(0) {\n }\n}\n```\n\nFrom what I see in the tests, there's no case where the `input_schema` is not defined:\n\nhttps://github.com/wp-cli/ability-command/blob/9e2b34eca6a37ec5d4aed9b73cbd14873a997c66/features/ability.feature#L152-L155","author":{"url":"https://github.com/meszarosrob","@type":"Person","name":"meszarosrob"},"datePublished":"2026-06-11T14:37:28Z","url":"https://github.com/wp-cli/ability-command/issues/6"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:58e91304-3500-f456-1ed4-8a5b3db57d95 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC38:2F2AB3:11777D7:17F8BED:6AFB6A3C |
| html-safe-nonce | dc43ddfc0241aa38baf6929e5b4c1d761c0111cbf39697c70eafbecbeb8cce3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzM4OjJGMkFCMzoxMTc3N0Q3OjE3RjhCRUQ6NkFGQjZBM0MiLCJ2aXNpdG9yX2lkIjoiNjQ3NzQwMTQxOTg1NzM2MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5b5583fce26e75d9928718216df451893534d958a6bb17196499bac8cb6f6965 |
| hovercard-subject-tag | issue:4641489917 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/wp-cli/ability-command/6/issue_layout |
| twitter:image | https://opengraph.githubassets.com/179573d9a3248ea6ef6fac1e254f23096c2fdc9e1ef31e66054c6898bb23999b/wp-cli/ability-command/issues/6 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/179573d9a3248ea6ef6fac1e254f23096c2fdc9e1ef31e66054c6898bb23999b/wp-cli/ability-command/issues/6 |
| og:image:alt | Bug Report Yes, I reviewed the contribution guidelines. Yes, more specifically, I reviewed the guidelines on how to write clear bug reports. Describe the current, buggy behavior The input_schema is... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | meszarosrob |
| hostname | github.com |
| expected-hostname | github.com |
| None | ea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94 |
| turbo-cache-control | no-preview |
| go-import | github.com/wp-cli/ability-command git https://github.com/wp-cli/ability-command.git |
| octolytics-dimension-user_id | 1570774 |
| octolytics-dimension-user_login | wp-cli |
| octolytics-dimension-repository_id | 1113185972 |
| octolytics-dimension-repository_nwo | wp-cli/ability-command |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1113185972 |
| octolytics-dimension-repository_network_root_nwo | wp-cli/ability-command |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 59ef97164c52cf59bd10558ddec9c4f482763988 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width