_wptexturize_pushpop_element

函数


_wptexturize_pushpop_element ( $text, $stack, $disabled_elements )
Access
Private
参数
  • (string)
    $text
    Text to check. Must be a tag like “ or `[shortcode]`.
    Required:
  • (string[])
    $stack
    Array of open tag elements.
    Required:
  • (string[])
    $disabled_elements
    Array of tag names to match against. Spaces are not allowed in tag names.
    Required:
定义位置
  • wp-includes/formatting.php
    , line 387
引入
2.9.0
弃用

Searches for disabled element tags. Pushes element to stack on tag open
and pops on tag close.

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 “.

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. 
) even if there was invalid nesting before that.
			 *
			 * Example: in the case 
sadsadasd"baba"

* "baba" won't be texturized.
*/

array_push( $stack, $tag );
} elseif ( end( $stack ) == $tag ) {
array_pop( $stack );
}
}
}

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。