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

Fix md5 class messed up with new block key #52557

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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