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.


See also


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



bool Whether a tag was matched.


public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
	// Refuse to proceed if there was a previous error.
	if ( null !== $this->last_error ) {
		return false;

	if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
		 * Void elements still hop onto the stack of open elements even though
		 * there's no corresponding closing tag. This is important for managing
		 * stack-based operations such as "navigate to parent node" or checking
		 * on an element's breadcrumbs.
		 * When moving on to the next node, therefore, if the bottom-most element
		 * on the stack is a void element, it must be closed.
		 * @TODO: Once self-closing foreign elements and BGSOUND are supported,
		 *        they must also be implicitly closed here too. BGSOUND is
		 *        special since it's only self-closing if the self-closing flag
		 *        is provided in the opening tag, otherwise it expects a tag closer.
		$top_node = $this->state->stack_of_open_elements->current_node();
		if ( $top_node && self::is_void( $top_node->node_name ) ) {

		parent::next_tag( self::VISIT_EVERYTHING );

	// Finish stepping when there are no more tokens in the document.
	if ( null === $this->get_tag() ) {
		return false;

	$this->state->current_token = new WP_HTML_Token(

	try {
		switch ( $this->state->insertion_mode ) {
			case WP_HTML_Processor_State::INSERTION_MODE_IN_BODY:
				return $this->step_in_body();

				$this->last_error = self::ERROR_UNSUPPORTED;
				throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
	} catch ( WP_HTML_Unsupported_Exception $e ) {
		 * Exceptions are used in this class to escape deep call stacks that
		 * otherwise might involve messier calling and return conventions.
		return false;



User Contributed Notes

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