Make WordPress Core


Ignore:
Timestamp:
10/04/2022 03:48:31 PM (2 years ago)
Author:
davidbaumwald
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r54363 r54385  
    3434     *
    3535     * @since 5.8.0
     36     * @since 6.1.0 Initialize as an empty array.
    3637     * @var array
    3738     */
    38     protected static $blocks_metadata = null;
     39    protected static $blocks_metadata = array();
    3940
    4041    /**
     
    722723     */
    723724    protected static function get_blocks_metadata() {
    724         if ( null !== static::$blocks_metadata ) {
    725             return static::$blocks_metadata;
    726         }
    727 
    728         static::$blocks_metadata = array();
    729 
    730725        $registry = WP_Block_Type_Registry::get_instance();
    731726        $blocks   = $registry->get_all_registered();
     727
     728        // Is there metadata for all currently registered blocks?
     729        $blocks = array_diff_key( $blocks, static::$blocks_metadata );
     730        if ( empty( $blocks ) ) {
     731            return static::$blocks_metadata;
     732        }
     733
    732734        foreach ( $blocks as $block_name => $block_type ) {
    733735            if (
Note: See TracChangeset for help on using the changeset viewer.