Skip to content

Commit

Permalink
Fix md5 class messed up with new block key
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Jul 12, 2023
1 parent d645a09 commit 083422e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/experimental/interactivity-api/directive-processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 083422e

Please sign in to comment.