New filter should_load_block_assets_on_demand in 6.8

WordPress 6.8 introduces a new filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. should_load_block_assets_on_demand, which runs as part of a new function wp_should_load_block_assets_on_demand(). The filter complements the existing should_load_separate_core_block_assets filter by more clearly separating concerns of both filters.

Until now the should_load_separate_core_block_assets filter had two different purposes:

  1. Loading separate stylesheets for CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. blocks, instead of a combined wp-block-library stylesheet (as the name indicates).
  2. Loading blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. scripts and stylesheets on demand only if the blocks are included in the page (not indicated by the name).

Now the new filter (and its surrounding function) handles only the second purpose. To maintain backward compatibility, the existing filter still works for both purposes. But going forward, please use it only for the first purpose.

Having the two separate filters for these purposes lets you control them separately. For example, as a site owner who wants to opt in to loading block scripts and stylesheets on demand, but keep loading the combined wp-block-library stylesheet with your classic theme, now you can:

add_filter( 'should_load_separate_core_block_assets', '__return_false' );
add_filter( 'should_load_block_assets_on_demand', '__return_true' );

Block themes now opt in by default to both features, similar to how they were already doing before via just the one filter.

Refer to TracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. ticketticket Created for both bug reports and feature development on the bug tracker. #61965 for more context.

Props to @jeffpaul, @michelleames, @marybaum, @webcommsat for review and proofreading.

#6-8, #dev-notes, #dev-notes-6-8