WP_Interactivity_API_Directives_Processor::next_balanced_tag_closer_tag(): bool

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.

Finds the matching closing tag for an opening tag.

Description

When called while the processor is on an open tag, it traverses the HTML until it finds the matching closer tag, respecting any in-between content, including nested tags of the same name. Returns false when called on a closer tag, a tag that doesn’t have a closer tag (void), a tag that doesn’t visit the closer tag, or if no matching closing tag was found.

Return

bool Whether a matching closing tag was found.

Source

public function next_balanced_tag_closer_tag(): bool {
	$depth    = 0;
	$tag_name = $this->get_tag();

	if ( ! $this->has_and_visits_its_closer_tag() ) {
		return false;
	}

	while ( $this->next_tag(
		array(
			'tag_name'    => $tag_name,
			'tag_closers' => 'visit',
		)
	) ) {
		if ( ! $this->is_tag_closer() ) {
			++$depth;
			continue;
		}

		if ( 0 === $depth ) {
			return true;
		}

		--$depth;
	}

	return false;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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