Changeset 49310
- Timestamp:
- 10/26/2020 08:29:04 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r49226 r49310 649 649 650 650 /** 651 * Block currently being parsed.652 *653 * @type array654 */655 global $current_parsed_block;656 657 $current_parsed_block = array(658 'blockName' => null,659 'attributes' => null,660 );661 662 /**663 651 * Renders a single block into a HTML string. 664 652 * 665 653 * @since 5.0.0 666 654 * 667 * @global array $current_parsed_block Block currently being parsed.668 655 * @global WP_Post $post The post to edit. 669 656 * @global WP_Query $wp_query WordPress Query object. … … 674 661 */ 675 662 function render_block( $parsed_block ) { 676 global $post, $wp_query , $current_parsed_block;663 global $post, $wp_query; 677 664 678 665 /** … … 688 675 return $pre_render; 689 676 } 690 691 $current_parsed_block = $parsed_block;692 677 693 678 $source_block = $parsed_block; -
trunk/src/wp-includes/class-wp-block-supports.php
r49226 r49310 23 23 */ 24 24 private $block_supports = array(); 25 26 /** 27 * Tracks the current block to be rendered. 28 * 29 * @var array 30 */ 31 public static $block_to_render = null; 25 32 26 33 /** … … 73 80 } 74 81 75 76 82 /** 77 83 * Generates an array of HTML attributes, such as classes, by applying to … … 80 86 * @since 5.6.0 81 87 * 82 * @param array $parsed_block Block as parsed from content.83 88 * @return array Array of HTML attributes. 84 89 */ 85 public function apply_block_supports( $parsed_block) {86 $block_attributes = $parsed_block['attrs'];90 public function apply_block_supports() { 91 $block_attributes = self::$block_to_render['attrs']; 87 92 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( 88 $parsed_block['blockName']93 self::$block_to_render['blockName'] 89 94 ); 90 95 … … 156 161 * @since 5.6.0 157 162 * 158 * @global array $current_parsed_block Block currently being parsed.159 *160 163 * @param array $extra_attributes Optional. Extra attributes to render on the block wrapper. 161 164 * … … 163 166 */ 164 167 function get_block_wrapper_attributes( $extra_attributes = array() ) { 165 global $current_parsed_block; 166 $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block ); 168 $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports(); 167 169 168 170 if ( empty( $new_attributes ) && empty( $extra_attributes ) ) { … … 209 211 return implode( ' ', $normalized_attributes ); 210 212 } 211 -
trunk/src/wp-includes/class-wp-block.php
r49226 r49310 193 193 */ 194 194 public function render( $options = array() ) { 195 global $post , $current_parsed_block;195 global $post; 196 196 $options = wp_parse_args( 197 197 $options, … … 207 207 $index = 0; 208 208 foreach ( $this->inner_content as $chunk ) { 209 if ( is_string( $chunk ) ) { 210 $block_content .= $chunk; 211 } else { 212 $parent_parsed_block = $current_parsed_block; 213 $current_parsed_block = $this->inner_blocks[ $index ]->parsed_block; 214 $block_content .= $this->inner_blocks[ $index++ ]->render(); 215 $current_parsed_block = $parent_parsed_block; 216 } 209 $block_content .= is_string( $chunk ) ? 210 $chunk : 211 $this->inner_blocks[ $index++ ]->render(); 217 212 } 218 213 } … … 220 215 if ( $is_dynamic ) { 221 216 $global_post = $post; 217 $parent = WP_Block_Supports::$block_to_render; 218 WP_Block_Supports::$block_to_render = $this->parsed_block; 222 219 $block_content = (string) call_user_func( $this->block_type->render_callback, $this->attributes, $block_content, $this ); 220 WP_Block_Supports::$block_to_render = $parent; 223 221 $post = $global_post; 224 222 } -
trunk/tests/phpunit/includes/testcase-block-supports.php
r49226 r49310 97 97 * 98 98 * @param array $block Block to render. 99 * 100 * @return string Rendered output for the current block. 99 101 */ 100 102 private function render_example_block( $block ) { 101 global $current_parsed_block;102 $current_parsed_block= $block;103 $wrapper_attributes = get_block_wrapper_attributes(103 WP_Block_Supports::init(); 104 WP_Block_Supports::$block_to_render = $block; 105 $wrapper_attributes = get_block_wrapper_attributes( 104 106 array( 105 107 'class' => 'foo-bar-class',
Note: See TracChangeset
for help on using the changeset viewer.