Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Don't process directives in inner blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Apr 13, 2023
1 parent 1336a98 commit 16faac9
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions wp-directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,28 +234,37 @@ function wp_directives_mark_interactive_blocks( $block_content, $block, $instanc
*/
function wp_directives_inner_blocks( $parsed_block, $source_block, $parent_block ) {
if (
isset( $parent_block ) &&
block_has_support(
$parent_block->block_type,
array(
'interactivity',
'isolated',
)
)
isset( $parent_block )
) {
$parsed_block['isolated'] = true;
if (
block_has_support(
$parent_block->block_type,
array(
'interactivity',
'isolated',
)
)
) {
$parsed_block['isolated'] = true;
}
$parsed_block['inner_block'] = true; // TODO: Limit to interactive blocks.
}
return $parsed_block;
}
add_filter( 'render_block_data', 'wp_directives_inner_blocks', 10, 3 );


/**
* Process directives in block.
*
* @param string $block_content Block content.
* @return string Filtered block content.
*/
function process_directives_in_block( $block_content ) {
function process_directives_in_block( $block_content, $block, $instance ) {
if ( isset( $instance->parsed_block['inner_block'] ) ) {
return $block_content;
}

// TODO: Add some directive/components registration mechanism.
$directives = array(
'data-wp-context' => 'process_wp_context',
Expand All @@ -275,7 +284,7 @@ function process_directives_in_block( $block_content ) {
'render_block',
'process_directives_in_block',
10,
1
3
);

// TODO: check if priority 9 is enough.
Expand Down

0 comments on commit 16faac9

Please sign in to comment.