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

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 interactivity directives contained within the HTML content and updates the markup accordingly.

Description

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

Parameters

$htmlstringrequired
The HTML content to process.
$context_stackarrayrequired
The reference to the array used to keep track of contexts during processing.
$namespace_stackarrayrequired
The reference to the array used to manage namespaces during processing.

Return

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

Source


	$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;
	}

	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__,
			__( 'The element can only be read during directive processing.' ),
			'6.7.0'
		);
	}

	return $this->current_element;
}

/**
 * Registers the `@wordpress/interactivity` script modules.
 *
 * @deprecated 6.7.0 Script Modules registration is handled by wp_default_script_modules().
 *
 * @since 6.5.0
 */
public function register_script_modules() {
	_deprecated_function( __METHOD__, '6.7.0', 'wp_default_script_modules' );
}

/**
 * Adds the necessary hooks for the Interactivity API.
 *
 * @since 6.5.0
 */
public function add_hooks() {
	add_filter( 'script_module_data_@wordpress/interactivity', array( $this, 'filter_script_module_interactivity_data' ) );
	add_filter( 'script_module_data_@wordpress/interactivity-router', array( $this, 'filter_script_module_interactivity_router_data' ) );
}

/**
 * Processes the interactivity directives contained within the HTML content
 * and updates the markup accordingly.
 *
 * @since 6.5.0
 *

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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