WP_HTML_Tag_Processor::get_attribute_names_with_prefix( string $prefix ): array|null

Gets lowercase names of all attributes matching a given prefix in the current tag.

Description

Note that matching is case-insensitive. This is in accordance with the spec:

There must never be two or more attributes on the same start tag whose names are an ASCII case-insensitive match for each other.

  • HTML 5 spec

Example:

$p = new WP_HTML_Tag_Processor( '<div data-ENABLED class="test" DATA-test-id="14">Test</div>' );
$p->next_tag( array( 'class_name' => 'test' ) ) === true;
$p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' );

$p->next_tag() === false;
$p->get_attribute_names_with_prefix( 'data-' ) === null;

See also

Parameters

$prefixstringrequired
Prefix of requested attribute names.

Return

array|null List of attribute names, or null when no tag opener is matched.

Source

 * Return the enqueued value for a given attribute, if one exists.
 *
 * Enqueued updates can take different data types:
 *  - If an update is enqueued and is boolean, the return will be `true`
 *  - If an update is otherwise enqueued, the return will be the string value of that update.
 *  - If an attribute is enqueued to be removed, the return will be `null` to indicate that.
 *  - If no updates are enqueued, the return will be `false` to differentiate from "removed."
 *
 * @since 6.2.0
 *
 * @param string $comparable_name The attribute name in its comparable form.
 * @return string|boolean|null Value of enqueued update if present, otherwise false.
 */
private function get_enqueued_attribute_value( string $comparable_name ) {
	if ( self::STATE_MATCHED_TAG !== $this->parser_state ) {
		return false;
	}

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

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