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