WP_HTML_Processor::next_tag( array|string|null $query = null ): bool

Finds the next tag matching the $query.


Parameters

$query array|string|null Optional
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 whole class name to match.
  • breadcrumbs string[]
    DOM sub-path at which element is found, e.g. array( 'FIGURE', 'IMG' ).
    May also contain the wildcard * which matches a single element, e.g. array( 'SECTION', '*' ).

Default: null


Top ↑

Return

bool Whether a tag was matched.


Top ↑

Source

File: wp-includes/html-api/class-wp-html-processor.php. View all references

public function next_tag( $query = null ) {
	if ( null === $query ) {
		while ( $this->step() ) {
			if ( ! $this->is_tag_closer() ) {
				return true;
			}
		}

		return false;
	}

	if ( is_string( $query ) ) {
		$query = array( 'breadcrumbs' => array( $query ) );
	}

	if ( ! is_array( $query ) ) {
		_doing_it_wrong(
			__METHOD__,
			__( 'Please pass a query array to this function.' ),
			'6.4.0'
		);
		return false;
	}

	if ( ! ( array_key_exists( 'breadcrumbs', $query ) && is_array( $query['breadcrumbs'] ) ) ) {
		while ( $this->step() ) {
			if ( ! $this->is_tag_closer() ) {
				return true;
			}
		}

		return false;
	}

	if ( isset( $query['tag_closers'] ) && 'visit' === $query['tag_closers'] ) {
		_doing_it_wrong(
			__METHOD__,
			__( 'Cannot visit tag closers in HTML Processor.' ),
			'6.4.0'
		);
		return false;
	}

	$breadcrumbs  = $query['breadcrumbs'];
	$match_offset = isset( $query['match_offset'] ) ? (int) $query['match_offset'] : 1;

	while ( $match_offset > 0 && $this->step() ) {
		if ( $this->matches_breadcrumbs( $breadcrumbs ) && 0 === --$match_offset ) {
			return true;
		}
	}

	return false;
}


Top ↑

Changelog

Changelog
Version Description
6.4.0 Introduced.

Top ↑

User Contributed Notes

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