-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Full Site Editing: Only allow FSE blocks in wp_template CPT #32657
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
This approach is fine in the short term but will break once we move to a more universal editing model, since the In lieu of better logic for showing/allowing blocks in varying contexts, we could also approach this by modifying the internal logic of the block's But I think that would be premature, this gets us moving just fine. |
Good point, I didn't think about that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm less of a fan of doing this in JavaScript even though the approach in abstract is how I'd prefer to do it - conditionally register the blocks based on if we're editing a wp_template
Doing it in JavaScript opens us up to even more data races that have already given us headaches with conditionally-registered block types.
How about conditionally queuing the script in PHP in the plugin based on whether the current page is a wp_template
? Did you try that approach?
@dmsnell I did try that, but to be honest I haven't explored it enough, once I got stuck trying to figure out the action order. I can push an alternative approach to this one, it would also solve the Core's |
@Copons that sounds like a golden comment to add in the implementation here if you ask me // Note: we _could_ have conditionally enqueued this script from the server
// but at the time that the `init` hook runs in PHP we don't know the post type
// so we can't make that choice there whether or not to load this
//
// It _may_ be possible to transition to a server-based approach and that could
// alleviate related issues with data-races affecting block registration. |
For some reason I'm no longer able to insert this blocks to any post type (including |
Changes proposed in this Pull Request
wp_template
CPT.Note: my first thinking was to use the
allowed_block_types
filter, which seems designed exactly for this purpose, but in fact falls short of our needs.The first parameter (and return value) can be
true
if all blocks are allowed,false
if none, or a whitelist of allowed blocks.This means that, if we want to disallow FSE blocks from all post types except
wp_template
, we would need to return an array including all blocks except the FSE ones.The filter doesn't make such list available, and as far as I know there is no way to get it in PHP.
JS-side, it's slightly easier but less elegant: once the DOM is ready, only register the blocks if the current post's type is
wp_template
.Testing instructions
Part of #32618 and #32619