WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.47k stars 4.18k forks source link

register_block_pattern() returns 'true' however pattern has not successfully registered if pattern contains block not in whitelist, specifically (columns, column) #59413

Open smile-matt-oakley opened 7 months ago

smile-matt-oakley commented 7 months ago

Description

The Issue and context

I have a theme that defines a whitelist of blocks using the filter, allowed_block_types_all, in this whitelist I allow the block core/columns. This successfully allows columns to be used in the editor, this also allowed the block core/column to be used, even if not specifically specified in the whitelist. This works as personally expected.

However I recently started registering patterns using register_block_pattern(). Our patterns included a 50/50 columns block which included the child column block. When these blocks are passed to the register_block_pattern() the function returns true that the patterns successfully registered, but upon loading the pattern library the patterns failed to appear.

After digging around I found that if you if do not specifically include core/column in the whitelist the pattern will register "successfully" (according to the functions return) but will fail to register as a selectable pattern. Only once adding the core/column to the whitelist will the pattern then actually be registered successfully and be available for use in the editor.

This caused great confusion as using just core/columns enabled both the "column" and "columns" in the editor experience, however when registering patterns the pattern failed to register silently.

I propose that either of the following:

  1. When registering a pattern if the core/columns block is whitelisted it also recongises core/column as a whitelisted block.
  2. The function register_block_pattern() returns an error specifying that the pattern you are attempting to register includes blocks that are not in the whitelist.

Step-by-step reproduction instructions

  1. Define a whitelist using allowed_block_types_all and only add core/columns
  2. Create a set of blocks that uses the columns block.
  3. Register the pattern using register_block_pattern()
  4. The pattern should fail to register, but the function will return true.
  5. Inside your whitelist now add core/column
  6. The pattern should now be registered and selectable.

Screenshots, screen recording, code snippet

No response

Environment info

Wordpress version 6.4.3

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

github-actions[bot] commented 6 months ago

Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.