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:
- Loading separate stylesheets for Core blocks, instead of a combined
wp-block-library
stylesheet (as the name indicates).
- 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.