WP_Interactivity_API::data_wp_bind_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-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.
$context_stackarrayrequired
The reference to the context stack.
$namespace_stackarrayrequired
The reference to the store namespace stack.

Source


// Extracts the value from the store using the reference path.
$path_segments = explode( '.', $path );
$current       = $store;
foreach ( $path_segments as $path_segment ) {
	/*
	 * Special case for numeric arrays and strings. Add length
	 * property mimicking JavaScript behavior.
	 *
	 * @since 6.8.0
	 */
	if ( 'length' === $path_segment ) {
		if ( is_array( $current ) && array_is_list( $current ) ) {
			$current = count( $current );
			break;
		}

		if ( is_string( $current ) ) {
			/*
			 * Differences in encoding between PHP strings and
			 * JavaScript mean that it's complicated to calculate
			 * the string length JavaScript would see from PHP.
			 * `strlen` is a reasonable approximation.
			 *
			 * Users that desire a more precise length likely have
			 * more precise needs than "bytelength" and should
			 * implement their own length calculation in derived
			 * state taking into account encoding and their desired
			 * output (codepoints, graphemes, bytes, etc.).
			 */
			$current = strlen( $current );
			break;
		}
	}

	if ( ( is_array( $current ) || $current instanceof ArrayAccess ) && isset( $current[ $path_segment ] ) ) {
		$current = $current[ $path_segment ];
	} elseif ( is_object( $current ) && isset( $current->$path_segment ) ) {
		$current = $current->$path_segment;
	} else {

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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