Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP_Theme_JSON: Invalidate blocks metadata cache when needed #3359

14 changes: 8 additions & 6 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class WP_Theme_JSON {
* process it twice.
*
* @since 5.8.0
* @since 6.1.0 Initialize as empty array.
ockham marked this conversation as resolved.
Show resolved Hide resolved
* @var array
*/
protected static $blocks_metadata = null;
protected static $blocks_metadata = array();

/**
* The CSS selector for the top-level styles.
Expand Down Expand Up @@ -729,14 +730,15 @@ protected static function append_to_selector( $selector, $to_append, $position =
* @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();

// Do we have metadata for all currently registered blocks?
ockham marked this conversation as resolved.
Show resolved Hide resolved
$blocks = array_diff_key( $blocks, static::$blocks_metadata );
if ( count( $blocks ) === 0 ) {
ockham marked this conversation as resolved.
Show resolved Hide resolved
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'] ) &&
Expand Down