WordPress/wp-includes/blocks/block.php
Gary Pendergast 798c2581b1 Blocks: Parse blocks when displaying posts.
Posts containing blocks are now correctly handled when displaying on the front end, including dynamic blocks and nested blocks.

See #45109.


Built from https://develop.svn.wordpress.org/branches/5.0@43752


git-svn-id: http://core.svn.wordpress.org/branches/5.0@43581 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-10-18 11:54:26 +00:00

40 lines
744 B
PHP

<?php
/**
* Server-side rendering of the `core/block` block.
*
* @package gutenberg
*/
/**
* Renders the `core/block` block on server.
*
* @param array $attributes The block attributes.
*
* @return string Rendered HTML of the referenced block.
*/
function render_block_core_block( $attributes ) {
if ( empty( $attributes['ref'] ) ) {
return '';
}
$reusable_block = get_post( $attributes['ref'] );
if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
return '';
}
return do_blocks( $reusable_block->post_content );
}
register_block_type(
'core/block',
array(
'attributes' => array(
'ref' => array(
'type' => 'number',
),
),
'render_callback' => 'render_block_core_block',
)
);