Make WordPress Core


Ignore:
Timestamp:
03/12/2026 05:44:22 AM (3 months ago)
Author:
westonruter
Message:

Script Loader: Move wp_load_classic_theme_block_styles_on_demand() from init to wp_default_styles.

This ensures the filters to opt in to loading separate block styles on demand are added at the moment WP_Styles is constructed. This accounts for styles being registered at the init action before register_core_block_style_handles() runs at priority 9. Without this, the wp-block-library stylesheet may get registered with the full combined block styles as style.css instead of just common.css, due to wp_should_load_block_assets_on_demand() still returning false. The wp_default_styles action still runs during init.

Developed in https://github.com/WordPress/wordpress-develop/pull/11232

Follow-up to r61008.

Props westonruter, adamsilverstein.
See #64099.
Fixes #64846.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r61945 r61981  
    36753675 * Adds hooks to load block styles on demand in classic themes.
    36763676 *
     3677 * This function must be called before {@see wp_default_styles()} and {@see register_core_block_style_handles()} so that
     3678 * the filters are added to cause {@see wp_should_load_separate_core_block_assets()} to return true.
     3679 *
    36773680 * @since 6.9.0
     3681 * @since 7.0.0 This is now invoked at the `wp_default_styles` action with priority 0 instead of at `init` with priority 8.
    36783682 *
    36793683 * @see _add_default_theme_supports()
    36803684 */
    3681 function wp_load_classic_theme_block_styles_on_demand() {
     3685function wp_load_classic_theme_block_styles_on_demand(): void {
    36823686    // This is not relevant to block themes, as they are opted in to loading separate styles on demand via _add_default_theme_supports().
    36833687    if ( wp_is_block_theme() ) {
Note: See TracChangeset for help on using the changeset viewer.