Automattic\WooCommerce\Blocks\BlockTypes
FeaturedItem::extract_featured_item_inner_block_names
Extract the inner block names for the Featured Item block. This way it's possible to map all the inner blocks for a Featured Item block and manipulate the data as needed.
Method of the class: FeaturedItem{}
No Hooks.
Returns
Array. Array containing all the inner block names of a Featured Item block.
Usage
// protected - for code of main (parent) or child class $result = $this->extract_featured_item_inner_block_names( $block, $result );
- $block(array) (required)
- The Featured Item block or its inner blocks.
- $result(array) (passed by reference — &)
- Array of inner block names.
Default:[]
FeaturedItem::extract_featured_item_inner_block_names() FeaturedItem::extract featured item inner block names code WC 10.8.1
protected function extract_featured_item_inner_block_names( $block, &$result = [] ) {
if ( isset( $block['blockName'] ) ) {
$result[] = $block['blockName'];
}
if ( 'woocommerce/product-template' === $block['blockName'] || 'core/post-template' === $block['blockName'] ) {
return $result;
}
if ( isset( $block['innerBlocks'] ) ) {
foreach ( $block['innerBlocks'] as $inner_block ) {
$this->extract_featured_item_inner_block_names( $inner_block, $result );
}
}
return $result;
}