render_block_core_post_content()WP 5.8.0

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

Хуки из функции

Возвращает

Строку. Returns the filtered post content of the current post.

Использование

render_block_core_post_content( $attributes, $content, $block );
$attributes(массив) (обязательный)
Block attributes.
$content(строка) (обязательный)
Block default content.
$block(WP_Block) (обязательный)
Block instance.

Список изменений

С версии 5.8.0 Введена.

Код render_block_core_post_content() WP 7.0.4

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

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

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

	$tag_name = 'div';

	if ( isset( $attributes['tagName'] ) && is_string( $attributes['tagName'] ) ) {
		/**
		 * The allowed tag names match the options offered in the editor.
		 *
		 * @see packages/block-library/src/post-content/edit.js
		 */
		$allowed_tag_names   = array( 'div', 'main', 'section', 'article' );
		$normalized_tag_name = strtolower( $attributes['tagName'] );

		if ( in_array( $normalized_tag_name, $allowed_tag_names, true ) ) {
			$tag_name = $normalized_tag_name;
		}
	}

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

	return sprintf(
		'<%1$s %2$s>%3$s</%1$s>',
		$tag_name,
		$wrapper_attributes,
		$content
	);
}