搜索已禁用的元素标记。推送元素在标签打开时堆叠并在标签关闭时弹出。
原型
_wptexturize_pushpop_element( string $text, array $stack, array $disabled_elements )
描述
假设$ text的第一个char是标记打开,最后一个char是标记结束。假设$ text的第二个字符可选地为’/‘以表示关闭。
参数
$text
(string)
(Required)
要检查的文字。必须是或[shortcode]之类的标签。
$stack
(array)
(Required)
开放标签元素列表。
$disabled_elements
(array)
(Required)
要匹配的标记名称。标签名称中不允许使用空格。
源文件
路径:wp-includes/formatting.php
<?php
...
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 ) ) {
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 texturize
*/
array_push( $stack, $tag );
} elseif ( end( $stack ) == $tag ) {
array_pop( $stack );
}
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/_wptexturize_pushpop_element/