WP_Interactivity_API::data_wp_context_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )

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.

Source

private function data_wp_context_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) {
	// When exiting tags, it removes the last context from the stack.
	if ( 'exit' === $mode ) {
		array_pop( $this->context_stack );
		return;
	}

	$entries = $this->get_directive_entries( $p, 'context' );
	$context = end( $this->context_stack ) !== false ? end( $this->context_stack ) : array();
	foreach ( $entries as $entry ) {
		if ( null !== $entry['suffix'] ) {
			continue;
		}

		$context = array_replace_recursive(
			$context,
			array( $entry['namespace'] => is_array( $entry['value'] ) ? $entry['value'] : array() )
		);
	}
	$this->context_stack[] = $context;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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