_block_bindings_post_data_get_value( array $source_args, WP_Block $block_instance ): mixed
- Since
- 6.9.0
- Source
wp-includes/block-bindings/post-data.php:21
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$source_argsarray- Array containing arguments used to look up the source value.
Example: array( "field" => "foo" ). $block_instanceWP_Block- The block instance.
Return value
mixed- The value computed for the source.
Performance profile
How much work a call to _block_bindings_post_data_get_value() 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
- 7–61
- Plugin surface
- None
- 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 93.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()one call below _block_bindings_post_data_get_value() - optionoption read or write
get_option()one call below _block_bindings_post_data_get_value()
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 · 14 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _block_bindings_post_data_get_value() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–23 | none |
!empty($source_args) && !empty($post_id) && is_post_publicly_viewable() | 29–41 | get_post(), is_post_publicly_viewable(), post_password_required() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && !current_user_can() | 30–36 | get_post(), is_post_publicly_viewable(), current_user_can() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && current_user_can() | 34–46 | get_post(), is_post_publicly_viewable(), current_user_can(), post_password_required() |
!empty($source_args) && !empty($post_id) && is_post_publicly_viewable() && !post_password_required() && $field === "date" | 38–44 | get_post(), is_post_publicly_viewable(), post_password_required(), get_the_date(), esc_attr() |
!empty($source_args) && !empty($post_id) && is_post_publicly_viewable() && !post_password_required() && $field !== "date" && $field !== "modified" && $field === "link" && $permalink === false | 41–47 | get_post(), is_post_publicly_viewable(), post_password_required(), get_permalink() |
!empty($source_args) && !empty($post_id) && is_post_publicly_viewable() && !post_password_required() && $field !== "date" && $field === "modified" | 43–49 | get_post(), is_post_publicly_viewable(), post_password_required(), get_the_modified_date(), get_the_date() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && current_user_can() && !post_password_required() && $field === "date" | 43–49 | get_post(), is_post_publicly_viewable(), current_user_can(), post_password_required(), get_the_date(), esc_attr() |
!empty($source_args) && !empty($post_id) && is_post_publicly_viewable() && !post_password_required() && $field !== "date" && $field !== "modified" && $field === "link" && $permalink !== false | 44–50 | get_post(), is_post_publicly_viewable(), post_password_required(), get_permalink(), esc_url() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && current_user_can() && !post_password_required() && $field !== "date" && $field !== "modified" && $field === "link" && $permalink === false | 46–52 | get_post(), is_post_publicly_viewable(), current_user_can(), post_password_required(), get_permalink() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && current_user_can() && !post_password_required() && $field !== "date" && $field === "modified" | 48–54 | get_post(), is_post_publicly_viewable(), current_user_can(), post_password_required(), get_the_modified_date(), get_the_date() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && current_user_can() && !post_password_required() && $field !== "date" && $field !== "modified" && $field === "link" && $permalink !== false | 49–55 | get_post(), is_post_publicly_viewable(), current_user_can(), post_password_required(), get_permalink(), esc_url() |
2 further outcomes, up to 61 instructions
!empty($source_args) && !empty($post_id) && is_post_publicly_viewable() && !post_password_required() && $field !== "date" && $field === "modified" | 50–56 | get_post(), is_post_publicly_viewable(), post_password_required(), get_the_modified_date(), get_the_date(), get_the_modified_date(), esc_attr() |
!empty($source_args) && !empty($post_id) && !is_post_publicly_viewable() && current_user_can() && !post_password_required() && $field !== "date" && $field === "modified" | 55–61 | get_post(), is_post_publicly_viewable(), current_user_can(), post_password_required(), get_the_modified_date(), get_the_date(), get_the_modified_date(), esc_attr() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 93 instructions, 7–61 executed per call, 15 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 · 9
- get_post()Retrieves post data given a post ID or post object.
- is_post_publicly_viewable()Determines whether a post is publicly viewable.
- current_user_can()Returns whether the current user has the specified capability.
- post_password_required()Determines whether the post requires password and whether a correct password has been provided.
- esc_attr()Escaping for HTML attributes.
- get_the_date()Retrieves the date of the post.
- get_the_modified_date()Retrieves the date on which the post was last modified.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- esc_url()Checks and cleans a URL.
Source code
function _block_bindings_post_data_get_value( array $source_args, $block_instance ) { if ( empty( $source_args['field'] ) ) { // Backward compatibility for when the source argument was called `key` in Gutenberg plugin. if ( empty( $source_args['key'] ) ) { return null; } $field = $source_args['key']; } else { $field = $source_args['field']; } /* * BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks. * Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE. */ $block_name = $block_instance->name ?? ''; $is_navigation_block = in_array( $block_name, array( 'core/navigation-link', 'core/navigation-submenu' ), true ); if ( $is_navigation_block ) { // Navigation blocks: read from block attributes. $post_id = $block_instance->attributes['id'] ?? null; } else { // All other blocks: use context. $post_id = $block_instance->context['postId'] ?? null; } // If we don't have an entity ID, bail early. if ( empty( $post_id ) ) { return null; } // If a post isn't public, we need to prevent unauthorized users from accessing the post data. $post = get_post( $post_id ); if ( ( ! is_post_publicly_viewable( $post ) && ! current_user_can( 'read_post', $post_id ) ) || post_password_required( $post ) ) { return null; } if ( 'date' === $field ) { return esc_attr( get_the_date( 'c', $post_id ) ); } if ( 'modified' === $field ) { // Only return the modified date if it is later than the publishing date. if ( get_the_modified_date( 'U', $post_id ) > get_the_date( 'U', $post_id ) ) { return esc_attr( get_the_modified_date( 'c', $post_id ) ); } else { return ''; } } if ( 'link' === $field ) { $permalink = get_permalink( $post_id ); return false === $permalink ? null : esc_url( $permalink ); }}Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/block-bindings/post-data.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.