将笑脸代码转换为等效的图标图形文件。
原型
smilies_init()
描述
你可以通过转到写入设置屏幕并取消选中该框,或将“use_smilies”选项设置为false或删除该选项来关闭表情符号。
源文件
路径:wp-includes/functions.php
<?php
...
function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
if ( !isset( $wpsmiliestrans ) ) {
$wpsmiliestrans = array(
':mrgreen:' => 'mrgreen.png',
':neutral:' => "xf0x9fx98x90",
':twisted:' => "xf0x9fx98x88",
':arrow:' => "xe2x9exa1",
':shock:' => "xf0x9fx98xaf",
' ' => "xf0x9fx99x82",
':???:' => "xf0x9fx98x95",
' ' => "xf0x9fx98x8e",
':evil:' => "xf0x9fx91xbf",
' ' => "xf0x9fx98x80",
':idea:' => "xf0x9fx92xa1",
':oops:' => "xf0x9fx98xb3",
':razz:' => "xf0x9fx98x9b",
':roll:' => "xf0x9fx99x84",
' ' => "xf0x9fx98x89",
' ' => "xf0x9fx98xa5",
':eek:' => "xf0x9fx98xae",
':lol:' => "xf0x9fx98x86",
':mad:' => "xf0x9fx98xa1",
':sad:' => "xf0x9fx99x81",
'8-)' => "xf0x9fx98x8e",
'8-O' => "xf0x9fx98xaf",
':-(' => "xf0x9fx99x81",
':-)' => "xf0x9fx99x82",
':-?' => "xf0x9fx98x95",
':-D' => "xf0x9fx98x80",
':-P' => "xf0x9fx98x9b",
':-o' => "xf0x9fx98xae",
':-x' => "xf0x9fx98xa1",
':-|' => "xf0x9fx98x90",
';-)' => "xf0x9fx98x89",
// This one transformation breaks regular text with frequency.
// '8)' => "xf0x9fx98x8e",
'8O' => "xf0x9fx98xaf",
':(' => "xf0x9fx99x81",
':)' => "xf0x9fx99x82",
':?' => "xf0x9fx98x95",
':D' => "xf0x9fx98x80",
':P' => "xf0x9fx98x9b",
':o' => "xf0x9fx98xae",
':x' => "xf0x9fx98xa1",
':|' => "xf0x9fx98x90",
';)' => "xf0x9fx98x89",
':!:' => "xe2x9dx97",
':?:' => "xe2x9dx93",
);
}
/**
* Filters all the smilies.
*
* This filter must be added before `smilies_init` is run, as
* it is normally only run once to setup the smilies regex.
*
* @since 4.7.0
*
* @param array $wpsmiliestrans List of the smilies.
*/
$wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans);
if (count($wpsmiliestrans) == 0) {
return;
}
/*
* NOTE: we sort the smilies in reverse key order. This is to make sure
* we match the longest possible smilie (:???: vs :?) as the regular
* expression used below is first-match
*/
krsort($wpsmiliestrans);
$spaces = wp_spaces_regexp();
// Begin first "subpattern"
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$firstchar = substr($smiley, 0, 1);
$rest = substr($smiley, 1);
// new subpattern?
if ($firstchar != $subchar) {
if ($subchar != '') {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern"
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote($rest, '/');
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/smilies_init/