将一个笑脸代码转换为等效的图标图形文件。

原型

translate_smiley( array $matches )

描述

convert_smilies()的回调处理程序。

参数

$matches (array) (Required) 单场比赛。笑脸代码转换为图像。

返回值

(string)  笑脸的图像字符串。

源文件

路径:wp-includes/formatting.php

<?php
...
function translate_smiley( $matches ) {
	global $wpsmiliestrans;
	if ( count( $matches ) == 0 )
		return '';
	$smiley = trim( reset( $matches ) );
	$img = $wpsmiliestrans[ $smiley ];
	$matches = array();
	$ext = preg_match( '/.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;
	$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
	// Don't convert smilies that aren't images - they're probably emoji.
	if ( ! in_array( $ext, $image_exts ) ) {
		return $img;
	}
	/**
	 * Filters the Smiley image URL before it's used in the image element.
	 *
	 * @since 2.9.0
	 *
	 * @param string $smiley_url URL for the smiley image.
	 * @param string $img        Filename for the smiley image.
	 * @param string $site_url   Site URL, as returned by site_url().
	 */
	$src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
	return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );
}
...
?>

其他

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