wp/wp-includes/blocks/block.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the `core/block` block on server.
     9  * Renders the `core/block` block on server.
       
    10  *
       
    11  * @since 5.0.0
       
    12  *
       
    13  * @global WP_Embed $wp_embed
    10  *
    14  *
    11  * @param array $attributes The block attributes.
    15  * @param array $attributes The block attributes.
    12  *
    16  *
    13  * @return string Rendered HTML of the referenced block.
    17  * @return string Rendered HTML of the referenced block.
    14  */
    18  */
    25 	}
    29 	}
    26 
    30 
    27 	if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
    31 	if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
    28 		// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
    32 		// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
    29 		// is set in `wp_debug_mode()`.
    33 		// is set in `wp_debug_mode()`.
    30 		$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
    34 		$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY;
    31 			defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
       
    32 
    35 
    33 		return $is_debug ?
    36 		return $is_debug ?
    34 			// translators: Visible only in the front end, this warning takes the place of a faulty block.
    37 			// translators: Visible only in the front end, this warning takes the place of a faulty block.
    35 			__( '[block rendering halted]' ) :
    38 			__( '[block rendering halted]' ) :
    36 			'';
    39 			'';
    45 	// Handle embeds for reusable blocks.
    48 	// Handle embeds for reusable blocks.
    46 	global $wp_embed;
    49 	global $wp_embed;
    47 	$content = $wp_embed->run_shortcode( $reusable_block->post_content );
    50 	$content = $wp_embed->run_shortcode( $reusable_block->post_content );
    48 	$content = $wp_embed->autoembed( $content );
    51 	$content = $wp_embed->autoembed( $content );
    49 
    52 
       
    53 	// Back compat.
       
    54 	// For blocks that have not been migrated in the editor, add some back compat
       
    55 	// so that front-end rendering continues to work.
       
    56 
       
    57 	// This matches the `v2` deprecation. Removes the inner `values` property
       
    58 	// from every item.
       
    59 	if ( isset( $attributes['content'] ) ) {
       
    60 		foreach ( $attributes['content'] as &$content_data ) {
       
    61 			if ( isset( $content_data['values'] ) ) {
       
    62 				$is_assoc_array = is_array( $content_data['values'] ) && ! wp_is_numeric_array( $content_data['values'] );
       
    63 
       
    64 				if ( $is_assoc_array ) {
       
    65 					$content_data = $content_data['values'];
       
    66 				}
       
    67 			}
       
    68 		}
       
    69 	}
       
    70 
       
    71 	// This matches the `v1` deprecation. Rename `overrides` to `content`.
       
    72 	if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
       
    73 		$attributes['content'] = $attributes['overrides'];
       
    74 	}
       
    75 
       
    76 	/**
       
    77 	 * We set the `pattern/overrides` context through the `render_block_context`
       
    78 	 * filter so that it is available when a pattern's inner blocks are
       
    79 	 * rendering via do_blocks given it only receives the inner content.
       
    80 	 */
       
    81 	$has_pattern_overrides = isset( $attributes['content'] ) && null !== get_block_bindings_source( 'core/pattern-overrides' );
       
    82 	if ( $has_pattern_overrides ) {
       
    83 		$filter_block_context = static function ( $context ) use ( $attributes ) {
       
    84 			$context['pattern/overrides'] = $attributes['content'];
       
    85 			return $context;
       
    86 		};
       
    87 		add_filter( 'render_block_context', $filter_block_context, 1 );
       
    88 	}
       
    89 
    50 	$content = do_blocks( $content );
    90 	$content = do_blocks( $content );
    51 	unset( $seen_refs[ $attributes['ref'] ] );
    91 	unset( $seen_refs[ $attributes['ref'] ] );
       
    92 
       
    93 	if ( $has_pattern_overrides ) {
       
    94 		remove_filter( 'render_block_context', $filter_block_context, 1 );
       
    95 	}
       
    96 
    52 	return $content;
    97 	return $content;
    53 }
    98 }
    54 
    99 
    55 /**
   100 /**
    56  * Registers the `core/block` block.
   101  * Registers the `core/block` block.
       
   102  *
       
   103  * @since 5.3.0
    57  */
   104  */
    58 function register_block_core_block() {
   105 function register_block_core_block() {
    59 	register_block_type_from_metadata(
   106 	register_block_type_from_metadata(
    60 		__DIR__ . '/block',
   107 		__DIR__ . '/block',
    61 		array(
   108 		array(