Skip to content

Instantly share code, notes, and snippets.

@phpbits
Last active June 2, 2023 15:21
Show Gist options
  • Save phpbits/f4dcab50f46d570b4c13a38af4be5f23 to your computer and use it in GitHub Desktop.
Save phpbits/f4dcab50f46d570b4c13a38af4be5f23 to your computer and use it in GitHub Desktop.
<?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