Opened 23 hours ago
Last modified 23 hours ago
#66865 new enhancement
REST API: Add a route to restore a revision
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | REST API | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The REST API can list, read and delete revisions, but it can not restore one. Gutenberg adds a restore route in https://github.com/WordPress/gutenberg/pull/82158 and that route needs to come to core.
Background and proposal, put together by Claude (Fable 5.2):
The in-editor revisions screen of the block editor restores a revision by copying its fields into an ordinary post update.
wp_restore_post_revision()never runs, so thewp_restore_post_revisionaction does not fire and revisioned meta that is not shown in REST is not restored. See https://github.com/WordPress/gutenberg/issues/85549.
Proposal
Add
POST /wp/v2/<base>/<parent>/revisions/<id>/restorefor every post type with revisions, templates and template parts included. The route:
- requires the
edit_postcapability on the parent,- returns a 404 when the revision does not exist or does not belong to the parent,
- only restores autosaves while revisions are disabled for the post, as
wp-admin/revision.phpdoes,- calls
wp_restore_post_revision(), so the restore is the same one the classic revisions screen and XML-RPC run,- returns the restored parent as its own endpoint returns it in the
editcontext, so the editor can show it without another request.Global styles revisions are not included, they are not restored through
wp_restore_post_revision().
Related: #66859, where the revision stored by a restore holds the meta from before the restore. The Gutenberg route works around that. The core route does not need to once that ticket is fixed.
A PR is on the way.
AI Use
Claude (Fable 5.2) wrote the Gutenberg route and this ticket. (Ticket only, the core PR follows.)
Generated with Claude Code
Change History (1)
This ticket was mentioned in PR #16315 on WordPress/wordpress-develop by @adamsilverstein.
23 hours ago
#1
- Keywords has-patch has-unit-tests added
Core side of https://github.com/WordPress/gutenberg/pull/82158.
_Claude Code (Fable 5.2) ported the route from the Gutenberg PR and wrote this description:_
AI Use
Claude Code (Fable 5.2) wrote the route, the tests and this description. I will review and test.
🤖 Generated with Claude Code