WP_HTML_Processor::next_token(): 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.

Ensures internal accounting is maintained for HTML semantic rules while the underlying Tag Processor class is seeking to a bookmark.

Description

This doesn’t currently have a way to represent non-tags and doesn’t process semantic rules for text nodes. For access to the raw tokens consider using WP_HTML_Tag_Processor instead.

Return

bool

Source

 *
 * @param array|string|null $query {
 *     Optional. Which tag name to find, having which class, etc. Default is to find any tag.
 *
 *     @type string|null $tag_name     Which tag to find, or `null` for "any tag."
 *     @type string      $tag_closers  'visit' to pause at tag closers, 'skip' or unset to only visit openers.
 *     @type int|null    $match_offset Find the Nth tag matching all search criteria.
 *                                     1 for "first" tag, 3 for "third," etc.
 *                                     Defaults to first tag.
 *     @type string|null $class_name   Tag must contain this whole class name to match.
 *     @type string[]    $breadcrumbs  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', '*' )`.
 * }
 * @return bool Whether a tag was matched.
 */
public function next_tag( $query = null ): bool {
	$visit_closers = isset( $query['tag_closers'] ) && 'visit' === $query['tag_closers'];

	if ( null === $query ) {
		while ( $this->next_token() ) {
			if ( '#tag' !== $this->get_token_type() ) {
				continue;
			}

			if ( ! $this->is_tag_closer() || $visit_closers ) {
				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;
	}

	$needs_class = ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) )
		? $query['class_name']
		: null;

	if ( ! ( array_key_exists( 'breadcrumbs', $query ) && is_array( $query['breadcrumbs'] ) ) ) {

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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