wpseek.com
A WordPress-centric search engine for devs and theme authors



render_block_core_post_content › WordPress Function

Since5.8.0
Deprecatedn/a
render_block_core_post_content ( $attributes, $content, $block )
Parameters: (3)
  • (array) $attributes Block attributes.
    Required: Yes
  • (string) $content Block default content.
    Required: Yes
  • (WP_Block) $block Block instance.
    Required: Yes
Returns:
  • (string) Returns the filtered post content of the current post.
Defined at:
Codex:

Renders the `core/post-content` block on the server.



Source

function render_block_core_post_content( $attributes, $content, $block ) {
	static $seen_ids = array();

	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

	$post_id = $block->context['postId'];

	if ( isset( $seen_ids[ $post_id ] ) ) {
		// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
		// is set in `wp_debug_mode()`.
		$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY;

		return $is_debug ?
			// translators: Visible only in the front end, this warning takes the place of a faulty block.
			__( '[block rendering halted]' ) :
			'';
	}

	$seen_ids[ $post_id ] = true;

	// When inside the main loop, we want to use queried object
	// so that `the_preview` for the current post can apply.
	// We force this behavior by omitting the third argument (post ID) from the `get_the_content`.
	$content = get_the_content();
	// Check for nextpage to display page links for paginated posts.
	if ( has_block( 'core/nextpage' ) ) {
		$content .= wp_link_pages( array( 'echo' => 0 ) );
	}

	$ignored_hooked_blocks = get_post_meta( $post_id, '_wp_ignored_hooked_blocks', true );
	if ( ! empty( $ignored_hooked_blocks ) ) {
		$ignored_hooked_blocks  = json_decode( $ignored_hooked_blocks, true );
		$attributes['metadata'] = array(
			'ignoredHookedBlocks' => $ignored_hooked_blocks,
		);
	}

	// Wrap in Post Content block so the Block Hooks algorithm can insert blocks
	// that are hooked as first or last child of `core/post-content`.
	$content = get_comment_delimited_block_content(
		'core/post-content',
		$attributes,
		$content
	);

	// We need to remove the `core/post-content` block wrapper after the Block Hooks algorithm,
	// but before `do_blocks` runs, as it would otherwise attempt to render the same block again --
	// thus recursing infinitely.
	add_filter( 'the_content', 'remove_serialized_parent_block', 8 );

	/** This filter is documented in wp-includes/post-template.php */
	$content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) );
	unset( $seen_ids[ $post_id ] );

	remove_filter( 'the_content', 'remove_serialized_parent_block', 8 );

	if ( empty( $content ) ) {
		return '';
	}

	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );

	return (
		'<div ' . $wrapper_attributes . '>' .
			$content .
		'</div>'
	);
}