WP_HTML_Tag_Processor::parse_query( array|string|null $query )

In this article

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

Parses tag query input into internal search criteria.

Parameters

$queryarray|string|nulloptional
Which tag name to find, having which class, etc. Default is to find any tag.
  • tag_name string|null
    Which tag to find, or null for "any tag."
  • match_offset int|null
    Find the Nth tag matching all search criteria.
    1 for "first" tag, 3 for "third," etc.
    Defaults to first tag.
  • class_name string|null
    Tag must contain this class name to match.
  • tag_closers string
    "visit" or "skip": whether to stop on tag closers, e.g. </div>.

Source


/**
 * WordPress rejects more characters than are strictly forbidden
 * in HTML5. This is to prevent additional security risks deeper
 * in the WordPress and plugin stack. Specifically the following
 * are not allowed to be set as part of an HTML attribute name:
 *
 *  - greater-than “>”
 *  - ampersand “&”
 *
 * @see https://html.spec.whatwg.org/#attributes-2
 */
if (
	0 === $name_length ||
	// Syntax-like characters.
	strcspn( $name, '"\'>&</ =' ) !== $name_length ||
	// Control characters.
	strcspn(
		$name,
		"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" .
		"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
	) !== $name_length ||
	// Unicode noncharacters.
	wp_has_noncharacters( $name )
) {
	_doing_it_wrong(
		__METHOD__,
		__( 'Invalid attribute name.' ),
		'6.2.0'
	);

	return false;
}

/*
 * > The values "true" and "false" are not allowed on boolean attributes.
 * > To represent a false value, the attribute has to be omitted altogether.
 *     - HTML5 spec, https://html.spec.whatwg.org/#boolean-attributes
 */
if ( false === $value ) {
	return $this->remove_attribute( $name );
}

if ( true === $value ) {
	$updated_attribute = $name;
} else {
	$comparable_name = strtolower( $name );

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

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