[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Interactivity API: WP_Interactivity_API class.
File Size: | 1431 lines (50 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
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. return: array The current state for the specified store namespace. This will be the updated state if a $state param: string $store_namespace Optional. The unique store namespace identifier. param: array $state Optional. The array that will be merged with the existing state for the specified |
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. return: array The configuration for the specified store namespace. This will be the updated configuration if a 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 |
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. return: array Data for the Interactivity Router script module. param: array $data Data to filter. |
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. return: array Data for the Interactivity API script module. param: array $data Data to filter. |
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 $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. return: array The modified script tag attributes. param: array<string, string|true>|mixed $attributes The 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. return: string The processed HTML content. It returns the original content when the HTML contains unbalanced tags. param: string $html The HTML content to process. |
_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 are shared between all calls. This method returns null if the HTML contains unbalanced tags. return: string|null The processed HTML content. It returns null when the HTML contains unbalanced tags. param: string $html The HTML content to process. |
evaluate( $entry ) X-Ref |
Evaluates the reference path passed to a directive based on the current store namespace, state and context. return: mixed|null The result of the evaluation. Null if the reference path doesn't exist or the namespace is falsy. param: array $entry An array containing a whole directive entry with its namespace, value, suffix, or unique ID. |
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-". - 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.: See examples in the function unit tests `test_parse_directive_name`. return: array An array containing the directive prefix, optional suffix, and optional unique ID. param: string $directive_name The directive attribute name. |
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 ) ) return: array An array containing the namespace in the first item and the JSON, the reference path, or null on the 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. |
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. return: array An array of entries containing the directive namespace, value, suffix, and unique ID. param: WP_Interactivity_API_Directives_Processor $p The directives processor instance. param: string $prefix The directive prefix to filter by. |
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. |
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. return: string The new style attribute value after the specified property has been added, updated or removed. 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 |
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. |
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 : Wed Oct 22 08:20:04 2025 | Cross-referenced by PHPXref |