From 083422e0af92d7b33978c811a477a628baf54d1e Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Wed, 12 Jul 2023 11:00:30 +0200 Subject: [PATCH] Fix md5 class messed up with new block key --- .../class-wp-directive-processor.php | 31 +++++++++++++++++++ .../directive-processing.php | 6 ++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/experimental/interactivity-api/class-wp-directive-processor.php b/lib/experimental/interactivity-api/class-wp-directive-processor.php index 608466a9c6eda..69c72a222fdc7 100644 --- a/lib/experimental/interactivity-api/class-wp-directive-processor.php +++ b/lib/experimental/interactivity-api/class-wp-directive-processor.php @@ -17,6 +17,37 @@ * to improve this code. */ class WP_Directive_Processor extends WP_HTML_Tag_Processor { + + /** + * An array of root blocks. + * + * @var array + */ + static $root_blocks = array(); + + /** + * Add a root block to the list. + * + * @param array $block The block to add. + * + * @return void + */ + public static function add_root_block( $block ) { + self::$root_blocks[] = md5( serialize( $block ) ); + } + + /** + * Check if block is a root block. + * + * @param array $block The block to check. + * + * @return bool True if block is a root block, false otherwise. + */ + public static function is_root_block( $block ) { + return in_array( md5( serialize( $block ) ), self::$root_blocks, true ); + } + + /** * Find the matching closing tag for an opening tag. * diff --git a/lib/experimental/interactivity-api/directive-processing.php b/lib/experimental/interactivity-api/directive-processing.php index 0f2af5da0f804..ce20eac43b3cb 100644 --- a/lib/experimental/interactivity-api/directive-processing.php +++ b/lib/experimental/interactivity-api/directive-processing.php @@ -17,7 +17,7 @@ */ function gutenberg_interactivity_process_directives_in_root_blocks( $block_content, $block ) { // Don't process inner blocks or root blocks that don't contain directives. - if ( isset( $block['is_inner_block'] ) || strpos( $block_content, 'data-wp-' ) === false ) { + if ( ! WP_Directive_Processor::is_root_block( $block ) || strpos( $block_content, 'data-wp-' ) === false ) { return $block_content; } @@ -47,8 +47,8 @@ function gutenberg_interactivity_process_directives_in_root_blocks( $block_conte * @return array The parsed block. */ function gutenberg_interactivity_mark_inner_blocks( $parsed_block, $source_block, $parent_block ) { - if ( isset( $parent_block ) ) { - $parsed_block['is_inner_block'] = true; + if ( ! isset( $parent_block ) ) { + WP_Directive_Processor::add_root_block( $parsed_block ); } return $parsed_block; }