_block_bindings_term_data_get_value( array $source_args, WP_Block $block_instance ): mixed
- Since
- 6.9.0
- Source
wp-includes/block-bindings/term-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 source arguments used to look up the override value.
Example: array( "field" => "name" ). $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_term_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
- 5–74
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_term().
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 143.
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_term()called directly - hookthird-party callbacks
apply_filters()one call below _block_bindings_term_data_get_value()
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 · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _block_bindings_term_data_get_value() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–31 | none |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) | 31–41 | get_term(), is_wp_error() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() | 41–70 | get_term(), is_wp_error(), get_taxonomy(), current_user_can() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && $taxonomy_object | 42–66 | get_term(), is_wp_error(), get_taxonomy() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && $taxonomy_object | 46–70 | get_term(), is_wp_error(), get_taxonomy(), esc_html() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && $taxonomy_object | 47–66 | get_term(), is_wp_error(), get_taxonomy(), wp_kses_post() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && current_user_can() | 48–74 | get_term(), is_wp_error(), get_taxonomy(), current_user_can(), esc_html() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && current_user_can() | 49–70 | get_term(), is_wp_error(), get_taxonomy(), current_user_can(), wp_kses_post() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && $taxonomy_object | 52–67 | get_term(), is_wp_error(), get_taxonomy(), get_term_link(), is_wp_error() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && current_user_can() | 54–71 | get_term(), is_wp_error(), get_taxonomy(), current_user_can(), get_term_link(), is_wp_error() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && $taxonomy_object | 54–69 | get_term(), is_wp_error(), get_taxonomy(), get_term_link(), is_wp_error(), esc_url() |
!empty($source_args) && !empty($term_id) && !empty($taxonomy) && !is_wp_error() && current_user_can() | 56–73 | get_term(), is_wp_error(), get_taxonomy(), current_user_can(), get_term_link(), is_wp_error(), esc_url() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 142 | 5–74 | 24 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 143 | 5–74 | 24 | |
| 8.4 | 143 | 5–74 | 24 | |
| 8.3 | 143 | 5–74 | 24 | |
| 8.2 | 143 | 5–74 | 24 | 1 more instruction than PHP 8.1 |
| 8.1 | 142 | 5–74 | 24 | |
| 7.4 | 142 | 5–74 | 24 |
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
- get_term()Gets all term data from database by term ID.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- current_user_can()Returns whether the current user has the specified capability.
- esc_html()Escaping for HTML blocks.
- get_term_link()Generates a permalink for a taxonomy term archive.
- esc_url()Checks and cleans a URL.
- wp_kses_post()Sanitizes content for allowed HTML tags for post content.
Source code
function _block_bindings_term_data_get_value( array $source_args, $block_instance ) { if ( empty( $source_args['field'] ) ) { return null; } /* * 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. $term_id = $block_instance->attributes['id'] ?? null; $type = $block_instance->attributes['type'] ?? ''; // Map UI shorthand to taxonomy slug when using attributes. $taxonomy = ( 'tag' === $type ) ? 'post_tag' : $type; } else { // All other blocks: use context $term_id = $block_instance->context['termId'] ?? null; $taxonomy = $block_instance->context['taxonomy'] ?? ''; } // If we don't have required identifiers, bail early. if ( empty( $term_id ) || empty( $taxonomy ) ) { return null; } // Get the term data. $term = get_term( $term_id, $taxonomy ); if ( is_wp_error( $term ) || ! $term ) { return null; } // Check if taxonomy exists and is publicly queryable. $taxonomy_object = get_taxonomy( $taxonomy ); if ( ! $taxonomy_object || ! $taxonomy_object->publicly_queryable ) { if ( ! current_user_can( 'read' ) ) { return null; } } switch ( $source_args['field'] ) { case 'id': return esc_html( (string) $term_id ); case 'name': return esc_html( $term->name ); case 'link': // Only taxonomy entities are supported by Term Data. $term_link = get_term_link( $term ); return is_wp_error( $term_link ) ? null : esc_url( $term_link ); case 'slug': return esc_html( $term->slug ); case 'description': return wp_kses_post( $term->description ); case 'parent': return esc_html( (string) $term->parent ); case 'count': return esc_html( (string) $term->count ); default: return null; }}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/term-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.