Editor: Allow notes on templates and template parts - #13027
Editor: Allow notes on templates and template parts#13027adamsilverstein wants to merge 2 commits into
Conversation
Notes are gated on the editor.notes post type feature. Templates and template parts declare a plain editor feature, so the REST comments controller refuses notes for them and the block editor hides its notes UI. Declare the feature as an array for both post types, matching post and page, which leaves post_type_supports() unchanged. Notes attach to templates that exist as posts, so user-created and customized templates gain notes while theme-provided template files are unaffected. Permissions need no new code: both post types map their primitive capabilities to edit_theme_options, so the edit_post meta cap the comments controller checks already resolves correctly.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
What
Declares notes support for
wp_templateandwp_template_partso that block-level notes work when editing templates in the site editor.Notes are gated on the
editor.notespost type feature, checked inWP_REST_Comments_Controller::check_post_type_supports_notes()and again in the block editor's post type support check. Both template post types declare a plaineditorfeature, so notes are refused for them today. Declaring the feature as an array opts them in, matching howpostandpagealready do it, and leavespost_type_supports( 'wp_template', 'editor' )returning true.Notes are comments, so they attach to templates that exist as posts - user-created templates, and theme templates once they have been customized and saved. Theme-provided template files have no post to attach a comment to and are unaffected.
Permissions need no new code. Both post types map every primitive capability to
edit_theme_options, so theedit_postmeta cap the comments controller already checks resolves to the template editing capability. Users who cannot edit templates can neither read nor create notes on them.This is the Core counterpart of WordPress/gutenberg#81548, which carries the editor-side change (resolving the numeric post ID for a template record) and the plugin-side test coverage.
Related Gutenberg issue: WordPress/gutenberg#72918
Testing instructions
Unit tests
In Playground
The badge above boots this branch. Getting notes into the site editor UI takes an editor-side change that lives in the Gutenberg PR, so a build of this branch on its own cannot show that flow - what it can show is the REST gate this patch controls, which is the whole of the change.
Wait for the Playground dashboard to load, then open the browser console on the Playground tab itself (not on a site editor screen, which is cross-origin) and paste:
On this branch:
Running the same snippet on a plain trunk Playground gives the before picture:
The site editor flow
Boot this branch with the Gutenberg PR on top to walk the UI, following the steps on WordPress/gutenberg#81548. Worth noting for anyone reading the result: the plugin ships its own copy of this supports declaration so notes work on templates before 7.2 lands, so that instance demonstrates the feature end to end rather than this patch in isolation.
Manually, on a local build
edit_theme_options(eg. an editor) receives a 403 fromPOST /wp/v2/commentswithtype=noteagainst that template's post ID.Trac ticket
https://core.trac.wordpress.org/ticket/65866
AI Use
Claude Code drafted the patch and this description. I will review and test.