Processes the data-wp-bind directive.
Description
It updates or removes the bound attributes based on the evaluation of its associated reference.
Parameters
$pWP_Interactivity_API_Directives_Processorrequired- The directives processor instance.
$modestringrequired- Whether the processing is entering or exiting the tag.
Source
private function data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) {
if ( 'enter' === $mode ) {
$entries = $this->get_directive_entries( $p, 'bind' );
foreach ( $entries as $entry ) {
if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) {
return;
}
$result = $this->evaluate( $entry );
if (
null !== $result &&
(
false !== $result ||
( strlen( $entry['suffix'] ) > 5 && '-' === $entry['suffix'][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( $entry['suffix'] ) > 5 && '-' === $entry['suffix'][4] )
) {
$result = $result ? 'true' : 'false';
}
$p->set_attribute( $entry['suffix'], $result );
} else {
$p->remove_attribute( $entry['suffix'] );
}
}
}
}
Changelog
| Version | Description |
|---|---|
| 6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.