WP_Interactivity_API::get_context( string $store_namespace = null )

In this article

Returns the latest value on the context stack with the passed namespace.

Description

When the namespace is omitted, it uses the current namespace on the namespace stack during a process_directives call.

Parameters

$store_namespacestringoptional
The unique store namespace identifier.

Default:null

Source

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();
}

Changelog

VersionDescription
6.6.0Introduced.

User Contributed Notes

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