-
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: Conditionally enqueue blocks scripts when editing wp_template
posts
#32717
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. |
I've noticed the current implementation doesn't work as expected. In other words:
In other other words: this PR becomes a bugfix. 😓 |
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.
A couple of nits but this looks good to me
add_action( 'init', array( $this, 'register_blocks' ), 100 ); | ||
add_action( 'init', array( $this, 'register_wp_template' ) ); | ||
|
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.
The extra space here seems untidy
|
||
function is_editor_wp_template() { | ||
$current_screen = get_current_screen(); | ||
return 'wp_template' === $current_screen->post_type; |
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.
Since $current_screen
isn't being used for anything else I'd probably just rewrite this as a one-liner:
return 'wp_template' === get_current_screen()->post_type;
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.
Tests well for me.
FWIW I tried the allowed_block_types
filter which wasn't useful for this at all, and conditionally registering the script based on post type that will call unregisterBlockType
on domReady
. Both seemed more convoluted than the approach provided here.
5a5aea7
to
2320054
Compare
Changes proposed in this Pull Request
We want to limit FSE blocks to be only used in
wp_template
posts.In #32657 we merged a JS solution, as implied by the official docs.
In this alternative approach, we try to only enqueue the blocks scripts (and styles) when editing a
wp_template
post.The problem is that the blocks registration must be performed on
init
(or at least, all Core blocks are registered oninit
, and I tried to move FSE's to other hooks to no avail), and consequently, the blocks scripts must also be registered oninit
(before the blocks registration, which automatically enqueues them).On
init
, though, we don't have anycurrent_screen
information yet, and so wouldn't work:The remaining possibility is to check the query params:
$_GET['post_type]
is available when creating new posts.get_post_type( $_GET['post'] )
must be used when modifying an existing one.Testing instructions
Fixes Dennis' concerns in #32657 (review) (well, at least tries to 😄)