CodeExplorer _flatten_blocks example
function _inject_theme_attribute_in_block_template_content( $template_content ) { $has_updated_content = false;
$new_content = '';
$template_blocks =
parse_blocks( $template_content );
$blocks =
_flatten_blocks( $template_blocks );
foreach ( $blocks as &
$block ) { if ( 'core/template-part' ===
$block['blockName'
] &&
!
isset( $block['attrs'
]['theme'
] ) ) { $block['attrs'
]['theme'
] =
get_stylesheet();
$has_updated_content = true;
} } if ( $has_updated_content ) {