WP_Interactivity_API::evaluate( string|true $directive_value, string $default_namespace, array|false $context = false ): mixed|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 in other core functions. It is listed here for completeness.

Evaluates the reference path passed to a directive based on the current store namespace, state and context.


The directive attribute value string or true when it’s a boolean attribute.
The default namespace to use if none is explicitly defined in the directive value.
The current context for evaluating the directive or false if there is no context.



mixed|null The result of the evaluation. Null if the reference path doesn’t exist.


private function evaluate( $directive_value, string $default_namespace, $context = false ) {
	list( $ns, $path ) = $this->extract_directive_value( $directive_value, $default_namespace );
	if ( empty( $path ) ) {
		return null;

	$store = array(
		'state'   => $this->state_data[ $ns ] ?? array(),
		'context' => $context[ $ns ] ?? array(),

	// Checks if the reference path is preceded by a negation operator (!).
	$should_negate_value = '!' === $path[0];
	$path                = $should_negate_value ? substr( $path, 1 ) : $path;

	// Extracts the value from the store using the reference path.
	$path_segments = explode( '.', $path );
	$current       = $store;
	foreach ( $path_segments as $path_segment ) {
		if ( isset( $current[ $path_segment ] ) ) {
			$current = $current[ $path_segment ];
		} else {
			return null;

	// Returns the opposite if it contains a negation operator (!).
	return $should_negate_value ? ! $current : $current;



User Contributed Notes

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