Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. * Serializes a block.
  3. *
  4. * @param array $block Block object.
  5. * @return string String representing the block.
  6. */
  7. function serialize_block( $block ) {
  8. if ( ! isset( $block['blockName'] ) ) {
  9. return false;
  10. }
  11. $name = $block['blockName'];
  12. if ( 0 === strpos( $name, 'core/' ) ) {
  13. $name = substr( $name, strlen( 'core/' ) );
  14. }
  15. if ( empty( $block['attrs'] ) ) {
  16. $opening_tag_suffix = '';
  17. } else {
  18. $opening_tag_suffix = ' ' . json_encode( $block['attrs'] );
  19. }
  20. if ( empty( $block['innerHTML'] ) ) {
  21. return sprintf(
  22. '<!-- wp:%s%s /-->',
  23. $name,
  24. $opening_tag_suffix
  25. );
  26. } else {
  27. return sprintf(
  28. '<!-- wp:%1$s%2$s -->%3$s<!-- /wp:%1$s -->',
  29. $name,
  30. $opening_tag_suffix,
  31. $block['innerHTML']
  32. );
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement