On this page
_wptexturize_pushpop_element( string $text, string[] $stack, string[] $disabled_elements )
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Searches for disabled element tags. Pushes element to stack on tag open and pops on tag close.
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>.
Parameters
$textstring Required-
Text to check. Must be a tag like
<html>or[shortcode]. $stackstring[] Required-
Array of open tag elements.
$disabled_elementsstring[] Required-
Array of tag names to match against. Spaces are not allowed in tag names.
Source
File: wp-includes/formatting.php. View all references
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 );
}
}
}
Related
Used By
| Used By | Description |
|---|---|
| wptexturize() wp-includes/formatting.php | Replaces common plain text characters with formatted entities. |
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_wptexturize_pushpop_element