[wp-trac] [WordPress Trac] #55881: Block templates with specific postTypes that have been edited by the user can be selected for any other post type
WordPress Trac
noreply at wordpress.org
Tue May 31 11:56:40 UTC 2022
#55881: Block templates with specific postTypes that have been edited by the user
can be selected for any other post type
--------------------------+-----------------------------
Reporter: aljullu | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When a block template provided by a theme has been edited by the user, the
`postTypes` argument is ignored, so the template is available for the
wrong post types.
== Steps to reproduce ==
1. With a block theme (I used Twenty Twenty Two), create two templates and
add them to `theme.json`:
{{{
{
"version": 2,
"customTemplates": [
....
{
"name": "custom-single-post-template",
"title": "Custom Single Post template",
"postTypes": [
"post"
]
},
{
"name": "custom-single-post-template-not-
modified",
"title": "Custom Single Post template (not
modified)",
"postTypes": [
"post"
]
}
],
...
}
}}}
2. Go to Appearance > Editor > Templates and make a modification to
`Custom Single Post template`.
3. Now, create a new page.
4. Notice in the ''Template'' panel in the sidebar, `Custom Single Post
template` is available while `Custom Single Post template (not modified)`
isn't.
== Expected behavior ==
If the user modifies a template in the Site Editor, that shouldn't affect
which post types that template is available for.
== More context ==
I think the issue is caused by [https://github.com/WordPress/wordpress-
develop/blob/91dc2d1b42d8208f257947b9379a37d4df514747/src/wp-includes
/block-template-utils.php#L550 `_build_block_template_result_from_post()`]
not setting a `post_types` attribute to templates returned.
`_build_block_template_result_from_post()` [https://github.com/WordPress
/wordpress-develop/blob/91dc2d1b42d8208f257947b9379a37d4df514747/src/wp-
includes/block-template-utils.php#L791 is used by `get_block_template()`].
We identified that issue when working on WooCommerce templates. See
[https://github.com/woocommerce/woocommerce-blocks/issues/6490 woocommerce
/woocommerce-blocks#6490].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55881>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list