WP_Interactivity_API::state()publicWP 6.5.0

Gets and/or sets the initial state of an Interactivity API store for a given namespace.

If state for that store namespace already exists, it merges the new provided state with the existing one.

Method of the class: WP_Interactivity_API{}

No Hooks.


Array. The current state for the specified store namespace. This will be the updated state if a $state argument was provided.


$WP_Interactivity_API = new WP_Interactivity_API();
$WP_Interactivity_API->state( $store_namespace, $state ): array;
$store_namespace(string) (required)
The unique store namespace identifier.
The array that will be merged with the existing state for the specified store namespace.
Default: array()


Since 6.5.0 Introduced.

WP_Interactivity_API::state() code WP 6.5.4

public function state( string $store_namespace, array $state = array() ): array {
	if ( ! isset( $this->state_data[ $store_namespace ] ) ) {
		$this->state_data[ $store_namespace ] = array();
	if ( is_array( $state ) ) {
		$this->state_data[ $store_namespace ] = array_replace_recursive(
			$this->state_data[ $store_namespace ],
	return $this->state_data[ $store_namespace ];