Skip to content

Commit 48a310c

Browse files
committed
unregster bug fix
1 parent b08183e commit 48a310c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/wp-includes/class-wp-theme-json.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,14 @@ protected static function get_blocks_metadata() {
10001000
$registry = WP_Block_Type_Registry::get_instance();
10011001
$blocks = $registry->get_all_registered();
10021002

1003+
// Unset old blocks from static variable.
1004+
$blocks_to_unset = array_diff_key( static::$blocks_metadata, $blocks );
1005+
if ( ! empty( $blocks_to_unset ) ) {
1006+
foreach ( $blocks_to_unset as $block_name => $block_meta ) {
1007+
unset( static::$blocks_metadata[ $block_name ] );
1008+
}
1009+
}
1010+
10031011
// Is there metadata for all currently registered blocks?
10041012
$blocks = array_diff_key( $blocks, static::$blocks_metadata );
10051013
if ( empty( $blocks ) ) {

tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Tests_Theme_WpAddGlobalStylesForBlocks extends WP_Theme_UnitTestCase {
2020

2121
public function set_up() {
2222
parent::set_up();
23+
switch_theme( 'default' );
2324
remove_action( 'wp_print_styles', 'print_emoji_styles' );
2425
}
2526

@@ -32,6 +33,7 @@ public function tear_down() {
3233
$this->test_blocks = array();
3334
}
3435

36+
switch_theme( 'default' );
3537
parent::tear_down();
3638
}
3739

@@ -126,6 +128,7 @@ public function test_styles_for_blocks_skips_cache_in_dev_mode() {
126128
* @ticket 59595
127129
*/
128130
public function test_styles_for_blocks_cache_is_skipped() {
131+
switch_theme( 'block-theme' );
129132
wp_register_style( 'global-styles', false, array(), true, true );
130133

131134
// Initial register of global styles.
@@ -136,15 +139,14 @@ public function test_styles_for_blocks_cache_is_skipped() {
136139
$this->assertNotEmpty( $styles_for_blocks_initial, 'Initial cache was not set.' );
137140

138141
$this->set_up_third_party_block();
139-
140142
/*
141143
* Call register of global styles again to ensure the cache is updated.
142144
* In normal conditions, this function is only called once per request.
143145
*/
144146
wp_add_global_styles_for_blocks();
145147

146-
$cache_key = $this->get_wp_styles_for_blocks_cache_key();
147-
$styles_for_blocks_updated = get_site_transient( $cache_key );
148+
$cache_key_new = $this->get_wp_styles_for_blocks_cache_key();
149+
$styles_for_blocks_updated = get_site_transient( $cache_key_new );
148150
$this->assertNotEmpty( $styles_for_blocks_updated, 'Updated cache was not set.' );
149151

150152
$this->assertNotEquals(

0 commit comments

Comments
 (0)