# gutenberg/17.5.0/lib/experimental/interactivity-api/directives/wp-context.php

Gutenberg, version 17.5.0. 31 lines.

- Page: https://pluginprobe.com/plugins/gutenberg/17.5.0/code/lib/experimental/interactivity-api/directives/wp-context.php
- Raw: https://pluginprobe.com/plugins/gutenberg/17.5.0/raw/lib/experimental/interactivity-api/directives/wp-context.php
- Modified: 2024-01-17T12:56:36+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gutenberg/17.5.0/code/lib/experimental/interactivity-api/directives/wp-context.php#L10-L20`.

```php
<?php
/**
 * Process wp-context directive attribute.
 *
 * @package wp-directives
 */

/**
 * Process wp-context directive attribute.
 *
 * @param WP_Directive_Processor $tags Tags.
 * @param WP_Directive_Context   $context Directive context.
 * @param string                 $ns Namespace.
 */
function gutenberg_interactivity_process_wp_context( $tags, $context, $ns ) {
	if ( $tags->is_tag_closer() ) {
		$context->rewind_context();
		return;
	}

	$attr_value = $tags->get_attribute( 'data-wp-context' );

	//Separate namespace and value from the context directive attribute.
	list( $ns, $data ) = is_string( $attr_value ) && ! empty( $attr_value )
		? WP_Directive_Processor::parse_attribute_value( $attr_value, $ns )
		: array( $ns, null );

	// Add parsed data to the context under the corresponding namespace.
	$context->set_context( array( $ns => is_array( $data ) ? $data : array() ) );
}

```
