Block Hooks API: Add the block hooks algorithm to Woo templates (#45737)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
e4017f0800
commit
f2d828f49a
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: major
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Adds block hooks algorithm to WooCommerce templates.
|
|
@ -184,6 +184,19 @@ class BlockTemplateUtils {
|
||||||
$template->origin = 'plugin';
|
$template->origin = 'plugin';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run the block hooks algorithm introduced in WP 6.4 on the template content.
|
||||||
|
*/
|
||||||
|
if ( function_exists( 'inject_ignored_hooked_blocks_metadata_attributes' ) ) {
|
||||||
|
$hooked_blocks = get_hooked_blocks();
|
||||||
|
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
|
||||||
|
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $template );
|
||||||
|
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $template );
|
||||||
|
$blocks = parse_blocks( $template->content );
|
||||||
|
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +242,21 @@ class BlockTemplateUtils {
|
||||||
$template->post_types = array(); // Don't appear in any Edit Post template selector dropdown.
|
$template->post_types = array(); // Don't appear in any Edit Post template selector dropdown.
|
||||||
$template->area = self::get_block_template_area( $template->slug, $template_type );
|
$template->area = self::get_block_template_area( $template->slug, $template_type );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run the block hooks algorithm introduced in WP 6.4 on the template content.
|
||||||
|
*/
|
||||||
|
if ( function_exists( 'inject_ignored_hooked_blocks_metadata_attributes' ) ) {
|
||||||
|
$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
|
||||||
|
$after_block_visitor = null;
|
||||||
|
$hooked_blocks = get_hooked_blocks();
|
||||||
|
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
|
||||||
|
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $template );
|
||||||
|
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $template );
|
||||||
|
}
|
||||||
|
$blocks = parse_blocks( $template->content );
|
||||||
|
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
|
||||||
|
}
|
||||||
|
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue