wp/wp-includes/blocks/block.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    11  * @param array $attributes The block attributes.
    11  * @param array $attributes The block attributes.
    12  *
    12  *
    13  * @return string Rendered HTML of the referenced block.
    13  * @return string Rendered HTML of the referenced block.
    14  */
    14  */
    15 function render_block_core_block( $attributes ) {
    15 function render_block_core_block( $attributes ) {
       
    16 	static $seen_refs = array();
       
    17 
    16 	if ( empty( $attributes['ref'] ) ) {
    18 	if ( empty( $attributes['ref'] ) ) {
    17 		return '';
    19 		return '';
    18 	}
    20 	}
    19 
    21 
    20 	$reusable_block = get_post( $attributes['ref'] );
    22 	$reusable_block = get_post( $attributes['ref'] );
    21 	if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
    23 	if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
    22 		return '';
    24 		return '';
    23 	}
    25 	}
    24 
    26 
       
    27 	if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
       
    28 		// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
       
    29 		// is set in `wp_debug_mode()`.
       
    30 		$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
       
    31 			defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
       
    32 
       
    33 		return $is_debug ?
       
    34 			// translators: Visible only in the front end, this warning takes the place of a faulty block.
       
    35 			__( '[block rendering halted]' ) :
       
    36 			'';
       
    37 	}
       
    38 
    25 	if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
    39 	if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
    26 		return '';
    40 		return '';
    27 	}
    41 	}
    28 
    42 
    29 	return do_blocks( $reusable_block->post_content );
    43 	$seen_refs[ $attributes['ref'] ] = true;
       
    44 
       
    45 	$result = do_blocks( $reusable_block->post_content );
       
    46 	unset( $seen_refs[ $attributes['ref'] ] );
       
    47 	return $result;
    30 }
    48 }
    31 
    49 
    32 /**
    50 /**
    33  * Registers the `core/block` block.
    51  * Registers the `core/block` block.
    34  */
    52  */