wp_get_post_content_block_attributes(): array|null
- Since
- 6.3.0, 6.4.0
- Source
wp-includes/block-editor.php:430
Compatibility
- WordPress
- since 6.4.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.
Return value
array|null- Post Content block attributes array or null if Post Content block doesn't exist.
Performance profile
How much work a call to wp_get_post_content_block_attributes() 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
- Scales with input
- Instructions
- 6–52
- Plugin surface
- None
- Called by
- 1
Reaches the database via get_post().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 64.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()one call below wp_get_post_content_block_attributes() - hookthird-party callbacks
apply_filters()one call below wp_get_post_content_block_attributes()
Further down the call graph this can also reach option, 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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_post_content_block_attributes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–7 | wp_is_block_theme() |
empty($current_template) | 20 | wp_is_block_theme(), get_page_template_slug(), slug__in() |
empty($current_template) | 33–37 | wp_is_block_theme(), get_page_template_slug(), get_block_templates(), get_post_type(), slug__in() |
!empty($current_template) | 34–35 | wp_is_block_theme(), get_page_template_slug(), slug__in(), parse_blocks(), wp_get_first_block() |
!empty($current_template) | 47–52 | wp_is_block_theme(), get_page_template_slug(), get_block_templates(), get_post_type(), slug__in(), parse_blocks(), wp_get_first_block() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 64 instructions, 6–52 executed per call, 11 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
- wp_is_block_theme()Returns whether the active theme is a block-based theme or not.
- get_page_template_slug()Gets the specific template filename for a given post.
- get_block_templates()Retrieves a list of unified template objects based on a query.
- get_post_type()Retrieves the post type of the current post or of a given post.
- parse_blocks()Parses blocks out of a content string.
- wp_get_first_block()Finds the first occurrence of a specific block in an array of blocks.
Used by · 1
- get_block_editor_settings()Returns the contextualized block editor settings for a selected editor context.
Source code
function wp_get_post_content_block_attributes() { global $post_ID; $is_block_theme = wp_is_block_theme(); if ( ! $is_block_theme || ! $post_ID ) { return null; } $template_slug = get_page_template_slug( $post_ID ); if ( ! $template_slug ) { $post_slug = 'singular'; $page_slug = 'singular'; $template_types = get_block_templates(); foreach ( $template_types as $template_type ) { if ( 'page' === $template_type->slug ) { $page_slug = 'page'; } if ( 'single' === $template_type->slug ) { $post_slug = 'single'; } } $what_post_type = get_post_type( $post_ID ); switch ( $what_post_type ) { case 'page': $template_slug = $page_slug; break; default: $template_slug = $post_slug; break; } } $current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) ); if ( ! empty( $current_template ) ) { $template_blocks = parse_blocks( $current_template[0]->content ); $post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' ); if ( isset( $post_content_block['attrs'] ) ) { return $post_content_block['attrs']; } } return null;}Changelog
Introduced in 6.3.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/block-editor.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.