Skip to content

Instantly share code, notes, and snippets.

@phpbits
Last active June 2, 2023 15:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
<?php
/**
* Render Custom Block
*
* @param array $atts Block Attributes
* @param string $content Block Content (InnerBlocks)
* @param WP_Block $block_class Block Class Instance
* @return string Block Markup
*/
function render( $atts, $content, $block_class ) {
// Check how many inner blocks are available
$item_count = $block_class->inner_blocks->count();
if ( $item_count < 1 ) {
return '';
}
ob_start();
?>
<div>
<?php
// iterate over the available inner blocks
for ( $index = 1; $index <= $item_count; $index++ ) :
// Get the inner block data
$inner_block = $block_class->inner_blocks->current();
// Holds the inner block attribute
$attribute = $inner_block->attributes;
// This will display the attributes data
var_dump( $attribute );
// increase the index in the WP_Block_List class used to retrieve the current block
$block_class->inner_blocks->next();
endfor;
// reset the index in the WP_Block_List class to the initial state
$block_class->inner_blocks->rewind();
?>
</div>
<?php
return ob_get_clean();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment