Skip to content

Commit

Permalink
Use the filter in the new function for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Debarghya-Banerjee committed Oct 3, 2024
1 parent fddf09c commit a956a0d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,18 @@ function wp_should_load_block_assets_on_demand() {
return false;
}

/**
* Backward compatibility for the deprecated `should_load_separate_core_block_assets` filter.
*
* This filter is documented in wp-includes/deprecated.php
*/
$should_load = apply_filters_deprecated(
'should_load_separate_core_block_assets',
array( false ),
'6.8.0',
'wp_should_load_block_assets_on_demand'
);

/**
* Filters whether block assets should be loaded on demand.
*
Expand All @@ -2617,7 +2629,7 @@ function wp_should_load_block_assets_on_demand() {
* Default false (all block assets are loaded,
* even when not used).
*/
return apply_filters( 'wp_should_load_block_assets_on_demand', false );
return apply_filters( 'wp_should_load_block_assets_on_demand', $should_load );
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ public function test_register_block_style_handle_uses_correct_core_stylesheet( $
$metadata['editorStyle'] = "wp-block-{$block_name}-editor";
}

$this->expectDeprecated();

// Ensure block assets are separately registered.
add_filter( 'should_load_separate_core_block_assets', '__return_true' );

Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function test_wp_should_load_separate_core_block_assets_false( $name, $sc
* @param array $schema The block's schema.
*/
public function test_wp_should_load_separate_core_block_assets_true( $name, $schema ) {
$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
register_core_block_style_handles();

Expand Down Expand Up @@ -113,6 +114,7 @@ public function test_wp_should_load_separate_core_block_assets_true( $name, $sch
* @param string $name The block name.
*/
public function test_wp_should_load_separate_core_block_assets_current_theme_supports( $name ) {
$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
add_theme_support( 'wp-block-styles' );
register_core_block_style_handles();
Expand Down Expand Up @@ -145,6 +147,8 @@ public function test_register_core_block_style_handles_should_load_rtl_styleshee
$orig_text_dir = $wp_locale->text_direction;
$wp_locale->text_direction = 'rtl';

$this->expectDeprecated();

add_filter( 'should_load_separate_core_block_assets', '__return_true' );
register_core_block_style_handles();

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/dependencies/styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ public function test_block_styles_for_viewing_with_theme_support() {
* @covers ::wp_default_styles
*/
public function test_block_styles_for_viewing_without_split_styles() {
$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_false' );
wp_default_styles( $GLOBALS['wp_styles'] );

Expand All @@ -509,6 +510,7 @@ public function test_block_styles_for_viewing_without_split_styles() {
* @covers ::wp_default_styles
*/
public function test_block_styles_for_viewing_with_split_styles() {
$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
wp_default_styles( $GLOBALS['wp_styles'] );

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ public function data_block_theme_has_default_support() {
public function test_block_theme_should_load_separate_core_block_assets_by_default() {
$this->helper_requires_block_theme();

$this->expectDeprecated();

add_filter( 'should_load_separate_core_block_assets', '__return_false' );

$this->assertFalse(
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function test_third_party_blocks_inline_styles_get_registered_to_global_s
*/
public function test_third_party_blocks_inline_styles_get_registered_to_global_styles_when_per_block() {
$this->set_up_third_party_block();

$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_true' );

wp_register_style( 'global-styles', false, array(), true, true );
Expand All @@ -106,6 +108,8 @@ public function test_third_party_blocks_inline_styles_get_registered_to_global_s
*/
public function test_third_party_blocks_inline_styles_get_rendered_when_per_block() {
$this->set_up_third_party_block();

$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_true' );

wp_register_style( 'global-styles', false, array(), true, true );
Expand Down Expand Up @@ -156,6 +160,8 @@ public function test_blocks_inline_styles_get_rendered() {
*/
public function test_third_party_blocks_inline_styles_for_elements_get_rendered_when_per_block() {
$this->set_up_third_party_block();

$this->expectDeprecated();
add_filter( 'should_load_separate_core_block_assets', '__return_true' );

wp_register_style( 'global-styles', false, array(), true, true );
Expand Down

0 comments on commit a956a0d

Please sign in to comment.