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

Pattern postTypes no longer honored #52717

Closed
webmandesign opened this issue Jul 18, 2023 · 2 comments
Closed

Pattern postTypes no longer honored #52717

webmandesign opened this issue Jul 18, 2023 · 2 comments
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended

Comments

@webmandesign
Copy link
Contributor

Description

In my block theme I set 'postTypes' => [ 'wp_template', 'wp_template_part' ] (via register_block_pattern() PHP function) for all patterns that are meant to be used in Site Editor only (they should not be used in page block editor).

Then I insert such pattern into a Template Part with <!-- wp:pattern {"slug":"my-theme/site/header"} /-->, for example.

Everything is working perfectly fine with WordPress 6.2.2 - the site header pattern is correctly rendered when editing site header template part in Site Editor.

However, when I activate Gutenberg 16.2.1, the pattern is not rendered at all in Site Editor when editing related template part. The pattern is not available via block/pattern inserter either.

I've traced the issue down to setting up the postTypes attribute. Once I remove this attribute from the pattern registration arguments, the pattern renders OK.

Please check and fix this functionality. I think it should still work the same as it does with WP6.2.

Step-by-step reproduction instructions

The description says it all.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.2.2
  • Gutenberg 16.2.1

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

@bph bph added Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Jul 18, 2023
@andrewserong
Copy link
Contributor

Thanks for reporting this issue @webmandesign! I tested and confirmed that the issue was present in Gutenberg 16.2.1, and has been resolved in trunk. It appears to have been fixed by #52503, which sets the template type for the site editor by retrieving the current post type via getEditedPostType. It seems that prior to that PR, the site editor's settings had a template type of undefined, so the match against postTypes for registered block patterns was failing.

Since this fix will be rolled out to both Gutenberg 16.3 and WP 6.3, I'll close out this issue now.

@webmandesign
Copy link
Contributor Author

@andrewserong Perfect! Thanks for fast resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended
Projects
No open projects
Development

No branches or pull requests

3 participants