WP_Interactivity_API::state( string $store_namespace, array $state = array() ): array

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

Description

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

Parameters

$store_namespacestringrequired
The unique store namespace identifier.
$statearrayoptional
The array that will be merged with the existing state for the specified store namespace.

Default:array()

Return

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

Source

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 ],
			$state
		);
	}
	return $this->state_data[ $store_namespace ];
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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