Processes the data-wp-text directive.
Description
It updates the inner content of the current HTML element 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_text_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) {
if ( 'enter' === $mode ) {
$entries = $this->get_directive_entries( $p, 'text' );
$valid_entry = null;
// Get the first valid `data-wp-text` entry without suffix or unique ID.
foreach ( $entries as $entry ) {
if ( null === $entry['suffix'] && null === $entry['unique_id'] && ! empty( $entry['value'] ) ) {
$valid_entry = $entry;
break;
}
}
if ( null === $valid_entry ) {
return;
}
$result = $this->evaluate( $valid_entry );
/*
* Follows the same logic as Preact in the client and only changes the
* content if the value is a string or a number. Otherwise, it removes the
* content.
*/
if ( is_string( $result ) || is_numeric( $result ) ) {
$p->set_content_between_balanced_tags( esc_html( $result ) );
} else {
$p->set_content_between_balanced_tags( '' );
}
}
}
Changelog
| Version | Description |
|---|---|
| 6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.