WP_HTML_Processor::step_in_foreign_content(): bool
- Since
- 6.7.0
- Source
wp-includes/html-api/class-wp-html-processor.php:4806
Description
This internal function performs the 'in foreign content' insertion mode logic for the generalized WP_HTML_Processor::step() function.
Compatibility
- WordPress
- since 6.7.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_foreign_content() 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
- 18–107
- Plugin surface
- None
- Called by
- 1
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 490.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 24 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_foreign_content() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 18 | ->get_token_name(), ->get_token_type(), ->step() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 22–29 | ->get_token_name(), ->get_token_type(), ->insert_foreign_element() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 31–41 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_initial() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 34–44 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_before_html() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 37–47 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_before_head() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 40–43 | ->get_token_name(), ->get_token_type(), strspn(), ->insert_foreign_element() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 40–50 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_head() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 43–53 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_head_noscript() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 46–56 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_head() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 49–59 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_body() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 52–62 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_table() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 55–65 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_table_text() |
12 further outcomes, up to 107 instructions
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 58–68 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_caption() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 61–71 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_column_group() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 64–74 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_table_body() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 67–77 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_row() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 70–80 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_cell() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 73–83 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_template() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 76–86 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_body() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 79–89 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_frameset() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 82–92 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_frameset() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 85–95 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_after_body() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 88–98 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_after_frameset() |
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil | 97–107 | ->get_token_name(), ->get_token_type(), ->walk_up(), ->bail(), ->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 | 490 | 18–107 | 102 | |
| 8.5 | 490 | 18–107 | 102 | |
| 8.4 | 490 | 18–107 | 102 | |
| 8.3 | 490 | 18–107 | 102 | |
| 8.2 | 490 | 18–107 | 102 | 2 more instructions than PHP 8.1 |
| 8.1 | 488 | 18–106 | 102 | |
| 7.4 | 488 | 18–106 | 102 |
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 · 27
- 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_Processor::is_tag_closer()Indicates if the current tag token is a tag closer.
- WP_HTML_Processor::get_attribute()Returns the value of a requested attribute from a matched tag opener if that attribute exists.
- WP_HTML_Processor::insert_foreign_element()Inserts a foreign element on to the stack of open elements.
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- 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.
- 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.
Show all 27
- 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 · 1
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
Source code
private function step_in_foreign_content(): bool { $tag_name = $this->get_token_name(); $token_type = $this->get_token_type(); $op_sigil = '#tag' === $token_type ? ( $this->is_tag_closer() ? '-' : '+' ) : ''; $op = "{$op_sigil}{$tag_name}"; /* * > A start tag whose name is "font", if the token has any attributes named "color", "face", or "size" * * This section drawn out above the switch to more easily incorporate * the additional rules based on the presence of the attributes. */ if ( '+FONT' === $op && ( null !== $this->get_attribute( 'color' ) || null !== $this->get_attribute( 'face' ) || null !== $this->get_attribute( 'size' ) ) ) { $op = '+FONT with attributes'; } switch ( $op ) { case '#text': /* * > A character token that is U+0000 NULL * * This is handled by `get_modifiable_text()`. */ /* * 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_foreign_element( $this->state->current_token, false ); return true; /* * CDATA sections are alternate wrappers for text content and therefore * ought to follow the same rules as text nodes. */ case '#cdata-section': /* * NULL bytes and whitespace do not change the frameset-ok flag. */ $current_token = $this->bookmarks[ $this->state->current_token->bookmark_name ]; $cdata_content_start = $current_token->start + 9; $cdata_content_length = $current_token->length - 12; if ( strspn( $this->html, "\0 \t\n\f\r", $cdata_content_start, $cdata_content_length ) !== $cdata_content_length ) { $this->state->frameset_ok = false; } $this->insert_foreign_element( $this->state->current_token, false ); return true; /* * > A comment token * > A processing instruction token */ case '#comment': case '#funky-comment': case '#presumptuous-tag': case '#processing-instruction': $this->insert_foreign_element( $this->state->current_token, false ); return true; /* * > A DOCTYPE token */ case 'html': // Parse error: ignore the token. return $this->step(); /*Changelog
Introduced in 6.7.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.