[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/post-content` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/post-content` block on the server. 10 * 11 * @param array $attributes Block attributes. 12 * @param string $content Block default content. 13 * @param WP_Block $block Block instance. 14 * @return string Returns the filtered post content of the current post. 15 */ 16 function render_block_core_post_content( $attributes, $content, $block ) { 17 static $seen_ids = array(); 18 19 if ( ! isset( $block->context['postId'] ) ) { 20 return ''; 21 } 22 23 $post_id = $block->context['postId']; 24 25 if ( isset( $seen_ids[ $post_id ] ) ) { 26 // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent 27 // is set in `wp_debug_mode()`. 28 $is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; 29 30 return $is_debug ? 31 // translators: Visible only in the front end, this warning takes the place of a faulty block. 32 __( '[block rendering halted]' ) : 33 ''; 34 } 35 36 $seen_ids[ $post_id ] = true; 37 38 // When inside the main loop, we want to use queried object 39 // so that `the_preview` for the current post can apply. 40 // We force this behavior by omitting the third argument (post ID) from the `get_the_content`. 41 $content = get_the_content(); 42 // Check for nextpage to display page links for paginated posts. 43 if ( has_block( 'core/nextpage' ) ) { 44 $content .= wp_link_pages( array( 'echo' => 0 ) ); 45 } 46 47 /** This filter is documented in wp-includes/post-template.php */ 48 $content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) ); 49 unset( $seen_ids[ $post_id ] ); 50 51 if ( empty( $content ) ) { 52 return ''; 53 } 54 55 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) ); 56 57 return ( 58 '<div ' . $wrapper_attributes . '>' . 59 $content . 60 '</div>' 61 ); 62 } 63 64 /** 65 * Registers the `core/post-content` block on the server. 66 */ 67 function register_block_core_post_content() { 68 register_block_type_from_metadata( 69 __DIR__ . '/post-content', 70 array( 71 'render_callback' => 'render_block_core_post_content', 72 ) 73 ); 74 } 75 add_action( 'init', 'register_block_core_post_content' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Wed May 1 08:20:02 2024 | Cross-referenced by PHPXref |