get_registered( $block['blockName'] ); $is_dynamic = $block['blockName'] && null !== $block_type && $block_type->is_dynamic(); $block_content = ''; $index = 0; foreach ( $block['innerContent'] as $chunk ) { $block_content .= is_string( $chunk ) ? $chunk : render_block( $block['innerBlocks'][ $index++ ] ); } if ( ! is_array( $block['attrs'] ) ) { $block['attrs'] = array(); } if ( $is_dynamic ) { $global_post = $post; $prepared_attributes = $block_type->prepare_attributes_for_render( $block['attrs'] ); $block_content = (string) call_user_func( $block_type->render_callback, $prepared_attributes, $block_content, $block ); $post = $global_post; } /** This filter is documented in src/wp-includes/blocks.php */ return apply_filters( 'render_block', $block_content, $block ); } add_filter( 'pre_render_block', 'gutenberg_provide_render_callback_with_block_object', 10, 2 ); /** * Sets the current post for usage in template blocks. * * @return WP_Post|null The post if any, or null otherwise. */ function gutenberg_get_post_from_context() { // TODO: Without this temporary fix, an infinite loop can occur where // posts with post content blocks render themselves recursively. if ( is_admin() || defined( 'REST_REQUEST' ) ) { return null; } if ( ! in_the_loop() ) { rewind_posts(); the_post(); } return get_post(); }