Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR allows option to deny specific block only on specific post types and/or specific templates. Fix #41062.
Why?
It's sometimes desirable to limit blocks to certain post-type contexts (or, in a parallel fashion, to prevent a specific block from being used in a given context).
How?
I created a straightforward filter to deny specific blocks from posts and pages based on the post_type. We can also specify which blocks should be removed from the site editor templates.
Currently, when clicking on templates from the template listing page, the page does not reload, so the filter does not apply until the template edit page is reloaded.
If this way of handling the block restriction looks good, then we can further develop the current code with option to handle on-click scenario.
For further improvement, we can also provide a backend option for users to specify which blocks to avoid for which post types if it needed.
Testing Instructions
After that check out this branch:
Create a new post.
Search for Gallery/Cover block: it should not be visible.
Create a new page.
Search for Quote/Video block: it should not be visible.
Open the FSE.
Open the Archive template & reload
Search for Columns/Quote block: it should not be visible.
Open the single template & reload
Search for Gallery/Cover block: it should not be visible.
Screenshots before and after adding filter
post-edit-after
post-edit-before
template-edit-after
template-edit-before
Thanks.