Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Serializes a block.
- *
- * @param array $block Block object.
- * @return string String representing the block.
- */
- function serialize_block( $block ) {
- if ( ! isset( $block['blockName'] ) ) {
- return false;
- }
- $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']
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement