Skip to content

Editor: allow notes on the global styles post type. - #13030

Open
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:add/stylebook-notes-global-styles
Open

Editor: allow notes on the global styles post type.#13030
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:add/stylebook-notes-global-styles

Conversation

@adamsilverstein

Copy link
Copy Markdown
Member

Trac ticket:

Being filed now, will be linked here once it has a number.


The core half of Style Book notes. Gutenberg PR: WordPress/gutenberg#81554, which fixes WordPress/gutenberg#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 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.

Two small additions cover it.

wp_global_styles declares 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_anchor comment meta. A single string the anchoring surface defines and resolves, sanitized with sanitize_text_field and 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:

  • 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 these notes are theme-specific. Switching themes shows a different set; switching back brings the original notes with it.

How has this been tested

tests/phpunit/tests/rest-api/rest-global-styles-notes.php adds 17 tests:

  • the support shape WP_REST_Comments_Controller::check_post_type_supports_notes() actually reads, and post_type_supports( 'wp_global_styles', 'editor' ) still returning true
  • the anchor meta registration and its REST exposure
  • REST create and list against the global styles post, with the anchor round-tripping through the response and into comment meta
  • 403 for an author and 401 for anonymous, on both read and write
  • anchor sanitization, and the length cap rejecting rather than truncating
  • post types without notes support still being refused, so this did not widen the gate

Manual testing needs the Gutenberg PR for the UI. Its description has the steps.

Types of changes

  • Add 'editor' => array( 'notes' => true ) to the wp_global_styles supports in create_initial_post_types().
  • Register a _wp_note_anchor comment meta in wp_create_initial_comment_meta().
  • Add tests covering both.

Checklist:

  • My code is tested.
  • My code follows the WordPress code standards.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all @since references.

AI Use

Code and description both written with 🤖 Claude Code. I will review and test.

Notes anchor to a post, and within it to a block through that block's
metadata.noteId attribute. Surfaces with neither are out of reach today:
the Style Book 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.

Declare notes support on wp_global_styles so the theme's own styles
record can carry those threads, and register a _wp_note_anchor comment
meta holding an identifier the anchoring surface defines and resolves.
The value is opaque to core and capped at 100 characters.

Nothing in core reads the anchor yet; this is the storage half of the
Style Book notes UI in Gutenberg. Two consequences worth noting: notes
on global styles inherit that post type's capabilities, so writing one
requires edit_theme_options, and because core keeps one global styles
post per theme, the notes are theme-specific.
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein, poena, im3dabasia1, desrosj.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Notes for the Style Book

1 participant