From 335ecfdca9a3407ec21039436fedd7235227254d Mon Sep 17 00:00:00 2001 From: davidbaumwald Date: Tue, 4 Oct 2022 15:50:12 +0000 Subject: [PATCH] Editor: Invalidate blocks metadata cache when needed in `WP_Theme_JSON::get_blocks_metadata()`. This change ensures that user-supplied global styles settings for blocks aren't lost due to sanitization. This could previously occur due to outdated blocks metadata that did not include all registered blocks. Props jorgefilipecosta, andrewserong, oandregal, talldanwp, cbravobernal, bernhard-reiter, hellofromTonya. Fixes #56644. Built from https://develop.svn.wordpress.org/trunk@54385 git-svn-id: http://core.svn.wordpress.org/trunk@53944 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 14 ++++++++------ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index ae214b361a..1774c5ef6f 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -33,9 +33,10 @@ class WP_Theme_JSON { * process it twice. * * @since 5.8.0 + * @since 6.1.0 Initialize as an empty array. * @var array */ - protected static $blocks_metadata = null; + protected static $blocks_metadata = array(); /** * The CSS selector for the top-level styles. @@ -721,14 +722,15 @@ class WP_Theme_JSON { * @return array Block metadata. */ protected static function get_blocks_metadata() { - if ( null !== static::$blocks_metadata ) { + $registry = WP_Block_Type_Registry::get_instance(); + $blocks = $registry->get_all_registered(); + + // Is there metadata for all currently registered blocks? + $blocks = array_diff_key( $blocks, static::$blocks_metadata ); + if ( empty( $blocks ) ) { return static::$blocks_metadata; } - static::$blocks_metadata = array(); - - $registry = WP_Block_Type_Registry::get_instance(); - $blocks = $registry->get_all_registered(); foreach ( $blocks as $block_name => $block_type ) { if ( isset( $block_type->supports['__experimentalSelector'] ) && diff --git a/wp-includes/version.php b/wp-includes/version.php index bd6f9321f5..e70eb4af95 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta2-54384'; +$wp_version = '6.1-beta2-54385'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.