Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block templates with specific postTypes that have been edited by the user can be selected for any other post type #43557

Closed
Aljullu opened this issue Aug 24, 2022 · 2 comments · Fixed by #43597
Assignees
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended

Comments

@Aljullu
Copy link
Contributor

Aljullu commented Aug 24, 2022

Description

I originally opened this issue in Trac, but moving it here for better visibility.

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.

Step-by-step reproduction instructions

  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"
			]
		}
	],
	...
}
  1. Go to Appearance > Editor > Templates and make a modification to Custom Single Post template.
  2. Now, create a new page.
  3. 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.

Additional info

I think the issue is caused by _build_block_template_result_from_post() not setting a post_types attribute to the returned templates. _build_block_template_result_from_post() is used by get_block_template().

We identified that issue when working on WooCommerce templates. See woocommerce/woocommerce#42630.

Screenshots, screen recording, code snippet

No response

Environment info

No response

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

@Aljullu Aljullu added [Type] Bug An existing feature does not function as intended [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Aug 24, 2022
@Aljullu Aljullu self-assigned this Aug 24, 2022
@Aljullu
Copy link
Contributor Author

Aljullu commented Aug 24, 2022

PR created in wordpress-develop: WordPress/wordpress-develop#3131

@Mamaduka
Copy link
Member

Thanks for the core PR, @Aljullu.

I had a WIP branch for the plugin, which is slightly different from your patch. So I will try to create PR tomorrow morning.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Aug 25, 2022
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants