wppaste
WordPress

render_block_core_post_excerpt( array $attributes, string $content, WP_Block $block ): string

Since
5.8.0
Source
wp-includes/blocks/post-excerpt.php:18
Renders the core/post-excerpt block on the server.

Compatibility

WordPress
since 5.8.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$attributesarray
Block attributes.
$contentstring
Block default content.
$blockWP_Block
Block instance.

Return value

string
Returns the filtered post excerpt for the current post wrapped inside "p" tags.

Performance profile

How much work a call to render_block_core_post_excerpt() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
5

Executed per call on PHP 8.5. The body compiles to 118.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below render_block_core_post_excerpt()
  • querycontent queryget_post()one call below render_block_core_post_excerpt()
  • optionoption read or writeget_option()one call below render_block_core_post_excerpt()

Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_post_excerpt() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always5none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11859
8.511859
8.4118593 fewer instructions than PHP 8.3
8.312159
8.212159
8.1121591 fewer instruction than PHP 7.4
7.412259

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 8

Source code

function render_block_core_post_excerpt( $attributes, $content, $block ) {	if ( ! isset( $block->context['postId'] ) ) {		return '';	} 	$more_text           = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';	$filter_excerpt_more = static function ( $more ) use ( $more_text ) {		return empty( $more_text ) ? $more : '';	};	/**	 * Some themes might use `excerpt_more` filter to handle the	 * `more` link displayed after a trimmed excerpt. Since the	 * block has a `more text` attribute we have to check and	 * override if needed the return value from this filter.	 * So if the block's attribute is not empty override the	 * `excerpt_more` filter and return nothing. This will	 * result in showing only one `read more` link at a time.	 *	 * This hook needs to be applied before the excerpt is retrieved with get_the_excerpt.	 * Otherwise, the read more link filter from the theme is not removed.	 */	add_filter( 'excerpt_more', $filter_excerpt_more ); 	/*	 * The purpose of the excerpt length setting is to limit the length of both	 * automatically generated and user-created excerpts.	 * Because the excerpt_length filter only applies to auto generated excerpts,	 * wp_trim_words is used instead.	 *	 * To ensure the block's excerptLength setting works correctly for auto-generated	 * excerpts, we temporarily override excerpt_length to 101 (the max block setting)	 * so that wp_trim_excerpt doesn't pre-trim the content before wp_trim_words can	 * apply the user's desired length.	 */	$excerpt_length = $attributes['excerptLength'];	add_filter( 'excerpt_length', 'block_core_post_excerpt_excerpt_length', PHP_INT_MAX ); 	$excerpt = get_the_excerpt( $block->context['postId'] ); 	remove_filter( 'excerpt_length', 'block_core_post_excerpt_excerpt_length', PHP_INT_MAX ); 	if ( isset( $excerpt_length ) ) {		$excerpt = wp_trim_words( $excerpt, $excerpt_length );	} 	$classes = array();	if ( isset( $attributes['textAlign'] ) ) {		$classes[] = 'has-text-align-' . $attributes['textAlign'];	}	if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {		$classes[] = 'has-link-color';	}	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); 	$content               = '<p class="wp-block-post-excerpt__excerpt">' . $excerpt;	$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];	if ( $show_more_on_new_line && ! empty( $more_text ) ) {		$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';	} else {		$content .= " $more_text</p>";	}	remove_filter( 'excerpt_more', $filter_excerpt_more );	return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );}

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/post-excerpt.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.