WP_Interactivity_API::data_wp_bind_processor
Processes the data-wp-bind directive.
It updates or removes the bound attributes based on the evaluation of its associated reference.
Метод класса: WP_Interactivity_API{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->data_wp_bind_processor( $p, $mode );
- $p(WP_Interactivity_API_Directives_Processor) (обязательный)
- The directives processor instance.
- $mode(строка) (обязательный)
- Whether the processing is entering or exiting the tag.
Список изменений
| С версии 6.5.0 | Введена. |
Код WP_Interactivity_API::data_wp_bind_processor() WP Interactivity API::data wp bind processor WP 6.9
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'] );
}
}
}
}