Skip to content

Notes: Store the blocks a note was added to, so a note stays attached when the post isn't saved - #15828

Draft
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:72717-note-anchor-snapshot
Draft

adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:72717-note-anchor-snapshot

Conversation

@adamsilverstein

Copy link
Copy Markdown
Member

Backport of WordPress/gutenberg#86471, which keeps a new note attached to its block when the post isn't saved afterwards.

Claude ported the PHP from the Gutenberg PR and wrote up the changes:

A note's link to its block (metadata.noteId, plus the inline wp-note marker) lives in the post content, so it only persists when the post is saved. The editor now sends a snapshot of the note's blocks with the note, and re-attaches an orphaned note on load from that snapshot.

  • Register _wp_note_anchor comment meta in wp_create_initial_comment_meta(): an array of { path, content } objects, shown in REST and writable with edit_comment, the same as _wp_note_status.
  • Run each snapshot through wp_kses_post() for users without unfiltered_html, the same as post content, since editors read it back over REST.
  • Add wp_delete_persisted_note_anchors() on wp_after_insert_post. It deletes the snapshot of each top-level note the saved content links to, and leaves the rest alone, since another user may have saved content from before the note was added.
  • Add the private helper _wp_get_note_ids_from_blocks(), which collects metadata.noteId values through inner blocks.

Testing:

  • New Tests_Comment_WpDeletePersistedNoteAnchors covers the cleanup and the helper, including inner blocks, notes on another post, malformed ids, and the KSES filtering.
  • New REST tests create a note with the meta and check that a bad path or an unknown property is rejected.
  • The comment and restapi-comments groups pass locally, and PHPStan level 10 is clean on the changed lines.

The editor side ships with the Gutenberg package update.

Trac ticket: TBD

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Claude ported the code from the Gutenberg PR, wrote the tests, and drafted this description. I will review and test.

🤖 Generated with Claude Code

https://claude.ai/code/session_018vwYjS8MTZ2CfXecy2yRiU


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

A note's link to its block lives in the post content and only persists when the post is saved, so a note added to a post that isn't saved afterwards is orphaned. Register `_wp_note_anchor` comment meta so the editor can store a snapshot of the note's blocks and re-attach the note on load, and delete the snapshot once a saved post links to the note.

Claude-Session: https://claude.ai/code/session_018vwYjS8MTZ2CfXecy2yRiU
The snapshot is block markup stored by any user who can edit the note, and editors read it back over REST. Run it through KSES for users without `unfiltered_html`, the same as post content, and drop malformed entries.

Claude-Session: https://claude.ai/code/session_018vwYjS8MTZ2CfXecy2yRiU
@github-actions

github-actions Bot commented Nov 8, 2026

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.

1 participant