Title: WP_Interactivity_API::get_context
Published: February 24, 2026

---

# WP_Interactivity_API::get_context( string $store_namespace = null )

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#wp--skip-link--target)

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

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#description)󠁿

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#parameters)󠁿

 `$store_namespace`stringoptional

The unique store namespace identifier.

Default:`null`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/interactivity-api/class-wp-interactivity-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/interactivity-api/class-wp-interactivity-api.php#L316)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/interactivity-api/class-wp-interactivity-api.php#L316-L344)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#related)󠁿

| Uses | Description | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_interactivity_api/get_context/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_interactivity_api%2Fget_context%2F)
before being able to contribute a note or feedback.