render_block_core_post_content( array $attributes, string $content, WP_Block $block ): string
- Since
- 5.8.0
- Source
wp-includes/blocks/post-content.php:18
core/post-content 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 content of the current post.
Performance profile
How much work a call to render_block_core_post_content() 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
- Scaling
- Constant
- Instructions
- 8–59
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 72.
Third-party callbacks on 'the_content' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()one call below render_block_core_post_content()
Further down the call graph this can also reach option, transient, cache and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_post_content() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–18 | none |
isset($value) && isset($seen_ids[$post_id]) | 19–21 | __() |
isset($value) && !isset($seen_ids[$post_id]) && !has_block() && empty($content) | 31 | get_the_content(), has_block(), apply_filters() |
isset($value) && !isset($seen_ids[$post_id]) && has_block() && empty($content) | 35 | get_the_content(), has_block(), wp_link_pages(), apply_filters() |
isset($value) && !isset($seen_ids[$post_id]) && !has_block() && !empty($content) | 44–47 | get_the_content(), has_block(), apply_filters(), get_block_wrapper_attributes(), sprintf() |
isset($value) && !isset($seen_ids[$post_id]) && has_block() && !empty($content) | 48–51 | get_the_content(), has_block(), wp_link_pages(), apply_filters(), get_block_wrapper_attributes(), sprintf() |
isset($value) && !isset($seen_ids[$post_id]) && !has_block() && !empty($content) && isset($attributes) | 54–55 | get_the_content(), has_block(), apply_filters(), strtolower(), get_block_wrapper_attributes(), sprintf() |
isset($value) && !isset($seen_ids[$post_id]) && has_block() && !empty($content) && isset($attributes) | 58–59 | get_the_content(), has_block(), wp_link_pages(), apply_filters(), strtolower(), get_block_wrapper_attributes(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 72 | 8–59 | 9 | |
| 8.5 | 72 | 8–59 | 9 | |
| 8.4 | 72 | 8–59 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 75 | 8–62 | 9 | |
| 8.2 | 75 | 8–62 | 9 | |
| 8.1 | 75 | 8–62 | 9 | |
| 7.4 | 75 | 8–62 | 9 |
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.
Hooks and filters fired · 1
One hook fires while render_block_core_post_content() runs, in this order:
Uses · 6
- __()Retrieves the translation of $text.
- get_the_content()Retrieves the post content.
- has_block()Determines whether a $post or a string contains a specific block type.
- wp_link_pages()The formatted output of a list of pages.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
Source code
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 );}Changelog
Introduced in 5.8.0. Unchanged from 6.7.7 through 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-content.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.