Skip to content

Template activation bugs with plugin-registered templates #72475

@Aljullu

Description

@Aljullu

Description

While testing the template activation feature with a plugin-registered template in Gutenberg 21.8.2, I found a few issues.

The bugs might be in the Template registration API itself, or I might have done something wrong in my testing. In any case, documenting them here in case they are useful:

Step-by-step reproduction instructions

  1. Add this code to an existing plugin or in a code snippet using the Code Snippets plugin:
add_action(
	'init',
	function () {
		register_block_template(
			'gutenberg//plugin-template',
			array(
				'title'       => 'Plugin Template',
				'description' => 'A template registered by a plugin.',
				'content'     => '<!-- wp:template-part {"slug":"header","tagName":"header"} /--><!-- wp:group {"tagName":"main","layout":{"inherit":true}} --><main class="wp-block-group"><!-- wp:paragraph --><p>This is a plugin-registered template.</p><!-- /wp:paragraph --></main><!-- /wp:group -->',
			)
		);
		add_action(
			'category_template_hierarchy',
			function () {
				return array( 'plugin-template' );
			}
		);
	}
);

You can optionally also add the snippet below, but I don't think it makes a difference:

		add_filter(
			'default_template_types',
			function ( $default_template_types ) {
				$default_template_types['gutenberg//plugin-template'] = array(
					'title'       => 'Plugin Template',
					'description' => 'A template registered by a plugin.',
				);
				return $default_template_types;
			}
		);
  1. Go to /category/my-category/ to verify the template is applied correctly:
Image
  1. Click on Edit Site in the top bar.
  2. Now, click on the Actions menu:
Image
  • Issue 1: It allows moving the template to trash, but this doesn't seem to make any difference in the frontend: the template keeps being rendered. I believe the editor shouldn't allow moving plugin-registered templates to trash.
  1. Go back to /category/my-category/ and click on Edit Site. Make some edits to the template, save and activate the template. Verify they are applied in the frontend.
Image
  1. Click on Edit Site again.
  • Issue 2: This brings you to the unmodified template, instead of the template you just edited.
  1. Go to Appearance > Editor > Templates > Active templates. Open the modified Plugin Template, deactivate it and then move it to the trash.
  2. Now go to Appearance > Editor > Templates > Gutenberg.
  3. Activate the plugin template:
Image
  • Issue 3: Activating a plugin template doesn't seem to do anything. If after activating it you go to Active templates, it's not there.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.9-alpha-60939.
  • Gutenberg trunk.

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

Needs TestingNeeds further testing to be confirmed.[Feature] Templates APIRelated to API powering block template functionality in the Site Editor[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions