Opened 4 weeks ago
Last modified 4 weeks ago
#65866 new enhancement
Editor: Allow notes on templates and template parts
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Notes (block comments) shipped in 6.9 and work in the post and page editors, but not when editing templates or template parts in the site editor.
Notes are gated on the editor.notes post type feature, checked in WP_REST_Comments_Controller::check_post_type_supports_notes() and again in the block editor's post type support check. wp_template and wp_template_part declare a plain editor feature in create_initial_post_types(), so notes are refused for both.
Declaring the feature as an array opts both post types in, matching post and page:
'supports' => array( 'title', 'slug', 'excerpt', 'editor' => array( 'notes' => true ), 'revisions', 'author', ),
This leaves post_type_supports( 'wp_template', 'editor' ) returning true, so nothing else changes.
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 for a comment to attach to and are unaffected.
Permissions need no new code. Both post types register capability_type => array( 'template', 'templates' ) with map_meta_cap => true and map every primitive capability to edit_theme_options, so the edit_post meta 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.
Template notes do not leak: WP_Comment_Query excludes the note type by default since 6.9, and template post types are not publicly queryable.
The editor-side half of this (resolving a template record's numeric post ID from its wp_id, since the templates controller identifies records by a theme//slug string) lives in the Gutenberg plugin.
Gutenberg issue: https://github.com/WordPress/gutenberg/issues/72918
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/81548
PR: https://github.com/WordPress/wordpress-develop/pull/13027
Change History (1)
This ticket was mentioned in PR #13027 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)
## 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 https://github.com/WordPress/gutenberg/pull/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: https://github.com/WordPress/gutenberg/issues/72918
## Testing instructions
npm run test:php -- --filter test_template_post_types_support_notesedit_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