Skip to content

Commit

Permalink
Add end point
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 3, 2019
1 parent 6c278e6 commit 6f67d60
Show file tree
Hide file tree
Showing 4 changed files with 440 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,51 @@ function gutenberg_reregister_core_block_types() {
}
}
add_action( 'init', 'gutenberg_reregister_core_block_types' );

/**
* Serializes an array of blocks.
*
* @since 5.7.0
*
* @param array $blocks Post Array of block objects.
* @return string String representing the blocks.
*/
function serialize_blocks( $blocks ) {
return implode( array_map( 'serialize_block', $blocks ) );
}

/**
* Serializes a block.
*
* @since 5.7.0
*
* @param array $block Block object.
* @return string String representing the block.
*/
function serialize_block( $block ) {
$name = $block['blockName'];
if ( 0 === strpos( $name, 'core/' ) ) {
$name = substr( $name, strlen( 'core/' ) );
}

if ( empty( $block['attrs'] ) ) {
$opening_tag_suffix = '';
} else {
$opening_tag_suffix = ' ' . json_encode( $block['attrs'] );
}

if ( empty( $block['innerHTML'] ) ) {
return sprintf(
'<!-- wp:%s%s /-->',
$name,
$opening_tag_suffix
);
} else {
return sprintf(
'<!-- wp:%1$s%2$s -->%3$s<!-- /wp:%1$s -->',
$name,
$opening_tag_suffix,
$block['innerHTML']
);
}
}
Loading

0 comments on commit 6f67d60

Please sign in to comment.