WP_Interactivity_API::data_wp_text_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array $context_stack, array $namespace_stack )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Processes the data-wp-text directive.


It updates the inner content of the current HTML element based on the evaluation of its associated reference.


The directives processor instance.
Whether the processing is entering or exiting the tag.
The reference to the context stack.
The reference to the store namespace stack.


private function data_wp_text_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack ) {
	if ( 'enter' === $mode ) {
		$attribute_value = $p->get_attribute( 'data-wp-text' );
		$result          = $this->evaluate( $attribute_value, end( $namespace_stack ), end( $context_stack ) );

		 * 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( '' );



User Contributed Notes

You must log in before being able to contribute a note or feedback.