WP_Interactivity_API::extract_directive_value( string|true $directive_value, string|null $default_namespace = null ): array

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.

Parses and extracts the namespace and reference path from the given directive attribute value.

Description

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 ) )

Parameters

$directive_valuestring|truerequired
The directive attribute value. It can be true when it’s a boolean attribute.
$default_namespacestring|nulloptional
The default namespace if none is explicitly defined.

Default:null

Return

array An array containing the namespace in the first item and the JSON, the reference path, or null on the second item.

Source


		// Checks if there is a server directive processor registered for each directive.
		foreach ( $p->get_attribute_names_with_prefix( 'data-wp-' ) as $attribute_name ) {
			list( $directive_prefix ) = $this->extract_prefix_and_suffix( $attribute_name );
			if ( array_key_exists( $directive_prefix, self::$directive_processors ) ) {
				$directives_prefixes[] = $directive_prefix;
			}
		}

		/*
		 * If this tag will visit its closer tag, it adds it to the tag stack
		 * so it can process its closing tag and check for unbalanced tags.
		 */
		if ( $p->has_and_visits_its_closer_tag() ) {
			$tag_stack[] = array( $tag_name, $directives_prefixes );
		}
	}
}
/*
 * If the matching opener tag didn't have any directives, it can skip the
 * processing.
 */

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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