diff --git a/src/wp-includes/class-wp-block-type-registry.php b/src/wp-includes/class-wp-block-type-registry.php index 84adecd5d0774..2b9cb46728feb 100644 --- a/src/wp-includes/class-wp-block-type-registry.php +++ b/src/wp-includes/class-wp-block-type-registry.php @@ -96,6 +96,15 @@ public function register( $name, $args = array() ) { $this->registered_block_types[ $name ] = $block_type; + /** + * Fires after a block type is registered with the WP_Block_Type_Registry class. + * + * @since 6.1.0 + * + * @param WP_Block_Type $block_type The registered block type on success. + */ + do_action( 'registered_block_type', $block_type ); + return $block_type; } @@ -126,6 +135,15 @@ public function unregister( $name ) { $unregistered_block_type = $this->registered_block_types[ $name ]; unset( $this->registered_block_types[ $name ] ); + /** + * Fires after a block type is unregistered with the WP_Block_Type_Registry class. + * + * @since 6.1.0 + * + * @param WP_Block_Type $block_type The unregistered block type on success. + */ + do_action( 'unregistered_block_type', $unregistered_block_type ); + return $unregistered_block_type; } diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 4f5627a7904b9..4ba43ecccc14c 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -690,6 +690,15 @@ protected static function append_to_selector( $selector, $to_append, $position = return implode( ',', $new_selectors ); } + /** + * Cleans the cached data so it can be recalculated. + * + * @since 6.1.0 + */ + public static function clean_cached_data() { + static::$blocks_metadata = null; + } + /** * Returns the metadata for each block. * diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 725f5ef3cbce5..13d9a41a3ba9b 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -352,6 +352,7 @@ add_action( 'after_switch_theme', '_wp_sidebars_changed' ); add_action( 'wp_print_styles', 'print_emoji_styles' ); add_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); +add_filter( 'registered_block_type', 'wp_clean_theme_json_cache' ); if ( isset( $_GET['replytocom'] ) ) { add_filter( 'wp_robots', 'wp_robots_no_robots' ); diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 84077a5d2c28b..ffb672a3c6aa5 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -147,6 +147,18 @@ function wp_clean_themes_cache( $clear_update_cache = true ) { } } +/** + * Clears the cache held by WP_Theme_JSON and WP_Theme_JSON_Resolver classes. + * + * Ensures that subsequent calls to either class generate fresh core, theme, user, and block data. + * + * @since 6.1.0 + */ +function wp_clean_theme_json_cache() { + WP_Theme_JSON::clean_cached_data(); + WP_Theme_JSON_Resolver::clean_cached_data(); +} + /** * Whether a child theme is in use. *