Opened 4 weeks ago
Last modified 4 weeks ago
#65872 new defect (bug)
Editor: enable notes on the global styles post type
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Claude did most of the write up here, forwarded along with some edits:
Notes as they shipped in 6.9 anchor twice: to a post, through comment_post_ID, and within that post to a block, through that block's own metadata.noteId attribute. A surface with neither is out of reach today.
The Style Book is exactly that surface. It has no post of its own, and its examples are generated fresh on every render, so there is no persisted block to record a note id on. Feedback on a theme's styles - "these headings feel tight", "this button needs more contrast" - currently has nowhere to live, and reviewing a theme's styles is one of the places a review conversation is most useful.
See https://github.com/WordPress/gutenberg/issues/73278 for the feature request and the discussion behind it.
Proposed change
Two small additions, neither of which changes existing behavior:
wp_global_stylesdeclares notes support, by way of'editor' => array( 'notes' => true )increate_initial_post_types(). The theme's user global styles post is the record the Styles UI already edits, which makes it the natural home for feedback about that theme's styles.
- A new
_wp_note_anchorcomment meta, registered inwp_create_initial_comment_meta(). A single string that the anchoring surface defines and resolves, sanitized withsanitize_text_fieldand capped at 100 characters. Core never interprets it.
For the Style Book the anchor holds the example name - core/button, typography, theme-colors. Those names are deterministic and stable across sessions, users and reloads, which block client ids are not.
Nothing in core reads the anchor. This is the storage half; the UI lives in Gutenberg.
Consequences worth stating
- Notes on global styles inherit that post type's capabilities, so writing one requires
edit_theme_options. On most sites that means administrators only. - Core keeps one global styles post per theme, so the notes are theme-specific. Switching themes shows a different set; switching back brings the original notes with it. That seems right given the styles being reviewed are themselves theme specific, but it is a semantic worth confirming.
Patches
- Core: https://github.com/WordPress/wordpress-develop/pull/13030
- Gutenberg (the UI, plus the same two registrations as a
wordpress-7.2compat file): https://github.com/WordPress/gutenberg/pull/81554
Questions
- Should
_wp_note_anchorbe a flat string, or namespaced from day one - eg.stylebook:core/button- to leave room for other anchor domains such as template areas or theme.json paths? The meta is a string either way, so a namespaced scheme could be layered on later without a migration. - Is
edit_theme_optionsthe intended audience, or is there appetite for letting lower roles view but not write these notes? That would need a capability mapping change and is not part of this patch. - Is theme-specific the right semantic to ship, with the switching behavior documented?
Change History (1)
This ticket was mentioned in PR #13030 on WordPress/wordpress-develop by @adamsilverstein.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
## Trac ticket: https://core.trac.wordpress.org/ticket/65872
---
The core half of Style Book notes. Gutenberg PR: https://github.com/WordPress/gutenberg/pull/81554, which fixes https://github.com/WordPress/gutenberg/issues/73278.
Notes as they shipped in 6.9 anchor twice: to a post, through
comment_post_ID, and within that post to a block, through the block's ownmetadata.noteIdattribute. A surface with neither is out of reach today. The Style Book is exactly that surface - it has no post of its own, and its examples are generated fresh on every render, so there is no persisted block to record a note id on.Two small additions cover it.
wp_global_stylesdeclares notes support. The theme's user global styles post is the record the Styles UI already edits, so it is the natural home for feedback about that theme's styles. Nothing else about the post type changes.A
_wp_note_anchorcomment meta. A single string the anchoring surface defines and resolves, sanitized withsanitize_text_fieldand capped at 100 characters. Core never interprets it. For the Style Book it holds the example name -core/button,typography,theme-colors- which is deterministic and stable across sessions, users and reloads in a way block client ids are not.Nothing in core reads the anchor yet. This is the storage half; the UI lives in the Gutenberg PR above.
Two consequences worth stating plainly, since neither is obvious from the diff:
edit_theme_options. On most sites that means administrators only.## How has this been tested
tests/phpunit/tests/rest-api/rest-global-styles-notes.phpadds 17 tests:WP_REST_Comments_Controller::check_post_type_supports_notes()actually reads, andpost_type_supports( 'wp_global_styles', 'editor' )still returning trueManual testing needs the Gutenberg PR for the UI. Its description has the steps.
## Types of changes
'editor' => array( 'notes' => true )to thewp_global_stylessupports increate_initial_post_types()._wp_note_anchorcomment meta inwp_create_initial_comment_meta().## Checklist:
@sincereferences.## AI Use
Code and description both written with 🤖 Claude Code. I will review and test.