WP_HTML_Processor::get_attribute_names_with_prefix()publicWP 6.6.0

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

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;

Method of the class: WP_HTML_Processor{}

No Hooks.

Return

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

Usage

$WP_HTML_Processor = new WP_HTML_Processor();
$WP_HTML_Processor->get_attribute_names_with_prefix( $prefix );
$prefix(string) (required)
Prefix of requested attribute names.

Notes

Changelog

Since 6.6.0 Introduced.
Since 6.6.0 Subclassed for the HTML Processor.

WP_HTML_Processor::get_attribute_names_with_prefix() code WP 6.6.2

public function get_attribute_names_with_prefix( $prefix ) {
	return $this->is_virtual() ? null : parent::get_attribute_names_with_prefix( $prefix );
}