convert_smilies

函数
convert_smilies ( $text )
参数
  • (string) $text Content to convert smilies from text.
    Required:
返回值
  • (string) Converted content with text smilies replaced with images.
定义位置
相关方法
convert_invalid_entitiesconvert_charsconvert_to_screencount_userswp_count_sites
引入
0.71
弃用
-

convert_smilies: 这个函数把文章或评论中的表情符号转换为它们的图形等价物,称为笑脸。例如,:)被转换为一个笑脸的图形。

将相当于笑脸的文本转换为图像。

只有当选项’use_smilies’为真,并且函数中使用的全局不是空时,才会转换笑脸。

function convert_smilies( $text ) {
	global $wp_smiliessearch;
	$output = '';
	if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
		// HTML loop taken from texturize function, could possible be consolidated.
		$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between.
		$stop    = count( $textarr ); // Loop stuff.

		// Ignore proessing of specific tags.
		$tags_to_ignore       = 'code|pre|style|script|textarea';
		$ignore_block_element = '';

		for ( $i = 0; $i < $stop; $i++ ) {
			$content = $textarr[ $i ];

			// If we're in an ignore block, wait until we find its closing tag.
			if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
				$ignore_block_element = $matches[1];
			}

			// If it's not a tag and not in ignore block.
			if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] ) {
				$content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
			}

			// Did we exit ignore block?
			if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
				$ignore_block_element = '';
			}

			$output .= $content;
		}
	} else {
		// Return default text.
		$output = $text;
	}
	return $output;
}

常见问题

FAQs
查看更多 >