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 by core. 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

public function print_client_interactivity_data() {
	_deprecated_function( __METHOD__, '6.7.0' );
}

/**
 * Set client-side interactivity-router 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
 *
 * @param array $data Data to filter.
 * @return array Data for the Interactivity Router script module.
 */
public function filter_script_module_interactivity_router_data( array $data ): array {
	if ( ! isset( $data['i18n'] ) ) {
		$data['i18n'] = array();
	}
	$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|null $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 );

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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