Skip to content

Abilities API: Accept PUT for destructive and idempotent abilities in the run endpoint - #16257

Open
sajid-ansari-65 wants to merge 3 commits into
WordPress:trunkfrom
sajid-ansari-65:fix/66801-abilities-run-put-method
Open

sajid-ansari-65 wants to merge 3 commits into
WordPress:trunkfrom
sajid-ansari-65:fix/66801-abilities-run-put-method

Conversation

@sajid-ansari-65

@sajid-ansari-65 sajid-ansari-65 commented Nov 26, 2026 •

Copy link
Copy Markdown

Destructive and idempotent abilities now expect PUT, which carries the input in a JSON body. PATCH is also accepted, and DELETE stays accepted with the input in the query string for backward compatibility.

See #66801

Trac ticket: https://core.trac.wordpress.org/ticket/66801

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Claude Code wrote the implementation and tests, following the approach discussed in the ticket. I reviewed the diff, ran PHPUnit and PHPCS locally, and tested the endpoint with curl on a local install.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

… the run endpoint.

Destructive and idempotent abilities now expect PUT, which carries the
input in a JSON body. PATCH is also accepted, and DELETE stays accepted
with the input in the query string for backward compatibility.

See #66801.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sajidansari65, gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@gziolo
gziolo requested review from jorgefilipecosta and a balanced review from Copilot December 1, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the endpoint’s updated HTTP-method and input-handling behavior.

No open issues 🎉

What changed in this PR

This PR updates the Abilities API run endpoint to prefer PUT for destructive, idempotent abilities, while also accepting PATCH and preserving DELETE compatibility.

Changes:

  • Accept PUT and PATCH with JSON-body input; retain query-string input for DELETE.
  • Update method-validation messages and documentation, and expand tests for accepted methods and input handling.
File Description
tests/​phpunit/​tests/​rest-api/​wpRestAbilitiesV1RunController.php Adds method-validation cases, PUT query-input rejection coverage, and PUT/PATCH coercion coverage.
src/​wp-includes/​rest-api/​endpoints/​class-wp-rest-abilities-v1-run-controller.php Accepts PUT and PATCH for destructive, idempotent abilities and updates related messages and documentation.

Review effort: Balanced

@gziolo

gziolo commented Dec 1, 2026

Copy link
Copy Markdown
Member

@jorgefilipecosta, I'm just letting you know that this change is fully backward compatible. It will still require changes in the JavaScript package that handles abilities execution to account to the revised recommended way to call these abilities.

@sajid-ansari-65

Copy link
Copy Markdown
Author

Thanks for the review. For the Gutenberg follow-up, createServerCallback() in packages/core-abilities needs two changes: send PUT instead of DELETE, and send the JSON body for PUT (today it only sets data for POST). Since the plugin also runs on WordPress versions where the server still expects DELETE, it would need either a compat backport of this change or a fallback to DELETE on older versions. Happy to open that PR if it helps, @jorgefilipecosta.

@gziolo gziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! This is a complicated problem, because the same two annotations describe both updates and deletes. I really appreciate your work on it.

I spent more time trying to understand the MCP spec for these annotations and what it means for the REST methods. My current thinking is moving toward this mapping:

  • GET for read-only abilities. The input is in the query string.
  • PUT for idempotent updates, which are abilities marked destructive and idempotent. The input is in a JSON body.
  • DELETE for deletes, which have the same two annotations. The input is in the query string.
  • POST for everything else, such as creates and writes that are not idempotent. The input is in a JSON body.

The PR is already close to this. What do you think?

I left three inline comments with the changes this mapping would need. The tests pass for me locally.

…point.

Destructive and idempotent abilities now accept PUT for updates and DELETE for deletes. PATCH is rejected because it is not idempotent per RFC 9110.

The 405 error message now names both PUT and DELETE. A PUT request that sends the input in the query string returns a 400 error, so a destructive ability does not silently run with its default input.

See #66801.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sajid-ansari-65

Copy link
Copy Markdown
Author

Thanks for the review! I agree with the mapping, and I've updated the PR to follow it:

  • Read-only → GET (input in query string)
  • Destructive + idempotent → PUT for updates (JSON body) or DELETE for deletes (query string)
  • Everything else → POST (JSON body)

Changes in the latest commit:

  1. PATCH is no longer accepted for destructive + idempotent abilities, since it isn't idempotent per RFC 9110.
  2. The 405 message now reads "Idempotent destructive abilities require PUT method for updates or DELETE method for deletes."
  3. A PUT request that sends input in the query string now returns 400 rest_ability_invalid_input_location instead of running the ability with its default input.

One related question: a DELETE request that sends input in a JSON body is still silently ignored, which carries the same risk the PUT check now guards against. Should DELETE reject body input in the same way, either here or in a follow-up?

@gziolo

gziolo commented Dec 3, 2026

Copy link
Copy Markdown
Member

Thanks for the update, and for the good question!

I'm open to a stricter check for DELETE in this PR. It should target input directly, so the request fails only when input is sent in the body. Please also add tests for it.

We will need a dev note for WordPress 7.3 that explains these changes.

DELETE reads the input only from the query string. A DELETE request that sends `input` in a JSON or form body now returns a 400 error with the `rest_ability_invalid_input_location` code, so a destructive ability does not silently run with its default input. Body data without an `input` key is still accepted.

See #66801.
@sajid-ansari-65

Copy link
Copy Markdown
Author

Thanks! @gziolo.
Added in the latest commit:

  • A DELETE request that sends input in the body now returns 400 rest_ability_invalid_input_location ("DELETE requests must send the input in the query string."). The check targets the input key directly, in both JSON and form-encoded bodies, so body data without input is still accepted.
  • Tests cover a JSON body, a form body, and a body without input (which runs and reads the input from the query string).

Happy to draft the 7.3 dev note as well. I can share a draft on the ticket once the approach is settled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants