WP_HTML_Tag_Processor::parse_query()privateWP 6.2.0

Parses tag query input into internal search criteria.

Метод класса: WP_HTML_Tag_Processor{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->parse_query( $query );
$query(массив|строка|null) (обязательный)

Which tag name to find, having which class, etc.

По умолчанию: to find any tag

  • tag_name(строка|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.
    По умолчанию: first tag

  • class_name(строка|null)
    Tag must contain this class name to match.

  • tag_closers(строка)
    "visit" or "skip": whether to stop on tag closers, e.g. </div>.

Список изменений

С версии 6.2.0 Введена.

Код WP_HTML_Tag_Processor::parse_query() WP 6.6.2

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'];
	}
}