Title: WP_Interactivity_API::process_directives_args
Published: April 3, 2024

---

# WP_Interactivity_API::process_directives_args( string $html, array $context_stack, array $namespace_stack ): string|null

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#wp--skip-link--target)

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

Processes the interactivity directives contained within the HTML content and updates
the markup accordingly.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#description)󠁿

It needs the context and namespace stacks to be passed by reference, and it returns
null if the HTML contains unbalanced tags.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#parameters)󠁿

 `$html`stringrequired

The HTML content to process.

`$context_stack`arrayrequired

The reference to the array used to keep track of contexts during processing.

`$namespace_stack`arrayrequired

The reference to the array used to manage namespaces during processing.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#return)󠁿

 string|null The processed HTML content. It returns null when the HTML contains 
unbalanced tags.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#source)󠁿

    ```php
    	$data['i18n']['loading'] = __( 'Loading page, please wait.' );
    	$data['i18n']['loaded']  = __( 'Page Loaded.' );
    	return $data;
    }

    /**
     * Set client-side interactivity data.
     *
     * Once in the browser, the state will be parsed and used to hydrate the client-side
     * interactivity stores and the configuration will be available using a `getConfig` utility.
     *
     * @since 6.7.0
     * @since 6.9.0 Serializes derived state props accessed during directive processing.
     *
     * @param array $data Data to filter.
     * @return array Data for the Interactivity API script module.
     */
    public function filter_script_module_interactivity_data( array $data ): array {
    	if (
    		empty( $this->state_data ) &&
    		empty( $this->config_data ) &&
    		empty( $this->derived_state_closures )
    	) {
    		return $data;
    	}

    	$config = array();
    	foreach ( $this->config_data as $key => $value ) {
    		if ( ! empty( $value ) ) {
    			$config[ $key ] = $value;
    		}
    	}
    	if ( ! empty( $config ) ) {
    		$data['config'] = $config;
    	}

    	$state = array();
    	foreach ( $this->state_data as $key => $value ) {
    		if ( ! empty( $value ) ) {
    			$state[ $key ] = $value;
    		}
    	}
    	if ( ! empty( $state ) ) {
    		$data['state'] = $state;
    	}

    	$derived_props = array();
    	foreach ( $this->derived_state_closures as $key => $value ) {
    		if ( ! empty( $value ) ) {
    			$derived_props[ $key ] = $value;
    		}
    	}
    	if ( ! empty( $derived_props ) ) {
    		$data['derivedStateClosures'] = $derived_props;
    	}

    	return $data;
    }

    /**
     * Returns the latest value on the context stack with the passed namespace.
     *
     * When the namespace is omitted, it uses the current namespace on the
     * namespace stack during a `process_directives` call.
     *
     * @since 6.6.0
     *
     * @param string $store_namespace Optional. The unique store namespace identifier.
     */
    public function get_context( ?string $store_namespace = null ): array {
    	if ( null === $this->context_stack ) {
    		_doing_it_wrong(
    			__METHOD__,
    			__( 'The context can only be read during directive processing.' ),
    			'6.6.0'
    		);
    		return array();
    	}

    	if ( ! $store_namespace ) {
    		if ( null !== $store_namespace ) {
    			_doing_it_wrong(
    				__METHOD__,
    				__( 'The namespace should be a non-empty string.' ),
    				'6.6.0'
    			);
    			return array();
    		}

    		$store_namespace = end( $this->namespace_stack );
    	}

    	$context = end( $this->context_stack );

    	return ( $store_namespace && $context && isset( $context[ $store_namespace ] ) )
    		? $context[ $store_namespace ]
    		: array();
    }

    /**
     * Returns an array representation of the current element being processed.
     *
     * The returned array contains a copy of the element attributes.
     *
     * @since 6.7.0
     *
     * @return array{attributes: array<string, string|bool>}|null Current element.
     */
    public function get_element(): ?array {
    	if ( null === $this->current_element ) {
    		_doing_it_wrong(
    			__METHOD__,
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/interactivity-api/class-wp-interactivity-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/interactivity-api/class-wp-interactivity-api.php#L247)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/interactivity-api/class-wp-interactivity-api.php#L247-L358)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_interactivity_api/process_directives_args/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_interactivity_api%2Fprocess_directives_args%2F)
before being able to contribute a note or feedback.