_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`的第二個字元是可選的`/`,表示關閉,如“。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
}
}
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 ); } } }
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
檢視更多 >