wp/wp-includes/blocks/post-content.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the `core/post-content` block on the server.
     9  * Renders the `core/post-content` block on the server.
       
    10  *
       
    11  * @since 5.8.0
    10  *
    12  *
    11  * @param array    $attributes Block attributes.
    13  * @param array    $attributes Block attributes.
    12  * @param string   $content    Block default content.
    14  * @param string   $content    Block default content.
    13  * @param WP_Block $block      Block instance.
    15  * @param WP_Block $block      Block instance.
    14  * @return string Returns the filtered post content of the current post.
    16  * @return string Returns the filtered post content of the current post.
    23 	$post_id = $block->context['postId'];
    25 	$post_id = $block->context['postId'];
    24 
    26 
    25 	if ( isset( $seen_ids[ $post_id ] ) ) {
    27 	if ( isset( $seen_ids[ $post_id ] ) ) {
    26 		// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
    28 		// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
    27 		// is set in `wp_debug_mode()`.
    29 		// is set in `wp_debug_mode()`.
    28 		$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
    30 		$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY;
    29 			defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
       
    30 
    31 
    31 		return $is_debug ?
    32 		return $is_debug ?
    32 			// translators: Visible only in the front end, this warning takes the place of a faulty block.
    33 			// translators: Visible only in the front end, this warning takes the place of a faulty block.
    33 			__( '[block rendering halted]' ) :
    34 			__( '[block rendering halted]' ) :
    34 			'';
    35 			'';
    35 	}
    36 	}
    36 
    37 
    37 	$seen_ids[ $post_id ] = true;
    38 	$seen_ids[ $post_id ] = true;
    38 
       
    39 	// Check is needed for backward compatibility with third-party plugins
       
    40 	// that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
       
    41 	if ( ! in_the_loop() && have_posts() ) {
       
    42 		the_post();
       
    43 	}
       
    44 
    39 
    45 	// When inside the main loop, we want to use queried object
    40 	// When inside the main loop, we want to use queried object
    46 	// so that `the_preview` for the current post can apply.
    41 	// so that `the_preview` for the current post can apply.
    47 	// We force this behavior by omitting the third argument (post ID) from the `get_the_content`.
    42 	// We force this behavior by omitting the third argument (post ID) from the `get_the_content`.
    48 	$content = get_the_content();
    43 	$content = get_the_content();
    68 	);
    63 	);
    69 }
    64 }
    70 
    65 
    71 /**
    66 /**
    72  * Registers the `core/post-content` block on the server.
    67  * Registers the `core/post-content` block on the server.
       
    68  *
       
    69  * @since 5.8.0
    73  */
    70  */
    74 function register_block_core_post_content() {
    71 function register_block_core_post_content() {
    75 	register_block_type_from_metadata(
    72 	register_block_type_from_metadata(
    76 		__DIR__ . '/post-content',
    73 		__DIR__ . '/post-content',
    77 		array(
    74 		array(