_wptexturize_pushpop_element

函数
_wptexturize_pushpop_element ( $text, $stack, $disabled_elements )
Access
Private
参数
  • (string) $text Text to check. Must be a tag like `<html>` 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:
定义位置
相关方法
wptexturize_primeswptexturize_wp_customize_publish_changesetwp_unschedule_event_wp_get_image_size_from_meta
引入
2.9.0
弃用
-

_wptexturize_pushpop_element: 当WordPress处理文本时,这个函数用于将元素”推”和”弹”到堆栈中。它被用来跟踪某些类型的标签(例如,开头和结尾的引号),以便它们可以被正确地替换成它们的印刷品。

搜索禁用的元素标签。在标签打开时将元素推入堆栈,在标签关闭时将元素弹出。

假设`$text’的第一个字符是标签打开,最后一个字符是标签关闭。假设`$text`的第二个字符是可选的`/`,表示关闭,如“。

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 );
		}
	}
}

常见问题

FAQs
查看更多 >