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 in other core functions. 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

private function parse_query( $query ) {
	if ( null !== $query && $query === $this->last_query ) {
		return;
	}

	$this->last_query          = $query;
	$this->sought_tag_name     = null;
	$this->sought_class_name   = null;
	$this->sought_match_offset = 1;
	$this->stop_on_tag_closers = false;

	// A single string value means "find the tag of this name".
	if ( is_string( $query ) ) {
		$this->sought_tag_name = $query;
		return;
	}

	// An empty query parameter applies no restrictions on the search.
	if ( null === $query ) {
		return;
	}

	// If not using the string interface, an associative array is required.
	if ( ! is_array( $query ) ) {
		_doing_it_wrong(
			__METHOD__,
			__( 'The query argument must be an array or a tag name.' ),
			'6.2.0'
		);
		return;
	}

	if ( isset( $query['tag_name'] ) && is_string( $query['tag_name'] ) ) {
		$this->sought_tag_name = $query['tag_name'];
	}

	if ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) ) {
		$this->sought_class_name = $query['class_name'];
	}

	if ( isset( $query['match_offset'] ) && is_int( $query['match_offset'] ) && 0 < $query['match_offset'] ) {
		$this->sought_match_offset = $query['match_offset'];
	}

	if ( isset( $query['tag_closers'] ) ) {
		$this->stop_on_tag_closers = 'visit' === $query['tag_closers'];
	}
}

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

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