WP_HTML_Tag_Processor::matches()privateWP 6.2.0

Checks whether a given tag and its attributes match the search criteria.

Method of the class: WP_HTML_Tag_Processor{}

No Hooks.

Return

true|false. Whether the given tag and its attribute match the search criteria.

Usage

// private - for code of main (parent) class only
$result = $this->matches();

Changelog

Since 6.2.0 Introduced.

WP_HTML_Tag_Processor::matches() code WP 6.6.2

private function matches() {
	if ( $this->is_closing_tag && ! $this->stop_on_tag_closers ) {
		return false;
	}

	// Does the tag name match the requested tag name in a case-insensitive manner?
	if ( null !== $this->sought_tag_name ) {
		/*
		 * String (byte) length lookup is fast. If they aren't the
		 * same length then they can't be the same string values.
		 */
		if ( strlen( $this->sought_tag_name ) !== $this->tag_name_length ) {
			return false;
		}

		/*
		 * Check each character to determine if they are the same.
		 * Defer calls to `strtoupper()` to avoid them when possible.
		 * Calling `strcasecmp()` here tested slowed than comparing each
		 * character, so unless benchmarks show otherwise, it should
		 * not be used.
		 *
		 * It's expected that most of the time that this runs, a
		 * lower-case tag name will be supplied and the input will
		 * contain lower-case tag names, thus normally bypassing
		 * the case comparison code.
		 */
		for ( $i = 0; $i < $this->tag_name_length; $i++ ) {
			$html_char = $this->html[ $this->tag_name_starts_at + $i ];
			$tag_char  = $this->sought_tag_name[ $i ];

			if ( $html_char !== $tag_char && strtoupper( $html_char ) !== $tag_char ) {
				return false;
			}
		}
	}

	if ( null !== $this->sought_class_name && ! $this->has_class( $this->sought_class_name ) ) {
		return false;
	}

	return true;
}