Guidelines: Split singleton REST API into dedicated /content-guidelines route#77734
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 7.82 MB ℹ️ View Unchanged
|
a0b1b99 to
e503687
Compare
|
Flaky tests detected in 511efda. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25094020782
|
e503687 to
d2235b6
Compare
…es route Move the content guidelines singleton logic to a new Gutenberg_Content_Guidelines_REST_Controller mounted at /wp/v2/content-guidelines so the existing /wp/v2/guidelines collection can behave like a standard post-type endpoint and serve other guideline posts (artifacts) with full title/content/excerpt/author CRUD. The revisions controller now accepts an overrideable parent base and parent controller so it can be mounted under /content-guidelines while keeping the singleton response shape on restore. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Override get_post() and get_parent() so /wp/v2/content-guidelines/{id} and its
revisions sub-routes return 404 for guideline posts that aren't tagged with
the `content` term — those belong on the standard /wp/v2/guidelines collection.
Rename Gutenberg_Guidelines_Revisions_Controller (and its file) to
Gutenberg_Content_Guidelines_Revisions_Controller for symmetry with the REST
controller now that it's mounted exclusively under /content-guidelines.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The class is dedicated to the content singleton, so $parent_post_type, $parent_base, and $parent_controller never need overriding from the call site. Hardcode the post type and parent base, and instantiate the singleton controller directly inside restore_revision() when shaping the response. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The inherited WP_REST_Revisions_Controller::delete_item_permissions_check only requires `delete_post` capability, which editors hold on guideline posts. The singleton route is admin-managed for every other write — align revision deletion with that rule. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
307dd8e to
34a07f9
Compare
Part of:
Summary
Restores standard
WP_REST_Posts_Controllerbehavior on/wp/v2/guidelinesso anywp_guidelinepost can be created, listed, updated, and deleted with the usual fields (title, content, excerpt, author, taxonomy terms). The site-wide singleton — the post tagged with thecontentterm inwp_guideline_type— moves to a new/wp/v2/content-guidelinesroute backed byGutenberg_Content_Guidelines_REST_Controller. That controller preserves the existing customguideline_categoriesschema, the?status/?category/?blockfilters, the singleton-create guard, and the revision/restore semantics (now underGutenberg_Content_Guidelines_Revisions_Controllermounted at/wp/v2/content-guidelines/{id}/revisions).The singleton routes are scoped to actual content-typed posts:
/content-guidelines/{id}and its revisions sub-routes return 404 when the requested post lacks thecontentterm, so artifact-typed guidelines stay reachable only via the standard collection. The wp-admin Guidelines UI client and the e2e helper are updated to point at/wp/v2/content-guidelines.Singleton writes (POST/PATCH/DELETE on
/content-guidelines, plus revision DELETE and restore) requiremanage_options; reads use the post type's standardedit_postscap so editors can view but not modify the singleton. The standard/wp/v2/guidelinescollection inherits the post type's full capability map (now extended withpublish_posts,read_private_posts,edit_private_posts, anddelete_private_posts) so editors can create and manage artifact-typed guidelines through the default REST flow.Things to consider
The
wp_guidelinepost type advertises only the supports needed to make the editing flow functional today —title,editor,excerpt,author, andrevisions. The post type is internal (public: false,publicly_queryable: false), so there is no front-of-site to worry about, and the schema isn't a hard floor. Now that the standard/wp/v2/guidelinesendpoint is fully functional, it's worth deciding whether to widen it to be more page-like, since pages and posts share the same genericWP_REST_Posts_Controllerand the only thing that distinguishes them at the REST layer is the post type'ssupportsflags. The two changes most worth considering are addingthumbnail(so artifacts can carry a featured image, which helps in admin lists and pickers) and addingpage-attributestogether with flippinghierarchicaltotrueso guidelines can nest — Brand → Voice → Tone — alongside the flatwp_guideline_typetag. Skippingcustom-fieldsandcommentsseems right: the former only adds the legacy admin UI (register_post_meta()already exposes meta via the RESTmetafield), and the latter is out of band for guideline authoring. None of this changes the singleton route's hand-rolled schema; it only widens the standard/guidelinesendpoint.A second thing to consider is that singleton enforcement is now advisory rather than authoritative. Because
/wp/v2/guidelinesis open, an admin can POST a secondcontent-typed guideline directly to the standard collection and the new controller's "rest_guidelines_exists" guard won't catch it. If hard enforcement matters later, it would need to move into apre_post_*/save_post_wp_guidelinehook at the data layer. The acceptance here is that the singleton constraint is a UI affordance, not a data invariant.Test plan
vendor/bin/phpcs lib/experimental/guidelines phpunit/experimental/guidelinesnpm run test:unit:php:base -- --filter Guidelines— covers singleton CRUD, singleton-create guard, the query-param filters, the artifact-rejection guard on/content-guidelines/{id}and revisions, revision creation, restore, admin-only write enforcement, the revision deletion lock, the singleton schema, capability mapping, and artifact CRUD via/wp/v2/guidelinesnpm run lint:js -- routes/guidelines/api.ts test/e2e/specs/admin/guidelines.spec.jsGET /wp/v2/content-guidelinesreturns the singleton andPOSTto it errors when one already existsGET /wp/v2/guidelineslists artifact posts andPOST /wp/v2/guidelinescreates an artifact (auto-tagged with theartifactterm via the existingsave_post_wp_guidelinehook)PATCH /wp/v2/content-guidelines/{ARTIFACT_ID}returns 404 (rest_post_invalid_id)🤖 Generated with Claude Code