_wptexturize_pushpop_element( string $text, string[] $stack, string[] $disabled_elements )
- Since
- 2.9.0
- Source
wp-includes/formatting.php:391
Description
Assumes first char of $text is tag opening and last char is tag closing.
Assumes second char of $text is optionally / to indicate closing as in </html>.
Compatibility
- WordPress
- since 2.9.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
$textstring- Text to check. Must be a tag like
<html>or[shortcode]. $stackstring[]- Array of open tag elements.
$disabled_elementsstring[]- Array of tag names to match against. Spaces are not allowed in tag names.
Performance profile
How much work a call to _wptexturize_pushpop_element() 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
- 9–33
- Plugin surface
- None
- Called by
- 1
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 43.
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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wptexturize_pushpop_element() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9–24 | none |
$tag | 25–29 | array_push() |
$tag && $tag !== false | 26–30 | end() |
$tag && $tag === false | 29–33 | end(), array_pop() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 43 | 9–33 | 7 | |
| 8.5 | 43 | 9–33 | 7 | |
| 8.4 | 43 | 9–33 | 7 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 53 | 9–43 | 7 | |
| 8.2 | 53 | 9–43 | 7 | |
| 8.1 | 53 | 9–43 | 7 | |
| 7.4 | 53 | 9–43 | 7 |
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.
Used by · 1
- wptexturize()Replaces common plain text characters with formatted entities.
Source code
function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) { // Is it an opening tag or closing tag? if ( isset( $text[1] ) && '/' !== $text[1] ) { $opening_tag = true; $name_offset = 1; } elseif ( 0 === count( $stack ) ) { // Stack is empty. Just stop. return; } else { $opening_tag = false; $name_offset = 2; } // Parse out the tag name. $space = strpos( $text, ' ' ); if ( false === $space ) { $space = -1; } else { $space -= $name_offset; } $tag = substr( $text, $name_offset, $space ); // Handle disabled tags. if ( in_array( $tag, $disabled_elements, true ) ) { if ( $opening_tag ) { /* * This disables texturize until we find a closing tag of our type * (e.g. <pre>) even if there was invalid nesting before that. * * Example: in the case <pre>sadsadasd</code>"baba"</pre> * "baba" won't be texturized. */ array_push( $stack, $tag ); } elseif ( end( $stack ) === $tag ) { array_pop( $stack ); } }}Changelog
Introduced in 2.9.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 6.7.7 tag, from
src/wp-includes/formatting.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.