Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Hidden patterns should use false instead of no for the inserter property #580

Conversation

benoitchantre
Copy link

Description
Fixes #578.

The official documentation says that false should be used instead of no for the inserter property.

inserter (optional): By default, all patterns will appear in the inserter. To hide a pattern so that it can only be inserted programmatically, set the inserter to false.
source (optional): A string that denotes the source of the pattern.

https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/

Testing Instructions
Check that hidden patterns are not available from the inserter.

Contributors
benoitchantre

@huzaifaalmesbah
Copy link
Collaborator

Thank you for your valuable contribution.

@carolinan
Copy link
Contributor

carolinan commented Oct 8, 2023

Hi,
the documentation you are refererring to is for register_block_pattern() only.
When we place patterns inside the patterns folder, register_block_pattern() is not used, see https://developer.wordpress.org/reference/functions/_register_theme_block_patterns/
https://make.wordpress.org/core/2022/05/02/new-features-for-working-with-patterns-and-themes-in-wordpress-6-0/

It would absolutely have been easier for the developers if the two methods were more consistent, but now it has already been documented as yes/no and not true/false and it will need to continue to support yes/no.


It seems something has broken in 6.4. I would like to learn if this is only something on my local install, or if it can be reproduced, because then we have to create a new issue in the Gutenberg repository.

With 6.4 beta 2, current nightly:

If I add Inserter: false OR Inserter: no to any pattern in the patterns folder that is not already hidden, like if I update patterns/hero.php in my code editor, save the file, and then create a new post or page, that pattern remains available to me in the inserter.
Similarly, if I update the categories value for the hero pattern, the category does not change in the editor.

@benoitchantre
Copy link
Author

Thank you @carolinan for the explanation.

It seems something has broken in 6.4. I would like to learn if this is only something on my local install, or if it can be reproduced, because then we have to create a new issue in the Gutenberg repository.

Are you using the WP_DEVELOPMENT_MODE constant with theme as value?
https://make.wordpress.org/core/2023/07/14/configuring-development-mode-in-6-3/

I can't reproduce that when WP_DEVELOPMENT_MODE is used.

@benoitchantre benoitchantre deleted the fix-inserter-value-for-hidden-patterns branch October 8, 2023 20:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
3 participants