WP_Interactivity_API::data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array $context_stack, array $namespace_stack )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Processes the data-wp-bind directive.

Description

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

Parameters

$pWP_Interactivity_API_Directives_Processorrequired
The directives processor instance.
$modestringrequired
Whether the processing is entering or exiting the tag.
$context_stackarrayrequired
The reference to the context stack.
$namespace_stackarrayrequired
The reference to the store namespace stack.

Source

 * The suffix is the string after the first double hyphen and the prefix is
 * everything that comes before the suffix.
 *
 * Example:
 *
 *     extract_prefix_and_suffix( 'data-wp-interactive' )   => array( 'data-wp-interactive', null )
 *     extract_prefix_and_suffix( 'data-wp-bind--src' )     => array( 'data-wp-bind', 'src' )
 *     extract_prefix_and_suffix( 'data-wp-foo--and--bar' ) => array( 'data-wp-foo', 'and--bar' )
 *
 * @since 6.5.0
 *
 * @param string $directive_name The directive attribute name.
 * @return array An array containing the directive prefix and optional suffix.
 */
private function extract_prefix_and_suffix( string $directive_name ): array {
	return explode( '--', $directive_name, 2 );
}

/**
 * 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 ) )
 *
 * @since 6.5.0
 *
 * @param string|true $directive_value   The directive attribute value. It can be `true` when it's a boolean
 *                                       attribute.

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.