-
Notifications
You must be signed in to change notification settings - Fork 4.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
Global styles: specify priority in remove_action #43073
Conversation
@@ -105,7 +105,7 @@ function gutenberg_enqueue_global_styles() { | |||
} | |||
|
|||
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); | |||
remove_action( 'wp_footer', 'wp_enqueue_global_styles' ); | |||
remove_action( 'wp_footer', 'wp_enqueue_global_styles', has_action( 'wp_footer', 'wp_enqueue_global_styles' ) ); |
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.
Can we hardcode priority here?
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.
For sure, I tested with 1
and it works.
My reasoning was that has_action
gives us the right answer all the time.
Is it bad practice or slow to query it?
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.
It was mostly a nitpick. I don't think I've seen has_action
used this way, maybe only if priority is dynamically generated, and that's a bad idea for different reasons :)
Hardcoding the value should make scanning and getting all the data you need more accessible, IMO.
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.
Thanks for the fix, @ramonjd!
What?
This PR sets a priority in
remove_action( 'wp_footer', 'wp_enqueue_global_styles' );
, so that the core action is removed in time and the callback does not execute.Why?
In classic themes, when wp_should_load_separate_core_block_assets() returns
true
, global styles are printed twice:How?
Using has_action to get the priority of the already-registered callbackHardcoding the priority to
1
Testing Instructions
Switch to a classic theme.
Add the following filter somewhere:
Check that the styles in
global-styles-inline-css
are not loaded twice.