W3cubDocs

/WordPress

WP_HTML_Processor::next_token(): bool

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

Version Description
6.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_html_processor/next_token