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(); |