WP_HTML_Processor::step_in_body(): bool
- Since
- 6.4.0
- Source
wp-includes/html-api/class-wp-html-processor.php:2320
Description
This internal function performs the 'in body' insertion mode logic for the generalized WP_HTML_Processor::step() function.
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.
Return value
bool- Whether an element was found.
Performance profile
How much work a call to WP_HTML_Processor::step_in_body() 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
- Light
- Scaling
- Scales with input
- Instructions
- 15–135
- Plugin surface
- None
- Called by
- 15
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 1369.
Nothing here hands control to plugin code.
15 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 71 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::step_in_body() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$token_type !== "#tag" && $op_sigil | 15 | ->get_token_name(), ->get_token_type(), ->run_adoption_agency_algorithm() |
$token_type !== "#tag" | 16–28 | ->get_token_name(), ->get_token_type(), ->step() |
$token_type !== "#tag" | 16–52 | ->get_token_name(), ->get_token_type(), ->step_in_head() |
$token_type !== "#tag" | 19–30 | ->get_token_name(), ->get_token_type(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ::is_tag_closer() | 19 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->in_body_any_other_end_tag() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() | 20 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element() |
$token_type !== "#tag" | 21–35 | ->get_token_name(), ->get_token_type(), ->contains(), ->step() |
$token_type !== "#tag" | 22–62 | ->get_token_name(), ->get_token_type(), ->count(), ->step() |
$token_type !== "#tag" | 22–72 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->step() |
$token_type !== "#tag" && $op_sigil && ::is_tag_closer() | 23 | ->get_token_name(), ->get_token_type(), ->bail(), ::is_tag_closer(), ->in_body_any_other_end_tag() |
$token_type !== "#tag" | 24–34 | ->get_token_name(), ->get_token_type(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && !->has_p_in_button_scope() | 24–118 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->insert_html_element() |
59 further outcomes, up to 61 instructions
$token_type !== "#tag" && $op_sigil && $token_name === "LI" && !->has_element_in_list_item_scope() | 24 | ->get_token_name(), ->get_token_type(), ->has_element_in_list_item_scope(), ->step() |
$token_type !== "#tag" && $op_sigil && !::is_tag_closer() | 24 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() | 25 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->insert_html_element() |
$token_type !== "#tag" && ->has_p_in_button_scope() | 26–120 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() | 26 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->insert_html_element(), ->close_a_p_element() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() | 28–32 | ->get_token_name(), ->get_token_type(), ->contains(), ->has_element_in_scope(), ->step() |
$token_type !== "#tag" && $op_sigil | 28 | ->get_token_name(), ->get_token_type(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->insert_marker() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() && ::is_tag_closer() | 28 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->bail(), ::is_tag_closer(), ->in_body_any_other_end_tag() |
$token_type !== "#tag" && $op_sigil && !::is_tag_closer() | 28 | ->get_token_name(), ->get_token_type(), ->bail(), ::is_tag_closer(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil | 29 | ->get_token_name(), ->get_token_type(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->push() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() | 29 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 29–33 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->pop_until(), ->step() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() | 30–36 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil | 30 | ->get_token_name(), ->get_token_type(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 30–31 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() && ::is_tag_closer() | 30 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->bail(), ::is_tag_closer(), ->in_body_any_other_end_tag() |
$token_type !== "#tag" | 31–76 | ->get_token_name(), ->get_token_type(), ->count(), ->at(), ->step() |
$token_type !== "#tag" && !->has_p_in_button_scope() | 31–131 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->current_node(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 31–36 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() | 31 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_list_item_scope() && !->has_element_in_scope() | 32 | ->get_token_name(), ->get_token_type(), ->has_element_in_list_item_scope(), ->has_element_in_scope(), ->step() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 32 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() && !->has_element_in_scope() | 33 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->has_element_in_scope(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil | 33 | ->get_token_name(), ->get_token_type(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->pop() |
$token_type !== "#tag" && ->has_p_in_button_scope() | 33–133 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->current_node(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() && !->current_node_is() | 33 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->current_node_is(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() && !::is_tag_closer() | 33 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->bail(), ::is_tag_closer(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() | 34–40 | ->get_token_name(), ->get_token_type(), ->contains(), ->has_p_in_button_scope(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 34 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node(), ->insert_html_element() |
$token_type !== "#tag" && !->has_p_in_button_scope() | 35–135 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->current_node(), ->pop(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil | 35–42 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->push() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() | 35 | ->get_token_name(), ->get_token_type(), ->reconstruct_active_formatting_elements(), ->has_element_in_scope(), ->insert_html_element(), ->push() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() && ->has_element_in_scope() | 35 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() && !->has_element_in_scope() | 35 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->has_element_in_scope(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 35 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until(), ->clear_up_to_last_marker() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() && !::is_tag_closer() | 35 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->bail(), ::is_tag_closer(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() | 36–42 | ->get_token_name(), ->get_token_type(), ->contains(), ->has_p_in_button_scope(), ->close_a_p_element(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && $token_name === "LI" && ->has_element_in_list_item_scope() | 36 | ->get_token_name(), ->get_token_type(), ->has_element_in_list_item_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until() |
$token_type !== "#tag" | 37–79 | ->get_token_name(), ->get_token_type(), ->count(), ->at(), ->contains(), ->step() |
$token_type !== "#tag" && ->has_p_in_button_scope() | 37–135 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->current_node(), ->pop(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 37 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->pop_until(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->contains() && ->has_element_in_scope() | 37 | ->get_token_name(), ->get_token_type(), ->contains(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() && ->has_element_in_scope() | 37 | ->get_token_name(), ->get_token_type(), ->has_p_in_button_scope(), ->close_a_p_element(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() && ->current_node_is() | 37 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->current_node_is(), ->pop(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() && !is_string($type_attribute) | 38–42 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->get_attribute() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() | 39 | ->get_token_name(), ->get_token_type(), ->reconstruct_active_formatting_elements(), ->has_element_in_scope(), ->run_adoption_agency_algorithm(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->push() |
$token_type !== "#tag" && $op_sigil && !->has_element_in_scope() && is_string($type_attribute) | 40–47 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->get_attribute(), strtolower() |
$token_type !== "#tag" && ::is_tag_closer() | 42–83 | ->get_token_name(), ->get_token_type(), ->count(), ->at(), ->bail(), ::is_tag_closer(), ->in_body_any_other_end_tag() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_list_item_scope() && ->has_element_in_scope() | 42 | ->get_token_name(), ->get_token_type(), ->has_element_in_list_item_scope(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() && !is_string($type_attribute) | 43–47 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->pop_until(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->get_attribute() |
$token_type !== "#tag" && $op_sigil && !->contains() && $node !== null && ->has_element_in_scope() && $node === false | 45 | ->get_token_name(), ->get_token_type(), ->contains(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node(), ->remove_node() |
$token_type !== "#tag" && $op_sigil && ->has_element_in_scope() && is_string($type_attribute) | 45–52 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->pop_until(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->get_attribute(), strtolower() |
$token_type !== "#tag" && !::is_tag_closer() | 47–88 | ->get_token_name(), ->get_token_type(), ->count(), ->at(), ->bail(), ::is_tag_closer(), ->reconstruct_active_formatting_elements(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->contains() && $node !== null && ->has_element_in_scope() && $node !== false | 48 | ->get_token_name(), ->get_token_type(), ->contains(), ->has_element_in_scope(), ->generate_implied_end_tags(), ->current_node(), ->bail(), ->remove_node() |
$token_type !== "#tag" && $op_sigil && ::is_special() && !->has_p_in_button_scope() | 51–54 | ->get_token_name(), ->get_token_type(), ->current_node(), ::is_special(), ->has_p_in_button_scope(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->walk_up() | 52–56 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->run_adoption_agency_algorithm(), ->remove_node(), ->remove_node(), ->reconstruct_active_formatting_elements(), ->insert_html_element(), ->push() |
$token_type !== "#tag" && $op_sigil && ::is_special() && ->has_p_in_button_scope() | 53–56 | ->get_token_name(), ->get_token_type(), ->current_node(), ::is_special(), ->has_p_in_button_scope(), ->close_a_p_element(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && !->has_p_in_button_scope() | 55–59 | ->get_token_name(), ->get_token_type(), ->current_node(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until(), ->has_p_in_button_scope(), ->insert_html_element() |
$token_type !== "#tag" && $op_sigil && ->has_p_in_button_scope() | 57–61 | ->get_token_name(), ->get_token_type(), ->current_node(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until(), ->has_p_in_button_scope(), ->close_a_p_element(), ->insert_html_element() |
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 | 1369 | 15–135 | 248 | |
| 8.5 | 1369 | 15–135 | 248 | |
| 8.4 | 1369 | 15–135 | 248 | |
| 8.3 | 1369 | 15–135 | 248 | |
| 8.2 | 1369 | 15–135 | 248 | 2 more instructions than PHP 8.1 |
| 8.1 | 1367 | 15–135 | 248 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 1369 | 15–135 | 248 |
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 · 14
- WP_HTML_Processor::get_token_name()Returns the node name represented by the token.
- WP_HTML_Processor::get_token_type()Indicates the kind of matched token, if any.
- WP_HTML_Tag_Processor::is_tag_closer()Indicates if the current tag token is a tag closer.
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- WP_HTML_Processor::reconstruct_active_formatting_elements()Reconstructs the active formatting elements.
- WP_HTML_Processor::insert_html_element()Inserts an HTML element on the stack of open elements.
- WP_HTML_Processor::step_in_head()Parses next element in the 'in head' insertion mode.
- WP_HTML_Processor::bail()Stops the parser and terminates its execution when encountering unsupported markup.
- WP_HTML_Processor::close_a_p_element()Closes a P element.
- WP_HTML_Processor::generate_implied_end_tags()Closes elements that have implied end tags.
- WP_HTML_Processor::is_special()Returns whether an element of a given name is in the HTML special category.
- WP_HTML_Processor::run_adoption_agency_algorithm()Runs the adoption agency algorithm.
Show all 14
- WP_HTML_Processor::get_attribute()Returns the value of a requested attribute from a matched tag opener if that attribute exists.
- WP_HTML_Processor::in_body_any_other_end_tag()Applies the "any other end tag" parsing instructions for the IN BODY insertion mode.
Used by · 15
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- 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_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.
- 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.
Show all 15
- 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_template()Parses next element in the 'in template' insertion mode.
Source code
private function step_in_body(): bool { $token_name = $this->get_token_name(); $token_type = $this->get_token_type(); $op_sigil = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : ''; $op = "{$op_sigil}{$token_name}"; switch ( $op ) { case '#text': /* * > A character token that is U+0000 NULL * * Any successive sequence of NULL bytes is ignored and won't * trigger active format reconstruction. Therefore, if the text * only comprises NULL bytes then the token should be ignored * here, but if there are any other characters in the stream * the active formats should be reconstructed. */ if ( parent::TEXT_IS_NULL_SEQUENCE === $this->text_node_classification ) { // Parse error: ignore the token. return $this->step(); } $this->reconstruct_active_formatting_elements(); /* * Whitespace-only text does not affect the frameset-ok flag. * It is probably inter-element whitespace, but it may also * contain character references which decode only to whitespace. */ if ( parent::TEXT_IS_GENERIC === $this->text_node_classification ) { $this->state->frameset_ok = false; } $this->insert_html_element( $this->state->current_token ); return true; case '#comment': case '#funky-comment': case '#presumptuous-tag': case '#processing-instruction': $this->insert_html_element( $this->state->current_token ); return true; /* * > A DOCTYPE token * > Parse error. Ignore the token. */ case 'html': return $this->step(); /* * > A start tag whose tag name is "html" */ case '+HTML': if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) { /* * > Otherwise, for each attribute on the token, check to see if the attribute * > is already present on the top element of the stack of open elements. If * > it is not, add the attribute and its corresponding value to that element. * * This parser does not currently support this behavior: ignore the token. */ } // Ignore the token. return $this->step(); /* * > A start tag whose tag name is one of: "base", "basefont", "bgsound", "link", * > "meta", "noframes", "script", "style", "template", "title" * > * > An end tag whose tag name is "template" */ case '+BASE': case '+BASEFONT': case '+BGSOUND': case '+LINK': case '+META': case '+NOFRAMES': case '+SCRIPT':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.