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
- 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;
}
);
- Go to
/category/my-category/ to verify the template is applied correctly:
- Click on Edit Site in the top bar.
- Now, click on the Actions menu:
- 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.
- 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.
- Click on Edit Site again.
- Issue 2: This brings you to the unmodified template, instead of the template you just edited.
- Go to Appearance > Editor > Templates > Active templates. Open the modified Plugin Template, deactivate it and then move it to the trash.
- Now go to Appearance > Editor > Templates > Gutenberg.
- Activate the plugin template:
- 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.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
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
You can optionally also add the snippet below, but I don't think it makes a difference:
/category/my-category/to verify the template is applied correctly:/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.Screenshots, screen recording, code snippet
No response
Environment info
trunk.Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.