Knowledge: Rename the Guidelines CPT storage primitive to Knowledge#79149
Knowledge: Rename the Guidelines CPT storage primitive to Knowledge#79149gziolo wants to merge 5 commits into
Conversation
|
Size Change: 0 B Total Size: 8.6 MB |
|
Flaky tests detected in 44f408c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27698497871
|
|
After opening PR against WordPress core I'll keep this PR in the draft stage also because we need to sort out the story of how we end up storing the content that users save on the Guidelines settings page, which is being explored in: Both Gutenberg PRs must land in the same Gutenberg plugin release. As part of that, we will most likely also promote Guidelines to a regular feature that is no longer behind and an experiment. |
Renames the storage-primitive identifiers per the consolidation proposal in #77230: the CPT slug (wp_guideline -> wp_knowledge), the type taxonomy (wp_guideline_type -> wp_knowledge_type), the types registry and filter (wp_guideline_types -> wp_knowledge_types), the capability namespace (*_guidelines -> *_knowledge), and the generic REST route (/wp/v2/guidelines -> /wp/v2/knowledge). The capability registration uses capability_type => array( 'knowledge_item', 'knowledge' ) because "knowledge" is a mass noun: with identical singular/plural bases the generated per-post meta caps would collide with the primitives. The *_knowledge_item forms are never granted; map_meta_cap() resolves them. User-facing surfaces are intentionally unchanged: the Settings > Guidelines page, the /wp/v2/content-guidelines singleton route, all Guidelines labels, the gutenberg-guidelines experiment id, and the _guideline_* meta keys. The built-in type slugs (content, artifact, memory) are renamed separately. Ships a one-time data migration (lib/upgrade.php) that moves existing wp_guideline rows and wp_guideline_type terms to the new identifiers so sites already building on the experiment are not orphaned. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Renames two of the three built-in knowledge types per the #77230 proposal so every type is defined by behavior rather than by relation: - `content` -> `instruction`: loaded by default when applicable. The site-wide guidelines singleton managed by Settings > Guidelines now carries the `instruction` term; the /wp/v2/content-guidelines route is otherwise unchanged. - `artifact` -> `note`: private freeform working text, and the fallback term assigned on save when no type is given. - `memory` stays as is. The one-time migration in lib/upgrade.php now also re-slugs existing terms (content -> instruction, artifact -> note), replacing term names only when they still match the previous default labels so customized labels survive. The re-slug runs independently of the legacy taxonomy flip so partially migrated rows are covered too. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The gutenberg-guidelines flag gates more than the Settings page since the storage primitive rename: it also enables the wp_knowledge CPT, the /wp/v2/knowledge API, and the capability namespace integrators build on. The experiment id and label stay unchanged — the id is persisted in the gutenberg-experiments option on sites that enabled it, and the label follows the proposal's rule that the user-facing name stays Guidelines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Every other test file in the directory carries a group annotation; this one was missed when it was introduced, so group-filtered runs silently skipped it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Aligns the experimental Knowledge implementation with the refined version ported to WordPress core in WordPress/wordpress-develop#12201: - Built-in type `instruction` renamed to `guideline`; the core type registry consolidated on `guideline`/`memory`/`note`. The migration target slug, the TERM_GUIDELINE constant, and the content-guidelines singleton follow. - Type titles now use the `_x( ..., 'knowledge type' )` context. - Capability filter `_wp_knowledge_synthesize_caps` becomes the public `wp_maybe_grant_knowledge_caps`, hooked at priority 1 to match the `wp_maybe_grant_*` family. - Disable autosave support for `wp_knowledge` (headless storage with no editor session); revision history is retained. - Register the `wp_knowledge_type` taxonomy as headless (`show_ui => false`). - Align the private-status REST error message with core. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4e1214d to
44f408c
Compare
What?
This PR is an illustration for the consolidation proposal in #77230 (comment) — it implements the proposed rename of the Guidelines CPT to a Knowledge storage primitive, plus the type consolidation, so the expected end state can be reviewed as working code rather than prose. The direction is still gathering feedback on the issue; this branch exists to make that conversation concrete.
Renames, per the proposal:
wp_guideline→wp_knowledgewp_guideline_type→wp_knowledge_typewp_guideline_types→wp_knowledge_types*_guidelines→*_knowledge/wp/v2/guidelines→/wp/v2/knowledge(following theattachment→/wp/v2/mediaprecedent)content→guideline(the type the site-wide guidelines singleton carries),artifact→note(private freeform working text; the save-time fallback term),memorystays.The storage primitive tracks the WordPress core counterpart opened at WordPress/wordpress-develop#12201, and has been refreshed to match the refinements made there: the built-in type settled on
guideline(notinstruction), the capability filter is the publicwp_maybe_grant_knowledge_caps()hooked at priority 1 (matching thewp_maybe_grant_*family),wp_knowledgedisables autosave (headless storage with no editor session; revisions retained), and thewp_knowledge_typetaxonomy is headless (show_ui => false).Why?
"Knowledge" is the namespace for the storage primitive, API, capabilities, and type registry, while individual rows are referred to by their concrete type (a guideline, a memory, a note). The reasoning, prior feedback, and the full type model are in the proposal comment.
Renaming now is cheap: the feature is an experiment with no backward-compatibility guarantee, and the same rename would be much harder after a core merge.
How?
lib/experimental/guidelines/→lib/experimental/knowledge/, with the primitive classes renamed (Gutenberg_Knowledge_Post_Type,Gutenberg_Knowledge_REST_Controller).capability_type => array( 'knowledge_item', 'knowledge' ). "Knowledge" is a mass noun, so the singular base must differ from the plural: with both set toknowledge, the generated per-post meta caps (edit_knowledge_item) would collide with the primitives (edit_knowledge), makingcurrent_user_can( 'edit_knowledge' )ambiguous. The*_knowledge_itemforms are never granted and never typed in checks —map_meta_cap()resolves them — so the visible capability surface is*_knowledgethroughout. A dedicated test (test_post_type_meta_caps_do_not_collide_with_primitives) locks this in.routes/guidelines/, zero JS changes), the/wp/v2/content-guidelinessingleton route (it now resolves the site-wide post by theguidelineterm instead ofcontent), all user-facing Guidelines labels, thegutenberg-guidelinesexperiment id (persisted in site options), and the_guideline_*post meta keys (storage shape is orthogonal to the proposal).lib/upgrade.phpmoves existingwp_guidelinerows andwp_guideline_typeterms to the new identifiers and re-slugs the built-in type terms (content→guideline,artifact→note), preserving user-customized term labels. It runs even when the experiment is currently disabled, so integrations already building on the CPT are not orphaned.Out of scope, as follow-ups per the proposal: the
skilltype, the knowledge-management ability (Abilities API), pinning the singleton by ID instead of by term, and any evolution of the singleton storage shape.Testing Instructions
/wp/v2/content-guidelines).GET /wp/v2/knowledgereturns the collection (including the singleton row, typedguideline);POST /wp/v2/knowledgewithout a type creates a private row with thenotefallback term.wp_guidelinerows reappear aswp_knowledgewith re-slugged type terms (run_gutenberg_migrate_guidelines_to_knowledge()fires once via the version bump inlib/upgrade.php).npm run test:unit:php:base -- --group knowledge,guidelines— 161 tests covering the full feature.🤖 Generated with Claude Code