WP_Interactivity_API::data_wp_context_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-context directive.

Description

It adds the context defined in the directive value to the stack so that it’s available for the nested interactivity elements.

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

	 * not safe to process. In that case, the Interactivity API runtime will
	 * update the HTML on the client side during the hydration. It will also
	 * display a notice to the developer to inform them about the issue.
	 */
	if ( $unbalanced || 0 < count( $tag_stack ) ) {
		$tag_errored = 0 < count( $tag_stack ) ? end( $tag_stack )[0] : $tag_name;
		/* translators: %1s: Namespace processed, %2s: The tag that caused the error; could be any HTML tag.  */
		$message = sprintf( __( 'Interactivity directives failed to process in "%1$s" due to a missing "%2$s" end tag.' ), end( $this->namespace_stack ), $tag_errored );
		_doing_it_wrong( __METHOD__, $message, '6.6.0' );
		return null;
	}

	return $p->get_updated_html();
}

/**
 * Evaluates the reference path passed to a directive based on the current
 * store namespace, state and context.
 *
 * @since 6.5.0
 * @since 6.6.0 The function now adds a warning when the namespace is null, falsy, or the directive value is empty.
 * @since 6.6.0 Removed `default_namespace` and `context` arguments.
 * @since 6.6.0 Add support for derived state.
 *
 * @param string|true $directive_value The directive attribute value string or `true` when it's a boolean attribute.
 * @return mixed|null The result of the evaluation. Null if the reference path doesn't exist or the namespace is falsy.
 */
private function evaluate( $directive_value ) {
	$default_namespace = end( $this->namespace_stack );
	$context           = end( $this->context_stack );

	list( $ns, $path ) = $this->extract_directive_value( $directive_value, $default_namespace );
	if ( ! $ns || ! $path ) {

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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