_wp_apply_block_content_filters( string $content, string $context = '', array|null $seen_ids = null, string|null $id = null ): string
- Since
- 7.1.0
- Source
wp-includes/blocks.php:2650
Description
This function runs the typical content processing filters that WordPress applies to post content, useful for blocks that render nested content.
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$contentstring- The content to process.
$contextstringoptional- Context identifier for wp_filter_content_tags().
Default empty string.Default:'' $seen_idsarray|nulloptional- Reference to an array tracking seen IDs for recursion prevention. Default null.Default:
null $idstring|nulloptional- Unique identifier for this content, used with $seen_ids. Default null.Default:
null
Return value
string- The processed content.
Performance profile
How much work a call to _wp_apply_block_content_filters() 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
- Moderate
- Scaling
- Constant
- Instructions
- 39–43
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 49.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below _wp_apply_block_content_filters() - optionoption read or write
get_option()one call below _wp_apply_block_content_filters()
Further down the call graph this can also reach query, 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 _wp_apply_block_content_filters() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 39–43 | shortcode_unautop(), do_shortcode(), do_blocks(), wptexturize(), convert_smilies(), wp_filter_content_tags(), ->autoembed() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 49 instructions, 39–43 executed per call, 4 branches. The work does not change between versions.
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 · 6
- shortcode_unautop()Don't auto-p wrap shortcodes that stand alone.
- do_shortcode()Searches content for shortcodes and filter shortcodes through their hooks.
- do_blocks()Parses dynamic blocks out of `post_content` and re-renders them.
- wptexturize()Replaces common plain text characters with formatted entities.
- convert_smilies()Converts text equivalent of smilies to images.
- wp_filter_content_tags()Filters specific tags in post content and modifies their markup.
Used by · 2
- render_block_core_latest_posts()Renders the `core/latest-posts` block on server.
- render_block_core_template_part()Renders the `core/template-part` block on the server.
Source code
function _wp_apply_block_content_filters( $content, $context = '', &$seen_ids = null, $id = null ) { $content = shortcode_unautop( $content ); $content = do_shortcode( $content ); if ( null !== $seen_ids && null !== $id ) { $seen_ids[ $id ] = true; } try { $content = do_blocks( $content ); } finally { if ( null !== $seen_ids && null !== $id ) { unset( $seen_ids[ $id ] ); } } $content = wptexturize( $content ); $content = convert_smilies( $content ); $content = wp_filter_content_tags( $content, $context ); global $wp_embed; $content = $wp_embed->autoembed( $content ); return $content;}Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks.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.