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.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3).
Properties · 7
$directive_processorsarrayprivate 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.
$has_processed_router_regionboolprivate- Flag that indicates whether the
data-wp-router-regiondirective has been found in the HTML and processed. $namespace_stackarray<string>|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 · 27
- 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.
- 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.
- extract_prefix_and_suffix()Extracts the directive attribute name to separate and return the directive prefix and an optional suffix.
- extract_directive_value()Parses and extracts the namespace and reference path from the given directive attribute value.
- 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 */ private static $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(); /** * 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 bool */ private $has_processed_router_region = false; /** * Stack of namespaces defined by `data-wp-interactive` directives, in * the order they are processed. * * This is only available during directive processing, otherwise it is `null`. * * @since 6.6.0 * @var array<string>|null */ private $namespace_stack = null; /** * Stack of contexts defined by `data-wp-context` directives, in * the order they are processed. * * This is only available during directive processing, otherwise it is `null`. * * @since 6.6.0 * @var array<array<mixed>>|nullChangelog
Introduced in 6.5.0. 5 changes between 6.7.10 and 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
6.9.10
Method
add_load_on_client_navigation_attribute_to_script_modules() added.verified against source6.9.10
Method
add_client_navigation_support_to_script_module() added.verified against source6.9.10
Method
parse_directive_name() added.verified against source6.9.10
Method
get_directive_entries() added.verified against source6.9.10
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 6.7.10 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.