Make WordPress Core


Ignore:
Timestamp:
02/14/2025 06:36:48 PM (4 months ago)
Author:
flixos90
Message:

Editor: Introduce wp_should_load_block_assets_on_demand() with filter 'should_load_block_assets_on_demand'.

This function and filter complement the existing wp_should_load_separate_core_block_assets() with filter 'should_load_separate_core_block_assets', which until now was responsible for two different purposes:

  1. Loading separate stylesheets for Core blocks, instead of a combined wp-block-library stylesheet (as the name indicates).
  2. Loading block scripts and stylesheets on demand only if the blocks are included in the page (not indicated by the name).

The new function and filter handles exclusively the 2nd purpose, making it possible to individually adjust both behaviors. For backward compatibility, the return value of wp_should_load_separate_core_block_assets() is used as the filterable default for wp_should_load_block_assets_on_demand(). Yet, the two filters can now be individually be controlled: For example, a site owner that wants to keep loading the combined wp-block-library stylesheet can now do so without giving up on the ability to load block scripts and stylesheets on demand.

Block themes now opt in by default to both features, similar to how they were already doing before via just the one filter. This way, block themes that opt out of loading separate stylesheets for Core blocks will still benefit from loading block scripts and stylesheets on demand, which in the case of block themes is strongly recommended.

Props fabiankaegy, flixos90, gziolo.
Fixes #61965.

File:
1 edited

Legend:

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

    r59813 r59823  
    43964396
    43974397    add_filter( 'should_load_separate_core_block_assets', '__return_true' );
     4398    add_filter( 'should_load_block_assets_on_demand', '__return_true' );
    43984399
    43994400    /*
Note: See TracChangeset for help on using the changeset viewer.