| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side rendering of the `core/post-featured-image` block. |
| 4 |
* |
| 5 |
* @package WordPress |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Renders the `core/post-featured-image` 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 featured image for the current post. |
| 15 |
*/ |
| 16 |
function gutenberg_render_block_core_post_featured_image( $attributes, $content, $block ) { |
| 17 |
if ( ! isset( $block->context['postId'] ) ) { |
| 18 |
return ''; |
| 19 |
} |
| 20 |
|
| 21 |
return '<p>' . get_the_post_thumbnail( $block->context['postId'] ) . '</p>'; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Registers the `core/post-featured-image` block on the server. |
| 26 |
*/ |
| 27 |
function gutenberg_register_block_core_post_featured_image() { |
| 28 |
register_block_type_from_metadata( |
| 29 |
__DIR__ . '/post-featured-image', |
| 30 |
array( |
| 31 |
'render_callback' => 'gutenberg_render_block_core_post_featured_image', |
| 32 |
) |
| 33 |
); |
| 34 |
} |
| 35 |
add_action( 'init', 'gutenberg_register_block_core_post_featured_image', 20 ); |
| 36 |
|