block.php 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Server-side rendering of the `core/block` block.
  4. *
  5. * @package WordPress
  6. */
  7. /**
  8. * Renders the `core/block` block on server.
  9. *
  10. * @param array $attributes The block attributes.
  11. *
  12. * @return string Rendered HTML of the referenced block.
  13. */
  14. function render_block_core_block( $attributes ) {
  15. if ( empty( $attributes['ref'] ) ) {
  16. return '';
  17. }
  18. $reusable_block = get_post( $attributes['ref'] );
  19. if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
  20. return '';
  21. }
  22. if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
  23. return '';
  24. }
  25. return do_blocks( $reusable_block->post_content );
  26. }
  27. /**
  28. * Registers the `core/block` block.
  29. */
  30. function register_block_core_block() {
  31. register_block_type(
  32. 'core/block',
  33. array(
  34. 'attributes' => array(
  35. 'ref' => array(
  36. 'type' => 'number',
  37. ),
  38. ),
  39. 'render_callback' => 'render_block_core_block',
  40. )
  41. );
  42. }
  43. add_action( 'init', 'register_block_core_block' );