Skip to content

Knowledge: Rename the Guidelines CPT storage primitive to Knowledge#79149

Draft
gziolo wants to merge 5 commits into
trunkfrom
update/rename-guideline-cpt-to-knowledge
Draft

Knowledge: Rename the Guidelines CPT storage primitive to Knowledge#79149
gziolo wants to merge 5 commits into
trunkfrom
update/rename-guideline-cpt-to-knowledge

Conversation

@gziolo

@gziolo gziolo commented Jun 12, 2026

Copy link
Copy Markdown
Member

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:

  • CPT slug: wp_guidelinewp_knowledge
  • Taxonomy: wp_guideline_typewp_knowledge_type
  • Types registry + filter: wp_guideline_typeswp_knowledge_types
  • Capability namespace: *_guidelines*_knowledge
  • Generic REST route: /wp/v2/guidelines/wp/v2/knowledge (following the attachment/wp/v2/media precedent)
  • Built-in types: contentguideline (the type the site-wide guidelines singleton carries), artifactnote (private freeform working text; the save-time fallback term), memory stays.

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 (not instruction), the capability filter is the public wp_maybe_grant_knowledge_caps() hooked at priority 1 (matching the wp_maybe_grant_* family), wp_knowledge disables autosave (headless storage with no editor session; revisions retained), and the wp_knowledge_type taxonomy 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).
  • Capabilities: registered as capability_type => array( 'knowledge_item', 'knowledge' ). "Knowledge" is a mass noun, so the singular base must differ from the plural: with both set to knowledge, the generated per-post meta caps (edit_knowledge_item) would collide with the primitives (edit_knowledge), making current_user_can( 'edit_knowledge' ) ambiguous. The *_knowledge_item forms are never granted and never typed in checks — map_meta_cap() resolves them — so the visible capability surface is *_knowledge throughout. A dedicated test (test_post_type_meta_caps_do_not_collide_with_primitives) locks this in.
  • Intentionally unchanged: the Settings → Guidelines page and its client app (routes/guidelines/, zero JS changes), the /wp/v2/content-guidelines singleton route (it now resolves the site-wide post by the guideline term instead of content), all user-facing Guidelines labels, the gutenberg-guidelines experiment id (persisted in site options), and the _guideline_* post meta keys (storage shape is orthogonal to the proposal).
  • Data migration: a one-time migration in lib/upgrade.php moves existing wp_guideline rows and wp_guideline_type terms to the new identifiers and re-slugs the built-in type terms (contentguideline, artifactnote), 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 skill type, 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

  1. Enable the Guidelines experiment under Gutenberg → Experiments.
  2. Visit Settings → Guidelines, save some guidelines, and confirm the page works unchanged (round-trips through /wp/v2/content-guidelines).
  3. As an admin, GET /wp/v2/knowledge returns the collection (including the singleton row, typed guideline); POST /wp/v2/knowledge without a type creates a private row with the note fallback term.
  4. On a site with pre-rename data: after updating, confirm wp_guideline rows reappear as wp_knowledge with re-slugged type terms (run _gutenberg_migrate_guidelines_to_knowledge() fires once via the version bump in lib/upgrade.php).
  5. npm run test:unit:php:base -- --group knowledge,guidelines — 161 tests covering the full feature.

🤖 Generated with Claude Code

@gziolo gziolo self-assigned this Jun 12, 2026
@gziolo gziolo added [Feature] Guidelines An experimental feature for adding site-wide editorial rules. [Type] Breaking Change For PRs that introduce a change that will break existing functionality No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels Jun 12, 2026
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 8.6 MB

compressed-size-action

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Flaky tests detected in 44f408c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27698497871
📝 Reported issues:

@gziolo

gziolo commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

After opening PR against WordPress core trunk, this PR needs to get refreshed to adjust based on my findings there:

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.

gziolo and others added 5 commits June 17, 2026 16:59
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>
@gziolo gziolo force-pushed the update/rename-guideline-cpt-to-knowledge branch from 4e1214d to 44f408c Compare June 17, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Guidelines An experimental feature for adding site-wide editorial rules. No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Breaking Change For PRs that introduce a change that will break existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant