WP_HTML_Processor::step( string $node_to_process = self::PROCESS_NEXT_NODE ): bool

Steps through the HTML document and stop at the next tag, if any.

Description

See also

Parameters

$node_to_processstringoptional
Whether to parse the next node or reprocess the current node.

Default:self::PROCESS_NEXT_NODE

Return

bool Whether a tag was matched.

Source

	return (
		isset( $this->current_element->provenance ) &&
		'virtual' === $this->current_element->provenance
	);
}

/**
 * Indicates if the currently-matched tag matches the given breadcrumbs.
 *
 * A "*" represents a single tag wildcard, where any tag matches, but not no tags.
 *
 * At some point this function _may_ support a `**` syntax for matching any number
 * of unspecified tags in the breadcrumb stack. This has been intentionally left
 * out, however, to keep this function simple and to avoid introducing backtracking,
 * which could open up surprising performance breakdowns.
 *
 * Example:
 *
 *     $processor = WP_HTML_Processor::create_fragment( '<div><span><figure><img></figure></span></div>' );
 *     $processor->next_tag( 'img' );
 *     true  === $processor->matches_breadcrumbs( array( 'figure', 'img' ) );
 *     true  === $processor->matches_breadcrumbs( array( 'span', 'figure', 'img' ) );
 *     false === $processor->matches_breadcrumbs( array( 'span', 'img' ) );
 *     true  === $processor->matches_breadcrumbs( array( 'span', '*', 'img' ) );
 *
 * @since 6.4.0
 *
 * @param 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 the currently-matched tag is found at the given nested structure.
 */
public function matches_breadcrumbs( $breadcrumbs ): bool {
	// Everything matches when there are zero constraints.
	if ( 0 === count( $breadcrumbs ) ) {
		return true;
	}

	// Start at the last crumb.
	$crumb = end( $breadcrumbs );

	if ( '*' !== $crumb && $this->get_tag() !== strtoupper( $crumb ) ) {
		return false;
	}

	for ( $i = count( $this->breadcrumbs ) - 1; $i >= 0; $i-- ) {
		$node  = $this->breadcrumbs[ $i ];
		$crumb = strtoupper( current( $breadcrumbs ) );

		if ( '*' !== $crumb && $node !== $crumb ) {
			return false;
		}

		if ( false === prev( $breadcrumbs ) ) {
			return true;
		}
	}

	return false;
}

/**
 * Indicates if the currently-matched node expects a closing
 * token, or if it will self-close on the next step.

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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