| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side rendering of the `core/post-content` block. |
| 4 |
* |
| 5 |
* @package WordPress |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Renders the `core/post-content` block on the server. |
| 10 |
* |
| 11 |
* @param array $attributes Block attributes. |
| 12 |
* @param string $content Block default content. |
| 13 |
* @param WP_Block $block Block instance. |
| 14 |
* @return string Returns the filtered post content of the current post. |
| 15 |
*/ |
| 16 |
function gutenberg_render_block_core_post_content( $attributes, $content, $block ) { |
| 17 |
if ( ! isset( $block->context['postId'] ) ) { |
| 18 |
return ''; |
| 19 |
} |
| 20 |
|
| 21 |
if ( ! in_the_loop() ) { |
| 22 |
the_post(); |
| 23 |
} |
| 24 |
|
| 25 |
$content = get_the_content( null, false, $block->context['postId'] ); |
| 26 |
|
| 27 |
if ( empty( $content ) ) { |
| 28 |
return ''; |
| 29 |
} |
| 30 |
|
| 31 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) ); |
| 32 |
|
| 33 |
return ( |
| 34 |
'<div ' . $wrapper_attributes . '>' . |
| 35 |
apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) ) . |
| 36 |
'</div>' |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Registers the `core/post-content` block on the server. |
| 42 |
*/ |
| 43 |
function gutenberg_register_block_core_post_content() { |
| 44 |
register_block_type_from_metadata( |
| 45 |
__DIR__ . '/post-content', |
| 46 |
array( |
| 47 |
'render_callback' => 'gutenberg_render_block_core_post_content', |
| 48 |
) |
| 49 |
); |
| 50 |
} |
| 51 |
add_action( 'init', 'gutenberg_register_block_core_post_content', 20 ); |
| 52 |
|