wppaste
WordPress

WP_HTML_Processor::step_in_foreign_content(): bool

Since
6.7.0
Source
wp-includes/html-api/class-wp-html-processor.php:4806
Parses next element in the 'in foreign content' insertion mode.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
18–107

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 490.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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.

WhenInstructionsCalls it makes
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil18->get_token_name(), ->get_token_type(), ->step()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil22–29->get_token_name(), ->get_token_type(), ->insert_foreign_element()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil31–41->get_token_name(), ->get_token_type(), ->walk_up(), ->step_initial()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil34–44->get_token_name(), ->get_token_type(), ->walk_up(), ->step_before_html()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil37–47->get_token_name(), ->get_token_type(), ->walk_up(), ->step_before_head()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil40–43->get_token_name(), ->get_token_type(), strspn(), ->insert_foreign_element()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil40–50->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_head()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil43–53->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_head_noscript()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil46–56->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_head()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil49–59->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_body()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil52–62->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_table()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil55–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_sigil58–68->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_caption()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil61–71->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_column_group()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil64–74->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_table_body()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil67–77->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_row()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil70–80->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_cell()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil73–83->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_template()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil76–86->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_body()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil79–89->get_token_name(), ->get_token_type(), ->walk_up(), ->step_in_frameset()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil82–92->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_frameset()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil85–95->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_after_body()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil88–98->get_token_name(), ->get_token_type(), ->walk_up(), ->step_after_after_frameset()
$token_type !== "#tag" && $op !== "+FONT" && $op_sigil97–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

PHPCompiledExecutedBranchesNotes
8.6-dev49018–107102
8.549018–107102
8.449018–107102
8.349018–107102
8.249018–1071022 more instructions than PHP 8.1
8.148818–106102
7.448818–106102

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

Show all 27

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.