Skip to content

Instantly share code, notes, and snippets.

@davidfcarr
Last active March 21, 2023 12:51
Show Gist options
  • Save davidfcarr/6e0a750f58c903b054323fd3ac0c8373 to your computer and use it in GitHub Desktop.
Save davidfcarr/6e0a750f58c903b054323fd3ac0c8373 to your computer and use it in GitHub Desktop.
<?php
function rsvpBlockDataOutput($block, $post_id) {
if(empty($block))
return;
$attrs = ($block->attrs) ? json_encode($block->attrs) : '';
if(!empty($block->innerHTML) || (!empty($block->innerBlocks) && sizeof($block->innerBlocks)) ) {
$output = sprintf('<!-- wp:%s %s -->',$block->blockName,$attrs)."\n";
if(!empty($block->innerHTML))
$output .= $block->innerHTML."\n";
if(!empty($block->innerBlocks) && is_array($block->innerBlocks) && sizeof($block->innerBlocks)) {
foreach($block->innerBlocks as $innerblock) {
$output .= jsonBlockDataOutput($innerblock,$post_id);
}
}
$output .= sprintf('<!-- /wp:%s -->',$block->blockName)."\n\n";
}
else
$output = sprintf('<!-- wp:%s %s /-->',$block->blockName,$attrs)."\n\n";
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment