-
Notifications
You must be signed in to change notification settings - Fork 7
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
How to conditionally register/unregister patterns #307
Comments
I wrote a proof of concept for this as a snippet-style post: https://docs.google.com/document/d/1S4aWXZ-Q3GUklA82XAi4fq8ZdtJBseAYl9I_zeSAeVI/edit?usp=sharing For more information on Snippets, see: #314 |
This can be reviewed now: https://docs.google.com/document/d/1S4aWXZ-Q3GUklA82XAi4fq8ZdtJBseAYl9I_zeSAeVI/edit?usp=sharing I've also added this a draft in the backend to test what Snippet post types will look like: https://developer.wordpress.org/news/?post_type=snippets&p=4596&preview=true |
Props to @ndiego and @ryanwelcher for 1st and 2nd reviews. We still need to get a proper thumbnail for this before pushing live but looking to do so tomorrow. |
Social copy:
|
Social scheduled for October 31st. |
Discussed in #296
Originally posted by justintadlock August 28, 2024
When building a theme, I am sometimes building patterns that rely on a third-party block. In general, this works well enough with WordPress, giving a notice to the user that they need to install and activate the block.
However, not all theme authors want those patterns to appear without the block installed.
It's easy enough to only register patterns with a late
init
action and a conditional check. However, themers lose the ability to use the auto-registration via the/patterns
folder.Instead, we can conditionally unregister these without losing
/patterns
folder support. This would be a short tutorial with a reasonably small bit of code to explain the technique.A code example is here: https://github.com/x3p0-dev/x3p0-ideas/blob/869d801bd7e11dccffb4b344b174c7b52ac89e52/src/Patterns.php#L134-L152
I'm not 100% sure this is worthy of a full tutorial, but not everything needs to be epic either. Sometimes these small techniques can be very helpful. This should definitely be sub-1,000 words.
The text was updated successfully, but these errors were encountered: