Skip to content

Commit

Permalink
Fix md5 class messed up with new block key (#52557)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz authored and ockham committed Jul 12, 2023
1 parent 62d4264 commit cbec878
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

1 comment on commit cbec878

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in cbec878.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5531372825
📝 Reported issues:

Please sign in to comment.