Script Loader: Respect global styles opt-out in classic themes with on-demand assets#11961
Script Loader: Respect global styles opt-out in classic themes with on-demand assets#11961itzmekhokan wants to merge 2 commits into
Conversation
…n-demand assets. Since WordPress 6.9/7.0, classic themes enqueue global styles in the footer for hoisting. Previously common remove_action/wp_dequeue_style calls during wp_enqueue_scripts no longer prevented global-styles-inline-css from being injected into the head. Props edent. Fixes #65336.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Summary
global-styles-inline-csscould not be removed in classic themes after WordPress 6.9/7.0.wp_footerand hoisted into<head>, older opt-out patterns (remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' )andwp_dequeue_style( 'global-styles' )duringwp_enqueue_scripts) no longer prevented the inline CSS from appearing.What changed
In
wp_enqueue_global_styles()for classic themes with on-demand block assets:global-styleshandle duringwp_enqueue_scriptsso it can be dequeued before footer processing.wp_enqueue_scriptsto detect dequeue/remove opt-outs.Why this is a valid bug
Before 6.9/7.0, dequeuing or removing the
wp_enqueue_scriptscallback was sufficient to preventglobal-styles-inline-css. With footer-based generation + hoisting, those calls became ineffective, breaking existing classic theme setups that intentionally disable global styles.Test plan
npm run test:php -- --filter test_wp_hoist_late_printed_styles(15/15 passing)src/wp-includes/script-loader.phpandtests/phpunit/tests/template.phpglobal-styles-inline-cssappears by defaultwp_dequeue_style( 'global-styles' )onwp_enqueue_scriptsremoves itremove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' )removes itTrac ticket: https://core.trac.wordpress.org/ticket/65336