WP_Interactivity_API::data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )
- Since
- 6.5.0
- Source
wp-includes/interactivity-api/class-wp-interactivity-api.php:811
data-wp-bind directive.Description
It updates or removes the bound attributes based on the evaluation of its associated reference.
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pWP_Interactivity_API_Directives_Processor- The directives processor instance.
$modestring- Whether the processing is entering or exiting the tag.
Performance profile
How much work a call to WP_Interactivity_API::data_wp_bind_processor() 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
- Light
- Scaling
- Scales with input
- Instructions
- 5–20
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 82.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below WP_Interactivity_API::data_wp_bind_processor()
Further down the call graph this can also reach option, cache, serialize, query 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Interactivity_API::data_wp_bind_processor() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$mode !== "enter" | 5 | none |
$mode === "enter" | 11–12 | ->get_attribute_names_with_prefix() |
$mode === "enter" && !$all_bind_directives && empty($bound_attribute) | 20 | ->get_attribute_names_with_prefix(), ->extract_prefix_and_suffix() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 82 | 5–20 | 13 | |
| 8.5 | 82 | 5–20 | 13 | |
| 8.4 | 82 | 5–20 | 13 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 88 | 5–20 | 13 | |
| 8.2 | 88 | 5–20 | 13 | |
| 8.1 | 88 | 5–20 | 13 | |
| 7.4 | 88 | 5–20 | 13 |
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
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
- WP_Interactivity_API::extract_prefix_and_suffix()Extracts the directive attribute name to separate and return the directive prefix and an optional suffix.
- WP_Interactivity_API::evaluate()Evaluates the reference path passed to a directive based on the current store namespace, state and context.
Source code
private function data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) { if ( 'enter' === $mode ) { $all_bind_directives = $p->get_attribute_names_with_prefix( 'data-wp-bind--' ); foreach ( $all_bind_directives as $attribute_name ) { list( , $bound_attribute ) = $this->extract_prefix_and_suffix( $attribute_name ); if ( empty( $bound_attribute ) ) { return; } // Skip if the bound attribute is an event handler. if ( str_starts_with( $bound_attribute, 'on' ) ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: The directive, e.g. data-wp-on--click. */ __( 'Binding event handler attributes is not supported. Please use "%s" instead.' ), esc_attr( 'data-wp-on--' . substr( $bound_attribute, 2 ) ) ), '6.9.2' ); continue; } $attribute_value = $p->get_attribute( $attribute_name ); $result = $this->evaluate( $attribute_value ); if ( null !== $result && ( false !== $result || ( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] ) ) ) { /* * If the result of the evaluation is a boolean and the attribute is * `aria-` or `data-, convert it to a string "true" or "false". It * follows the exact same logic as Preact because it needs to * replicate what Preact will later do in the client: * https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136 */ if ( is_bool( $result ) && ( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] ) ) { $result = $result ? 'true' : 'false'; } $p->set_attribute( $bound_attribute, $result ); } else { $p->remove_attribute( $bound_attribute ); } } } }Changelog
Introduced in 6.5.0. Unchanged from 6.7.10 through 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.10 tag, from
src/wp-includes/interactivity-api/class-wp-interactivity-api.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.