Changeset 48224
- Timestamp:
- 06/30/2020 11:02:22 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r48185 r48224 650 650 * @since 5.0.0 651 651 * 652 * @global WP_Post $post The post to edit. 653 * 654 * @param array $block A single parsed block object. 652 * @global WP_Post $post The post to edit. 653 * @global WP_Query $wp_the_query WordPress Query object. 654 * 655 * @param array $parsed_block A single parsed block object. 655 656 * @return string String of rendered HTML. 656 657 */ 657 function render_block( $ block ) {658 global $post ;658 function render_block( $parsed_block ) { 659 global $post, $wp_query; 659 660 660 661 /** … … 663 664 * @since 5.1.0 664 665 * 665 * @param string|null $pre_render The pre-rendered content. Default null.666 * @param array $ blockThe block being rendered.666 * @param string|null $pre_render The pre-rendered content. Default null. 667 * @param array $parsed_block The block being rendered. 667 668 */ 668 $pre_render = apply_filters( 'pre_render_block', null, $ block );669 $pre_render = apply_filters( 'pre_render_block', null, $parsed_block ); 669 670 if ( ! is_null( $pre_render ) ) { 670 671 return $pre_render; 671 672 } 672 673 673 $source_block = $ block;674 $source_block = $parsed_block; 674 675 675 676 /** … … 678 679 * @since 5.1.0 679 680 * 680 * @param array $ blockThe block being rendered.681 * @param array $source_block An un-modified copy of $ block, as it appeared in the source content.681 * @param array $parsed_block The block being rendered. 682 * @param array $source_block An un-modified copy of $parsed_block, as it appeared in the source content. 682 683 */ 683 $block = apply_filters( 'render_block_data', $block, $source_block ); 684 685 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); 686 $is_dynamic = $block['blockName'] && null !== $block_type && $block_type->is_dynamic(); 687 $block_content = ''; 688 $index = 0; 689 690 foreach ( $block['innerContent'] as $chunk ) { 691 $block_content .= is_string( $chunk ) ? $chunk : render_block( $block['innerBlocks'][ $index++ ] ); 692 } 693 694 if ( ! is_array( $block['attrs'] ) ) { 695 $block['attrs'] = array(); 696 } 697 698 if ( $is_dynamic ) { 699 $global_post = $post; 700 $block_content = $block_type->render( $block['attrs'], $block_content ); 701 $post = $global_post; 684 $parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block ); 685 686 $context = array(); 687 688 if ( ! empty( $post ) ) { 689 $context['postId'] = $post->ID; 690 691 /* 692 * The `postType` context is largely unnecessary server-side, since the 693 * ID is usually sufficient on its own. That being said, since a block's 694 * manifest is expected to be shared between the server and the client, 695 * it should be included to consistently fulfill the expectation. 696 */ 697 $context['postType'] = $post->post_type; 698 } 699 700 if ( isset( $wp_query->tax_query->queried_terms['category'] ) ) { 701 $context['query'] = array( 'categoryIds' => array() ); 702 foreach ( $wp_query->tax_query->queried_terms['category']['terms'] as $category_slug_or_id ) { 703 $context['query']['categoryIds'][] = 'slug' === $wp_query->tax_query->queried_terms['category']['field'] ? get_cat_ID( $category_slug_or_id ) : $category_slug_or_id; 704 } 702 705 } 703 706 704 707 /** 705 * Filters the content of a singleblock.706 * 707 * @since 5. 0.0708 * 709 * @param string $block_content The block content about to be appended.710 * @param array $block The full block, including name and attributes.708 * Filters the default context provided to a rendered block. 709 * 710 * @since 5.5.0 711 * 712 * @param array $context Default context. 713 * @param array $parsed_block Block being rendered, filtered by `render_block_data`. 711 714 */ 712 return apply_filters( 'render_block', $block_content, $block ); 715 $context = apply_filters( 'render_block_context', $context, $parsed_block ); 716 717 $block = new WP_Block( $parsed_block, $context ); 718 719 return $block->render(); 713 720 } 714 721 -
trunk/src/wp-includes/class-wp-block.php
r48159 r48224 227 227 } 228 228 229 /** This filter is documented in src/wp-includes/blocks.php */ 229 /** 230 * Filters the content of a single block. 231 * 232 * @since 5.0.0 233 * 234 * @param string $block_content The block content about to be appended. 235 * @param array $block The full block, including name and attributes. 236 */ 230 237 return apply_filters( 'render_block', $block_content, $this->parsed_block ); 231 238 }
Note: See TracChangeset
for help on using the changeset viewer.