将等效于表情符号的文本转换为图像。

原型

convert_smilies( string $text )

描述

如果选项’use_smilies’为真且函数中使用的全局不为空,则仅转换表情符号。

参数

$text (string) (Required) 用于从文本转换表情符号的内容。

返回值

(string)  将文本表情符号替换为图像的已转换内容。

源文件

路径:wp-includes/formatting.php

<?php
...
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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/convert_smilies/