[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/interactivity-api/ -> class-wp-interactivity-api.php (summary)

Interactivity API: WP_Interactivity_API class.

File Size: 2041 lines (76 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 35 functions

  state()
  config()
  print_client_interactivity_data()
  filter_script_module_interactivity_router_data()
  filter_script_module_interactivity_data()
  get_context()
  get_element()
  register_script_modules()
  add_hooks()
  add_load_on_client_navigation_attribute_to_script_modules()
  add_client_navigation_support_to_script_module()
  process_directives()
  _process_directives()
  evaluate()
  parse_directive_name()
  extract_directive_value()
  get_directive_entries()
  kebab_to_camel_case()
  data_wp_interactive_processor()
  data_wp_context_processor()
  data_wp_bind_processor()
  is_bindable_object_attribute()
  data_wp_class_processor()
  data_wp_style_processor()
  merge_style_property()
  data_wp_text_processor()
  data_wp_html_processor()
  get_client_directives()
  resolve_html_reference()
  is_reserved_word()
  get_router_animation_styles()
  print_router_loading_and_screen_reader_markup()
  print_router_markup()
  data_wp_router_region_processor()
  data_wp_each_processor()

Functions
Functions that are not part of a class:

state( ?string $store_namespace = null, ?array $state = null )   X-Ref
Gets and/or sets the initial state of an Interactivity API store for a
given namespace.

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

When no namespace is specified, it returns the state defined for the
current value in the internal namespace stack during a `process_directives` call.

param: string|null $store_namespace Optional. The unique store namespace identifier.
param: array|null  $state           Optional. The array that will be merged with the existing state for the specified
return: array The current state for the specified store namespace. This will be the updated state if a $state

config( string $store_namespace, array $config = array()   X-Ref
Gets and/or sets the configuration of the Interactivity API for a given
store namespace.

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

param: string $store_namespace The unique store namespace identifier.
param: array  $config          Optional. The array that will be merged with the existing configuration for the
return: array The configuration for the specified store namespace. This will be the updated configuration if a

print_client_interactivity_data()   X-Ref
Prints the serialized client-side interactivity data.

Encodes the config and initial state into JSON and prints them inside a
script tag of type "application/json". Once in the browser, the state will
be parsed and used to hydrate the client-side interactivity stores and the
configuration will be available using a `getConfig` utility.


filter_script_module_interactivity_router_data( array $data )   X-Ref
Set client-side interactivity-router data.

Once in the browser, the state will be parsed and used to hydrate the client-side
interactivity stores and the configuration will be available using a `getConfig` utility.

param: array $data Data to filter.
return: array Data for the Interactivity Router script module.

filter_script_module_interactivity_data( array $data )   X-Ref
Set client-side interactivity data.

Once in the browser, the state will be parsed and used to hydrate the client-side
interactivity stores and the configuration will be available using a `getConfig` utility.

param: array $data Data to filter.
return: array Data for the Interactivity API script module.

get_context( ?string $store_namespace = null )   X-Ref
Returns the latest value on the context stack with the passed namespace.

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

param: string|null $store_namespace Optional. The unique store namespace identifier.

get_element()   X-Ref
Returns an array representation of the current element being processed.

The returned array contains a copy of the element attributes.

return: array{attributes: array<string, string|bool>}|null Current element.

register_script_modules()   X-Ref
Registers the `@wordpress/interactivity` script modules.


add_hooks()   X-Ref
Adds the necessary hooks for the Interactivity API.


add_load_on_client_navigation_attribute_to_script_modules( $attributes )   X-Ref
Adds the `data-wp-router-options` attribute to script modules that
support client-side navigation.

This method filters the script attributes to include loading instructions
for the Interactivity API router, indicating which modules can be loaded
during client-side navigation.

param: array<string, string|true>|mixed $attributes The script tag attributes.
return: array The modified script tag attributes.

add_client_navigation_support_to_script_module( string $script_module_id )   X-Ref
Marks a script module as compatible with client-side navigation.

This method registers a script module to be loaded during client-side
navigation in the Interactivity API router. Script modules marked with
this method will have the `loadOnClientNavigation` option enabled in the
`data-wp-router-options` directive.

param: string $script_module_id The script module identifier.

process_directives( string $html )   X-Ref
Processes the interactivity directives contained within the HTML content
and updates the markup accordingly.

param: string $html The HTML content to process.
return: string The processed HTML content. It returns the original content when the HTML contains unbalanced tags.

_process_directives( string $html )   X-Ref
Processes the interactivity directives contained within the HTML content
and updates the markup accordingly.

It uses the WP_Interactivity_API instance's context and namespace stacks,
which every call made during one `process_directives()` call shares.

This method returns null if the HTML contains unbalanced tags.

param: string $html The HTML content to process.
return: string|null The processed HTML content. It returns null when the HTML contains unbalanced tags.

evaluate( $entry )   X-Ref
Evaluates the reference path passed to a directive based on the current
store namespace, state and context.

param: array $entry An array containing a whole directive entry with its namespace, value, suffix, or unique ID.
return: mixed|null The result of the evaluation. Null if the reference path doesn't exist or the namespace is falsy.

parse_directive_name( string $directive_name )   X-Ref
Parse the directive name to extract the following parts:
- Prefix: The main directive name without "data-wp-". It cannot begin with a hyphen.
- Suffix: An optional suffix used during directive processing, extracted after the first double hyphen "--".
- Unique ID: An optional unique identifier, extracted after the first triple hyphen "---".

This function has an equivalent version for the client side.
See `parseDirectiveName` in https://github.com/WordPress/gutenberg/blob/trunk/packages/interactivity/src/vdom.ts:

An empty suffix or unique ID is normalized to null, but the string "0" is preserved. The
client's `|| null` discards only the empty string, since every non-empty string is truthy in
JavaScript. Do not use empty() for these checks: it would discard "0" and diverge from the
client.

param: string $directive_name The directive attribute name.
return: array|null An array containing the directive prefix, optional suffix, and optional unique ID, or null if the directive name cannot be parsed.

extract_directive_value( $directive_value, $default_namespace = null )   X-Ref
Parses and extracts the namespace and reference path from the given
directive attribute value.

If the value doesn't contain an explicit namespace, it returns the
default one. If the value contains a JSON object instead of a reference
path, the function tries to parse it and return the resulting array. If
the value contains strings that represent booleans ("true" and "false"),
numbers ("1" and "1.2") or "null", the function also transform them to
regular booleans, numbers and `null`.

Example:

extract_directive_value( 'actions.foo', 'myPlugin' )                      => array( 'myPlugin', 'actions.foo' )
extract_directive_value( 'otherPlugin::actions.foo', 'myPlugin' )         => array( 'otherPlugin', 'actions.foo' )
extract_directive_value( '{ "isOpen": false }', 'myPlugin' )              => array( 'myPlugin', array( 'isOpen' => false ) )
extract_directive_value( 'otherPlugin::{ "isOpen": false }', 'myPlugin' ) => array( 'otherPlugin', array( 'isOpen' => false ) )

param: string|true $directive_value   The directive attribute value. It can be `true` when it's a boolean
param: string|null $default_namespace Optional. The default namespace if none is explicitly defined.
return: array An array containing the namespace in the first item and the JSON, the reference path, or null on the

get_directive_entries( WP_Interactivity_API_Directives_Processor $p, string $prefix )   X-Ref
Parse the HTML element and get all the valid directives with the given prefix.

param: WP_Interactivity_API_Directives_Processor $p      The directives processor instance.
param: string                                    $prefix The directive prefix to filter by.
return: array An array of entries containing the directive namespace, value, suffix, unique ID, and attribute name.

kebab_to_camel_case( string $str )   X-Ref
No description

data_wp_interactive_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
No description

data_wp_context_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-context` directive.

It adds the context defined in the directive value to the stack so that
it's available for the nested interactivity elements.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.

data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-bind` directive.

It updates or removes the bound attributes based on the evaluation of its
associated reference.

param: WP_Interactivity_API_Directives_Processor $p    The directives processor instance.
param: string                                    $mode Whether the processing is entering or exiting the tag.

is_bindable_object_attribute( string $attribute_name )   X-Ref
Determines whether a binding may set or remove an attribute of an `object` element.

KSES only allows an `object` element in post content after checking the values of its
`data` and `type` attributes. Neither the server nor the client can repeat that check for
a bound value, so a binding on an `object` element may only change attributes that cannot
change what it loads: `aria-*` attributes, `data-*` attributes other than directives,
`width`, `height`, and the global attributes KSES allows on any element. Any `aria-*`
attribute is allowed, where KSES lists only some. A `data-wp-*` attribute is refused
because it is a directive, which could bind `data` or `type` once rendered. The client
runtime enforces the same set.

param: string $attribute_name The name of the bound attribute.
return: bool Whether the attribute may be bound on an `object` element.

data_wp_class_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-class` directive.

It adds or removes CSS classes in the current HTML element based on the
evaluation of its associated references.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.

data_wp_style_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-style` directive.

It updates the style attribute value of the current HTML element based on
the evaluation of its associated references.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.

merge_style_property( string $style_attribute_value, string $style_property_name, $style_property_value )   X-Ref
Merges an individual style property in the `style` attribute of an HTML
element, updating or removing the property when necessary.

If a property is modified, the old one is removed and the new one is added
at the end of the list.

param: string            $style_attribute_value The current style attribute value.
param: string            $style_property_name   The style property name to set.
param: string|false|null $style_property_value  The value to set for the style property. With false, null or an
return: string The new style attribute value after the specified property has been added, updated or removed.

data_wp_text_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-text` directive.

It updates the inner content of the current HTML element based on the
evaluation of its associated reference.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.

data_wp_html_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-html` directive.

Only an entry without a suffix or a unique ID controls the content: the
HTML of the token its reference resolves to, written as given, or nothing
for any other value. No directive inside that content is processed. See
{@see wp_interactivity_as_dangerous_html()} for the risks of marking HTML
as trusted.

HTML that closes the element, or that the browser moves out of it, such
as a `div` in a `p`, is still written as given. The browser places the part
that escapes after the element, where the client hydrates it as ordinary
markup although the server did not process its directives.

A value other than a token or `null` raises a notice. A reference that
resolves to nothing does not.

The element is processed as if it had no `data-wp-html` directive when it
also carries `data-wp-text`, `data-wp-each` or `data-wp-router-region`, which
raises a notice, or when its entries all have a suffix or unique ID or are
dropped by the client. The directive is also ignored, with a notice, on void
elements and on `script`, `style`, `textarea`, `title`, `iframe`, `xmp`,
`noembed` and `noframes` elements. Their content is preserved and the
reference is not evaluated.

param: WP_Interactivity_API_Directives_Processor $p    The directives processor instance.
param: string                                    $mode Whether the processing is entering or exiting the tag.

get_client_directives( WP_Interactivity_API_Directives_Processor $p )   X-Ref
Gets the directives on the current element that the client keeps.

The client drops a directive when a reserved word (`__proto__`,
`constructor` or `prototype`) is its prefix, any `--`-separated part of its
suffix or its unique ID, ignoring case and leading and trailing dashes, or
when its value names a reserved word as its namespace.

param: WP_Interactivity_API_Directives_Processor $p The directives processor instance.
return: array[] The directives by prefix, such as `html`, each in the order of the element's attributes,

resolve_html_reference( $reference )   X-Ref
Resolves the reference of a `data-wp-html` directive as the client does.

The reference is the raw attribute value, never decoded as JSON: an
optional `<namespace>::`, an optional `!` and a dot-separated path.
Without `<namespace>::`, the namespace is the one that the nearest
`data-wp-interactive` directive names, never one inherited from a further
one. When it names none, the reference resolves to `null`. It also
resolves to `null`, without being evaluated, when its path is empty or
starts with a second `!`, which names no property, or when a segment of
its path is a reserved word (`__proto__`, `constructor` or `prototype`).
The `!` applies after that, so `!state.x.constructor` resolves to `true`.

param: string|true $reference The attribute value. It is `true` when the attribute has no value.
return: mixed The value the reference resolves to, or `null` if it resolves to nothing.

is_reserved_word( string $name )   X-Ref
Checks whether a name is one the client never resolves or keeps as a
directive name part, because it would reach the prototype of an object.

param: string $name The name.
return: bool Whether the name is `__proto__`, `constructor` or `prototype`.

get_router_animation_styles()   X-Ref
Returns the CSS styles for animating the top loading bar in the router.

return: string The CSS styles for the router's top loading bar animation.

print_router_loading_and_screen_reader_markup()   X-Ref
Deprecated.


print_router_markup()   X-Ref
Outputs markup for the @wordpress/interactivity-router script module.

This method prints a div element representing a loading bar visible during
navigation.


data_wp_router_region_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-router-region` directive.

It renders in the footer a set of HTML elements to notify users about
client-side navigations. More concretely, the elements added are 1) a
top loading bar to visually inform that a navigation is in progress
and 2) an `aria-live` region for accessible navigation announcements.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.

data_wp_each_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$tag_stack )   X-Ref
Processes the `data-wp-each` directive.

This directive gets an array passed as reference and iterates over it
generating new content for each item based on the inner markup of the
`template` tag.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $tag_stack       The reference to the tag stack.



Generated : Thu Nov 12 08:20:02 2026 Cross-referenced by PHPXref