render_block()
最后更新于:2021-11-27 21:46:05
render_block( array$parsed_block)Renders a single block into a HTML string.
参数
- $parsed_block
-
(array) (Required) A single parsed block object.
响应
(string) String of rendered HTML.
源文件
文件: gc-includes/blocks.php
function render_block( $parsed_block ) {
global $post;
/**
* Allows render_block() to be short-circuited, by returning a non-null value.
*
* @since 5.1.0
*
* @param string|null $pre_render The pre-rendered content. Default null.
* @param array $parsed_block The block being rendered.
*/
$pre_render = apply_filters( 'pre_render_block', null, $parsed_block );
if ( ! is_null( $pre_render ) ) {
return $pre_render;
}
$source_block = $parsed_block;
/**
* Filters the block being rendered in render_block(), before it's processed.
*
* @since 5.1.0
*
* @param array $parsed_block The block being rendered.
* @param array $source_block An un-modified copy of $parsed_block, as it appeared in the source content.
*/
$parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block );
$context = array();
if ( $post instanceof GC_Post ) {
$context['postId'] = $post->ID;
/*
* The `postType` context is largely unnecessary server-side, since the ID
* is usually sufficient on its own. That being said, since a block's
* manifest is expected to be shared between the server and the client,
* it should be included to consistently fulfill the expectation.
*/
$context['postType'] = $post->post_type;
}
/**
* Filters the default context provided to a rendered block.
*
* @since 5.5.0
*
* @param array $context Default context.
* @param array $parsed_block Block being rendered, filtered by `render_block_data`.
*/
$context = apply_filters( 'render_block_context', $context, $parsed_block );
$block = new GC_Block( $parsed_block, $context );
return $block->render();
}