WP_HTML_Processor::step( string $node_to_process = self::PROCESS_NEXT_NODE ): bool
- Since
- 6.4.0
- Source
wp-includes/html-api/class-wp-html-processor.php:1020
Description
This is an internal method. The relevant public methods are WP_HTML_Processor::next_tag() and WP_HTML_Processor::next_token().
Compatibility
- WordPress
- since 6.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$node_to_processstringoptional- Whether to parse the next node or reprocess the current node.Default:
self::PROCESS_NEXT_NODE
Return value
bool- Whether a tag was matched.
Performance profile
How much work a call to WP_HTML_Processor::step() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 15–162
- Plugin surface
- None
- Called by
- 22
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 307.
Nothing here hands control to plugin code.
22 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 68 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::step() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 15–19 | none |
$node_to_process === false | 21 | ::next_token() |
| always | 47–74 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_foreign_content() |
| always | 53–80 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_initial() |
$node_to_process === false | 53–67 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_foreign_content() |
| always | 56–83 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_html() |
| always | 59–86 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_head() |
$node_to_process === false | 59–74 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_initial() |
| always | 62–89 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head() |
$node_to_process === false | 62–77 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_html() |
| always | 64–91 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_foreign_content() |
| always | 65–92 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head_noscript() |
56 further outcomes, up to 162 instructions
$node_to_process === false | 65–80 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_head() |
| always | 68–95 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_head() |
$node_to_process === false | 68–83 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head() |
| always | 70–97 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_initial() |
| always | 71–98 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_body() |
$node_to_process === false | 71–86 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head_noscript() |
| always | 73–100 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_before_html() |
| always | 74–101 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table() |
$node_to_process === false | 74–89 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_head() |
| always | 76–103 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_before_head() |
| always | 77–104 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_text() |
$node_to_process === false | 77–92 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_body() |
| always | 79–106 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_head() |
| always | 80–107 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_caption() |
$node_to_process === false | 80–95 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table() |
| always | 82–109 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_head_noscript() |
| always | 83–110 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_column_group() |
$node_to_process === false | 83–98 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_text() |
| always | 85–112 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_head() |
| always | 86–113 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_body() |
$node_to_process === false | 86–101 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_caption() |
| always | 88–115 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_body() |
| always | 89–116 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_row() |
$node_to_process === false | 89–104 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_column_group() |
| always | 91–118 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_table() |
| always | 92–119 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_cell() |
$node_to_process === false | 92–107 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_body() |
| always | 94–121 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_table_text() |
| always | 95–122 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_template() |
$node_to_process === false | 95–110 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_row() |
| always | 97–124 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_caption() |
| always | 98–125 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_body() |
$node_to_process === false | 98–113 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_cell() |
| always | 100–127 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_column_group() |
| always | 101–128 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_frameset() |
$node_to_process === false | 101–116 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_template() |
| always | 103–130 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_table_body() |
| always | 104–131 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_frameset() |
$node_to_process === false | 104–118 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_body() |
| always | 106–133 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_row() |
| always | 107–134 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_body() |
$node_to_process === false | 107–121 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_frameset() |
| always | 109–136 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_cell() |
| always | 110–137 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_frameset() |
$node_to_process === false | 110–124 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_frameset() |
| always | 112–139 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_template() |
$node_to_process === false | 113–127 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_body() |
| always | 115–142 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_body() |
$node_to_process === false | 116–130 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_frameset() |
| always | 118–145 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->bail() |
| always | 118–145 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_frameset() |
| always | 121–148 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_frameset() |
$node_to_process === false | 124–138 | ::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->bail() |
| always | 124–151 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_after_body() |
| always | 127–154 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_after_frameset() |
| always | 135–162 | ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->bail() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 307 | 15–162 | 45 | |
| 8.5 | 307 | 15–162 | 45 | |
| 8.4 | 307 | 15–162 | 45 | |
| 8.3 | 307 | 15–162 | 45 | |
| 8.2 | 307 | 15–162 | 45 | 1 more instruction than PHP 8.1 |
| 8.1 | 306 | 15–160 | 45 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 307 | 15–161 | 45 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 31
- WP_HTML_Processor::expects_closer()Indicates if the currently-matched node expects a closing token, or if it will self-close on the next step.
- WP_HTML_Tag_Processor::next_token()Finds the next token in the HTML document.
- WP_HTML_Tag_Processor::subdivide_text_appropriately()Subdivides a matched text node, splitting NULL byte sequences and decoded whitespace as distinct nodes prefixes.
- WP_HTML_Processor::get_adjusted_current_node()Returns the adjusted current node.
- WP_HTML_Processor::is_tag_closer()Indicates if the current tag token is a tag closer.
- WP_HTML_Processor::get_token_name()Returns the node name represented by the token.
- WP_HTML_Processor::bookmark_token()Creates a new bookmark for the currently-matched token and returns the generated name.
- WP_HTML_Token::__construct()Constructor - creates a reference to a token in some external HTML string.
- WP_HTML_Processor::has_self_closing_flag()Indicates if the currently matched tag contains the self-closing flag.
- WP_HTML_Processor::step_in_foreign_content()Parses next element in the 'in foreign content' insertion mode.
- WP_HTML_Processor::step_initial()Parses next element in the 'initial' insertion mode.
- WP_HTML_Processor::step_before_html()Parses next element in the 'before html' insertion mode.
Show all 31
- WP_HTML_Processor::step_before_head()Parses next element in the 'before head' insertion mode.
- WP_HTML_Processor::step_in_head()Parses next element in the 'in head' insertion mode.
- WP_HTML_Processor::step_in_head_noscript()Parses next element in the 'in head noscript' insertion mode.
- WP_HTML_Processor::step_after_head()Parses next element in the 'after head' insertion mode.
- WP_HTML_Processor::step_in_body()Parses next element in the 'in body' insertion mode.
- WP_HTML_Processor::step_in_table()Parses next element in the 'in table' insertion mode.
- WP_HTML_Processor::step_in_table_text()Parses next element in the 'in table text' insertion mode.
- WP_HTML_Processor::step_in_caption()Parses next element in the 'in caption' insertion mode.
- WP_HTML_Processor::step_in_column_group()Parses next element in the 'in column group' insertion mode.
- WP_HTML_Processor::step_in_table_body()Parses next element in the 'in table body' insertion mode.
- WP_HTML_Processor::step_in_row()Parses next element in the 'in row' insertion mode.
- WP_HTML_Processor::step_in_cell()Parses next element in the 'in cell' insertion mode.
- WP_HTML_Processor::step_in_template()Parses next element in the 'in template' insertion mode.
- WP_HTML_Processor::step_after_body()Parses next element in the 'after body' insertion mode.
- WP_HTML_Processor::step_in_frameset()Parses next element in the 'in frameset' insertion mode.
- WP_HTML_Processor::step_after_frameset()Parses next element in the 'after frameset' insertion mode.
- WP_HTML_Processor::step_after_after_body()Parses next element in the 'after after body' insertion mode.
- WP_HTML_Processor::step_after_after_frameset()Parses next element in the 'after after frameset' insertion mode.
- WP_HTML_Processor::bail()Stops the parser and terminates its execution when encountering unsupported markup.
Used by · 22
- WP_HTML_Processor::in_body_any_other_end_tag()Applies the "any other end tag" parsing instructions for the IN BODY insertion mode.
- WP_HTML_Processor::next_visitable_token()Ensures internal accounting is maintained for HTML semantic rules while the underlying Tag Processor class is seeking to a bookmark.
- WP_HTML_Processor::step_after_after_body()Parses next element in the 'after after body' insertion mode.
- WP_HTML_Processor::step_after_after_frameset()Parses next element in the 'after after frameset' insertion mode.
- WP_HTML_Processor::step_after_body()Parses next element in the 'after body' insertion mode.
- WP_HTML_Processor::step_after_frameset()Parses next element in the 'after frameset' insertion mode.
- WP_HTML_Processor::step_after_head()Parses next element in the 'after head' insertion mode.
- WP_HTML_Processor::step_before_head()Parses next element in the 'before head' insertion mode.
- WP_HTML_Processor::step_before_html()Parses next element in the 'before html' insertion mode.
- WP_HTML_Processor::step_in_body()Parses next element in the 'in body' insertion mode.
- WP_HTML_Processor::step_in_caption()Parses next element in the 'in caption' insertion mode.
- WP_HTML_Processor::step_in_cell()Parses next element in the 'in cell' insertion mode.
Show all 22
- WP_HTML_Processor::step_in_column_group()Parses next element in the 'in column group' insertion mode.
- WP_HTML_Processor::step_in_foreign_content()Parses next element in the 'in foreign content' insertion mode.
- WP_HTML_Processor::step_in_frameset()Parses next element in the 'in frameset' insertion mode.
- WP_HTML_Processor::step_in_head()Parses next element in the 'in head' insertion mode.
- WP_HTML_Processor::step_in_head_noscript()Parses next element in the 'in head noscript' insertion mode.
- WP_HTML_Processor::step_in_row()Parses next element in the 'in row' insertion mode.
- WP_HTML_Processor::step_in_table()Parses next element in the 'in table' insertion mode.
- WP_HTML_Processor::step_in_table_body()Parses next element in the 'in table body' insertion mode.
- WP_HTML_Processor::step_in_template()Parses next element in the 'in template' insertion mode.
- WP_HTML_Processor::step_initial()Parses next element in the 'initial' insertion mode.
Source code
public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool { // Refuse to proceed if there was a previous error. if ( null !== $this->last_error ) { return false; } if ( self::REPROCESS_CURRENT_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. */ $top_node = $this->state->stack_of_open_elements->current_node(); if ( isset( $top_node ) && ! $this->expects_closer( $top_node ) ) { $this->state->stack_of_open_elements->pop(); } } if ( self::PROCESS_NEXT_NODE === $node_to_process ) { parent::next_token(); if ( WP_HTML_Tag_Processor::STATE_TEXT_NODE === $this->parser_state ) { parent::subdivide_text_appropriately(); } } // Finish stepping when there are no more tokens in the document. if ( WP_HTML_Tag_Processor::STATE_INCOMPLETE_INPUT === $this->parser_state || WP_HTML_Tag_Processor::STATE_COMPLETE === $this->parser_state ) { return false; } $adjusted_current_node = $this->get_adjusted_current_node(); $is_closer = $this->is_tag_closer(); $is_start_tag = WP_HTML_Tag_Processor::STATE_MATCHED_TAG === $this->parser_state && ! $is_closer; $token_name = $this->get_token_name(); if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) { try { $bookmark_name = $this->bookmark_token(); } catch ( Exception $e ) { if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) { return false; } throw $e; } $this->state->current_token = new WP_HTML_Token( $bookmark_name, $token_name, $this->has_self_closing_flag(), $this->release_internal_bookmark_on_destruct ); } $parse_in_current_insertion_mode = ( 0 === $this->state->stack_of_open_elements->count() || 'html' === $adjusted_current_node->namespace || ( 'math' === $adjusted_current_node->integration_node_type && ( ( $is_start_tag && ! in_array( $token_name, array( 'MGLYPH', 'MALIGNMARK' ), true ) ) || '#text' === $token_name ) ) || ( 'math' === $adjusted_current_node->namespace && 'ANNOTATION-XML' === $adjusted_current_node->node_name && $is_start_tag && 'SVG' === $token_name ) || ( 'html' === $adjusted_current_node->integration_node_type && ( $is_start_tag || '#text' === $token_name ) ) );Changelog
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/html-api/class-wp-html-processor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.