WP_Interactivity_API
- Since
- 6.5.0
- Source
wp-includes/interactivity-api/class-wp-interactivity-api.php:15
Class used to process the Interactivity API on the server.
Compatibility
- WordPress
- since 6.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 9
$directive_processorsarray<string,private static- Holds the mapping of directive attribute names to their processor methods.
$state_dataarrayprivate- Holds the initial state of the different Interactivity API stores.
$config_dataarrayprivate- Holds the configuration required by the different Interactivity API stores.
$derived_state_closuresarrayprivate- Keeps track of all derived state closures accessed during server-side rendering.
$has_processed_router_regionboolprivate- Flag that indicates whether the
data-wp-router-regiondirective has been found in the HTML and processed. $namespace_stackarray<string|false>|nullprivate- Stack of namespaces defined by
data-wp-interactivedirectives, in the order they are processed. $context_stackarray<array<mixed>>|nullprivate- Stack of contexts defined by
data-wp-contextdirectives, in the order they are processed. $current_elementarray{attributes:private- Representation in array format of the element currently being processed.
Methods · 30
- state()Gets and/or sets the initial state of an Interactivity API store for a given namespace.
- config()Gets and/or sets the configuration of the Interactivity API for a given store namespace.
- print_client_interactivity_data()Prints the serialized client-side interactivity data.
- filter_script_module_interactivity_router_data()Set client-side interactivity-router data.
- filter_script_module_interactivity_data()Set client-side interactivity data.
- get_context()Returns the latest value on the context stack with the passed namespace.
- get_element()Returns an array representation of the current element being processed.
- register_script_modules()Registers the `@wordpress/interactivity` script modules.
- add_hooks()Adds the necessary hooks for the Interactivity API.
- add_load_on_client_navigation_attribute_to_script_modules()Adds the `data-wp-router-options` attribute to script modules that support client-side navigation.
- add_client_navigation_support_to_script_module()Marks a script module as compatible with client-side navigation.
- process_directives()Processes the interactivity directives contained within the HTML content and updates the markup accordingly.
- _process_directives()Processes the interactivity directives contained within the HTML content and updates the markup accordingly.
- evaluate()Evaluates the reference path passed to a directive based on the current store namespace, state and context.
- parse_directive_name()Parse the directive name to extract the following parts: - Prefix: The main directive name without "data-wp-". It cannot begin with a hyphen.
- extract_directive_value()Parses and extracts the namespace and reference path from the given directive attribute value.
- get_directive_entries()Parse the HTML element and get all the valid directives with the given prefix.
- kebab_to_camel_case()Transforms a kebab-case string to camelCase.
- data_wp_interactive_processor()Processes the `data-wp-interactive` directive.
- data_wp_context_processor()Processes the `data-wp-context` directive.
- data_wp_bind_processor()Processes the `data-wp-bind` directive.
- data_wp_class_processor()Processes the `data-wp-class` directive.
- data_wp_style_processor()Processes the `data-wp-style` directive.
- merge_style_property()Merges an individual style property in the `style` attribute of an HTML element, updating or removing the property when necessary.
- data_wp_text_processor()Processes the `data-wp-text` directive.
- get_router_animation_styles()Returns the CSS styles for animating the top loading bar in the router.
- print_router_loading_and_screen_reader_markup()Deprecated.
- print_router_markup()Outputs markup for the @wordpress/interactivity-router script module.
- data_wp_router_region_processor()Processes the `data-wp-router-region` directive.
- data_wp_each_processor()Processes the `data-wp-each` directive.
Source code
final class WP_Interactivity_API { /** * Holds the mapping of directive attribute names to their processor methods. * * @since 6.5.0 * @var array<string, string> * @phpstan-var array{ * 'data-wp-interactive': 'data_wp_interactive_processor', * 'data-wp-router-region': 'data_wp_router_region_processor', * 'data-wp-context': 'data_wp_context_processor', * 'data-wp-bind': 'data_wp_bind_processor', * 'data-wp-class': 'data_wp_class_processor', * 'data-wp-style': 'data_wp_style_processor', * 'data-wp-text': 'data_wp_text_processor', * 'data-wp-each': 'data_wp_each_processor', * } */ private static array $directive_processors = array( 'data-wp-interactive' => 'data_wp_interactive_processor', 'data-wp-router-region' => 'data_wp_router_region_processor', 'data-wp-context' => 'data_wp_context_processor', 'data-wp-bind' => 'data_wp_bind_processor', 'data-wp-class' => 'data_wp_class_processor', 'data-wp-style' => 'data_wp_style_processor', 'data-wp-text' => 'data_wp_text_processor', /* * `data-wp-each` needs to be processed in the last place because it moves * the cursor to the end of the processed items to prevent them to be * processed twice. */ 'data-wp-each' => 'data_wp_each_processor', ); /** * Holds the initial state of the different Interactivity API stores. * * This state is used during the server directive processing. Then, it is * serialized and sent to the client as part of the interactivity data to be * recovered during the hydration of the client interactivity stores. * * @since 6.5.0 * @var array */ private $state_data = array(); /** * Holds the configuration required by the different Interactivity API stores. * * This configuration is serialized and sent to the client as part of the * interactivity data and can be accessed by the client interactivity stores. * * @since 6.5.0 * @var array */ private $config_data = array(); /** * Keeps track of all derived state closures accessed during server-side rendering. * * This data is serialized and sent to the client as part of the interactivity * data, and is handled later in the client to support derived state props that * are lazily hydrated. * * @since 6.9.0 * @var array */ private $derived_state_closures = array(); /** * Flag that indicates whether the `data-wp-router-region` directive has * been found in the HTML and processed. * * The value is saved in a private property of the WP_Interactivity_API * instance instead of using a static variable inside the processor * function, which would hold the same value for all instances * independently of whether they have processed any * `data-wp-router-region` directive or not. * * @since 6.5.0 * @var boolChangelog
Introduced in 6.5.0. 5 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.9.7
Method
add_load_on_client_navigation_attribute_to_script_modules() added.verified against source6.9.7
Method
add_client_navigation_support_to_script_module() added.verified against source6.9.7
Method
parse_directive_name() added.verified against source6.9.7
Method
get_directive_entries() added.verified against source6.9.7
Method
extract_prefix_and_suffix() removed.verified against source6.5.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/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. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.