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

Add a _doing_it_wrong() to WP_Block_Patterns_Registry::register() when hooked but not on init. #2662

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

costdev
Copy link
Contributor

@costdev costdev commented May 2, 2022

@costdev costdev force-pushed the register_block_pattern_doing_it_wrong branch 3 times, most recently from c2c2626 to f2889dc Compare May 2, 2022 23:08
@costdev costdev marked this pull request as ready for review May 2, 2022 23:52
@costdev costdev force-pushed the register_block_pattern_doing_it_wrong branch from f2889dc to a323a98 Compare May 3, 2022 00:25
@costdev costdev force-pushed the register_block_pattern_doing_it_wrong branch from a323a98 to 5a2d4c0 Compare May 3, 2022 00:31
@hellofromtonya
Copy link
Contributor

See my comments here WordPress/gutenberg#40736 (comment) about forcing registration to only be when hooked to init. I'm wondering what the impact to extenders will be.

@costdev costdev force-pushed the register_block_pattern_doing_it_wrong branch 2 times, most recently from 06f9034 to 3637f4e Compare May 3, 2022 00:36
@peterwilsoncc
Copy link
Contributor

See my comments here WordPress/gutenberg#40736 (comment) about forcing registration to only be when hooked to init. I'm wondering what the impact to extenders will be.

I think it will be problematic.

Both post types and taxonomy require developers wait until the init hook or later to register a custom object. As the init hook is relatively early, later registration can come in handy when the developer wishes to know something about the request when registering the custom object.

That may also be the case here where waiting for the query to be parsed may be helpful.

@costdev costdev force-pushed the register_block_pattern_doing_it_wrong branch from 9ea54aa to ea74100 Compare February 9, 2023 21:46
@hellofromtonya
Copy link
Contributor

Notice at the end of WP_Block_Patterns_Registry::register() there's code to detect and store a pattern not registered on init. The code in this PR would bail out before that code and the subsequent code that works with the registered_patterns_outside_init property. In other words, a _doing_it_wrong() with an early bail-out negates the tracking and use case of the registered_patterns_outside_init property and its usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants