Skip to content

Editor: Allow notes on templates and template parts - #13027

Open
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:add/template-notes-support
Open

Editor: Allow notes on templates and template parts#13027
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:add/template-notes-support

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Aug 13, 2026

Copy link
Copy Markdown
Member

What

Declares notes support for wp_template and wp_template_part so that block-level notes work when editing templates 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. Both template post types declare a plain editor feature, so notes are refused for them today. Declaring the feature as an array opts them in, matching how post and page already do it, and leaves post_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 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.

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

Test with Playground

Unit tests

npm run test:php -- --filter test_template_post_types_support_notes

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:

( async () => {
	const site = document
		.querySelector( 'iframe' )
		.contentDocument.querySelector( 'iframe' );
	const url = new URL( site.src );
	const base = url.origin + '/' + url.pathname.split( '/' )[ 1 ];
	const w = site.contentWindow;
	const nonce = w.wpApiSettings.nonce;
	const api = ( path, opts = {} ) =>
		w.fetch( base + '/wp-json' + path, {
			credentials: 'include',
			headers: { 'X-WP-Nonce': nonce, 'Content-Type': 'application/json' },
			...opts,
		} );

	for ( const type of [ 'wp_template', 'wp_template_part' ] ) {
		const { supports } = await (
			await api( `/wp/v2/types/${ type }?context=edit&_fields=supports` )
		).json();
		console.log( type, '->', JSON.stringify( supports.editor ) );
	}

	// Templates are only notable once they exist as a post, so create one.
	const template = await (
		await api( '/wp/v2/templates', {
			method: 'POST',
			body: JSON.stringify( {
				slug: 'notes-test',
				title: 'Notes test',
				content: '<!-- wp:paragraph --><p>Hi</p><!-- /wp:paragraph -->',
			} ),
		} )
	).json();

	const res = await api( '/wp/v2/comments', {
		method: 'POST',
		body: JSON.stringify( {
			post: template.wp_id,
			type: 'note',
			content: 'Hello from a note',
		} ),
	} );
	console.log( 'POST /wp/v2/comments ->', res.status, await res.json() );
} )();

On this branch:

wp_template -> [{"notes":true}]
wp_template_part -> [{"notes":true}]
POST /wp/v2/comments -> 201 {…, type: 'note'}

Running the same snippet on a plain trunk Playground gives the before picture:

wp_template -> true
wp_template_part -> true
POST /wp/v2/comments -> 403 {code: 'rest_comment_not_supported_post_type'}

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

  1. In the site editor, create or customize and save a template.
  2. Select a block, open the block options menu, and add a note. Confirm it saves and survives a reload.
  3. Confirm a user without edit_theme_options (eg. an editor) receives a 403 from POST /wp/v2/comments with type=note against that template's post ID.
  4. Confirm notes on posts and pages are unchanged.

Trac ticket

https://core.trac.wordpress.org/ticket/65866

AI Use

Claude Code drafted the patch and this description. I will review and test.

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.
@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.

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

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