WP_Interactivity_API::data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )
- Since
- 6.5.0, 7.1.0
- Source
wp-includes/interactivity-api/class-wp-interactivity-api.php:1108
data-wp-bind directive.Description
It updates or removes the bound attributes based on the evaluation of its associated reference.
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 every tracked release (6.7.7 to 7.1.0), 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–13
- 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 154.
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 · 2 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" | 12–13 | ->get_directive_entries() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 154 | 5–13 | 21 | |
| 8.5 | 154 | 5–13 | 21 | |
| 8.4 | 154 | 5–13 | 21 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 160 | 5–13 | 21 | |
| 8.2 | 160 | 5–13 | 21 | |
| 8.1 | 160 | 5–13 | 21 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 163 | 5–13 | 21 |
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
- 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_json_encode()Encodes a variable into JSON, with some confidence checks.
- esc_html()Escaping for HTML blocks.
- WP_Interactivity_API::get_directive_entries()Parse the HTML element and get all the valid directives with the given prefix.
- 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 ): void { if ( 'enter' === $mode ) { $entries = $this->get_directive_entries( $p, 'bind' ); foreach ( $entries as $entry ) { if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) { continue; } // Skip if the suffix is an event handler. if ( str_starts_with( $entry['suffix'], '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( $entry['suffix'], 2 ) ) ), '6.9.2' ); continue; } $result = $this->evaluate( $entry ); /* * An object is resolved to whatever it serializes to. When the reference points to a value stored * in state or context, that is the value the client receives for it when the store is hydrated. * A derived state closure is never serialized, so there the client value comes from the derived * state's client-side implementation instead; the resolution is still applied so that both origins * behave the same. Round-tripping through the JSON encoder rather than calling * JsonSerializable::jsonSerialize() directly keeps this resolution identical to the client's, * including for an object which serializes to another serializable object. When the encoding fails * the object is left in place, to be reported as a usage error below. Note that it rarely does * fail: wp_json_encode() retries through _wp_json_sanity_check(), which rebuilds the object from * its public properties and so ignores jsonSerialize() altogether. An object whose serialized form * JSON cannot represent therefore resolves to whatever that rebuild encodes to, which is what the * client is sent for it as well. * * A throwing JsonSerializable::jsonSerialize() is caught for the same reason the value is checked * at all: a binding must not be able to abort the render. An exception escaping here would leave * `$context_stack` and `$namespace_stack` unrestored for every later `process_directives()` call * on this instance, so the object is treated as one which failed to encode. */ if ( is_object( $result ) ) { try { $encoded = wp_json_encode( $result ); } catch ( Throwable $e ) { $encoded = false; } if ( false !== $encoded ) { $result = json_decode( $encoded ); } } /* * Only a value which can be sent to the client may be stored in an attribute value. Strings and * booleans are passed in as-is, numbers are formatted, and everything else is rejected as a usage * error. * * An object which does not serialize to a scalar is rejected even when it defines `__toString()`, * which PHP would otherwise coerce for the string parameters of the escaping functions. Its string * representation is not what the client evaluates this reference to, whether that is the form * serialized into the store or the return value of a derived state's client-side implementation, * so the two could disagree once the directive is evaluated during hydration. */ if ( null !== $result ) { if ( ! is_scalar( $result ) ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: The attribute name. */ __( 'Attempted to bind a non-scalar value to the "%s" attribute. Ensure the state/context property or the derived state closure resolves to a string, number, or boolean.' ), esc_html( $entry['suffix'] ) ), '7.1.0' ); $result = null; } elseif ( is_int( $result ) || is_float( $result ) ) { /* * A number is formatted by the JSON encoder rather than cast to string, so that theChangelog
Introduced in 6.5.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/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.