wp-includes/interactivity-api/class-wp-interactivity-api.php:577Evaluates the reference path passed to a directive based on the current store namespace, state and context.
$directive_valuestring|truemixed|null private function evaluate( $directive_value ) { $default_namespace = end( $this->namespace_stack ); $context = end( $this->context_stack ); list( $ns, $path ) = $this->extract_directive_value( $directive_value, $default_namespace ); if ( ! $ns || ! $path ) { /* translators: %s: The directive value referenced. */ $message = sprintf( __( 'Namespace or reference path cannot be empty. Directive value referenced: %s' ), $directive_value ); _doing_it_wrong( __METHOD__, $message, '6.6.0' ); 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 ) { /* * Special case for numeric arrays and strings. Add length * property mimicking JavaScript behavior. * * @since 6.8.0 */ if ( 'length' === $path_segment ) { if ( is_array( $current ) && array_is_list( $current ) ) { $current = count( $current ); break; } if ( is_string( $current ) ) { /* * Differences in encoding between PHP strings and * JavaScript mean that it's complicated to calculate * the string length JavaScript would see from PHP. * `strlen` is a reasonable approximation. * * Users that desire a more precise length likely have * more precise needs than "bytelength" and should * implement their own length calculation in derived * state taking into account encoding and their desired * output (codepoints, graphemes, bytes, etc.). */ $current = strlen( $current ); break; } } if ( ( is_array( $current ) || $current instanceof ArrayAccess ) && isset( $current[ $path_segment ] ) ) { $current = $current[ $path_segment ]; } elseif ( is_object( $current ) && isset( $current->$path_segment ) ) { $current = $current->$path_segment; } else { $current = null; break; } if ( $current instanceof Closure ) { /* * This state getter's namespace is added to the stack so that * `state()` or `get_config()` read that namespace when called * without specifying one. */ array_push( $this->namespace_stack, $ns ); try { $current = $current(); } catch ( Throwable $e ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: 1: Path pointing to an Interactivity API state property, 2: Namespace for an Interactivity API store. */ __( 'Uncaught error executing a derived state callback with path "%1$s" and namespace "%2$s".' ), $path,Introduced in 6.5.0. 2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$entry added.verified against source$directive_value removed.verified against sourcesrc/wp-includes/interactivity-api/class-wp-interactivity-api.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.