Skip to content

Script Loader: Respect global styles opt-out in classic themes with on-demand assets#11961

Open
itzmekhokan wants to merge 2 commits into
WordPress:trunkfrom
itzmekhokan:fix/65336
Open

Script Loader: Respect global styles opt-out in classic themes with on-demand assets#11961
itzmekhokan wants to merge 2 commits into
WordPress:trunkfrom
itzmekhokan:fix/65336

Conversation

@itzmekhokan
Copy link
Copy Markdown

Summary

  • Fixes a regression where global-styles-inline-css could not be removed in classic themes after WordPress 6.9/7.0.
  • Since global styles are now generated in wp_footer and hoisted into <head>, older opt-out patterns (remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ) and wp_dequeue_style( 'global-styles' ) during wp_enqueue_scripts) no longer prevented the inline CSS from appearing.
  • This change detects theme/plugin opt-outs and skips generating/hoisting global styles when requested.

What changed

In wp_enqueue_global_styles() for classic themes with on-demand block assets:

  1. Queue the global-styles handle during wp_enqueue_scripts so it can be dequeued before footer processing.
  2. Run a deferred check at the end of wp_enqueue_scripts to detect dequeue/remove opt-outs.
  3. Skip footer global styles generation when an opt-out is detected.

Why this is a valid bug

Before 6.9/7.0, dequeuing or removing the wp_enqueue_scripts callback was sufficient to prevent global-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)
  • PHPCS on src/wp-includes/script-loader.php and tests/phpunit/tests/template.php
  • On a classic theme (no blocks), confirm global-styles-inline-css appears by default
  • Confirm wp_dequeue_style( 'global-styles' ) on wp_enqueue_scripts removes it
  • Confirm remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ) removes it
  • Confirm block themes and normal global styles loading are unaffected

Trac ticket: https://core.trac.wordpress.org/ticket/65336

…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.
@github-actions
Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props khokansardar.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant