Make WordPress Core

Changeset 52262


Ignore:
Timestamp:
11/28/2021 09:10:08 PM (3 years ago)
Author:
audrasjb
Message:

Script Loader: Enqueue block stylesheet only when the corresponding block is used.

Before this change, block stylesheets were enqueued although the corresponding blocks were not used in the current post, even if the should_load_separate_core_block_assets filter was set to true.

Props shimotomoki, devutpol, audrasjb.
Fixes #54457.

File:
1 edited

Legend:

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

    r52189 r52262  
    24602460                    add_filter(
    24612461                        'render_block',
    2462                         function( $html ) use ( $style_properties ) {
    2463                             wp_enqueue_style( $style_properties['style_handle'] );
     2462                        function( $html, $block ) use ( $block_name, $style_properties ) {
     2463                            if ( $block['blockName'] === $block_name ) {
     2464                                wp_enqueue_style( $style_properties['style_handle'] );
     2465                            }
    24642466                            return $html;
    2465                         }
     2467                        },
     2468                        10,
     2469                        2
    24662470                    );
    24672471                } else {
Note: See TracChangeset for help on using the changeset viewer.