将:)的表情符号改写为
内容表情将通过以下方式转换:
add_filter( \'the_content\', \'convert_smilies\' );
 在哪里
this part 的
convert_smilies() 功能很重要:
$content = preg_replace_callback( $wp_smiliessearch, \'translate_smiley\', $content );
 如果我们偷看
translate_smiley() 然后我们找到
following:
// Don\'t convert smilies that aren\'t images - they\'re probably emoji.
if ( ! in_array( $ext, $image_exts ) ) {
     return $img;
}
 在
smilies_src 应用过滤器。
因此,在:) 笑脸。
我们已使用以下命令初始化笑脸:
add_action( \'init\', \'smilies_init\', 5 );
 在功能描述中
smilies_init() 我们可以阅读
following:
插件可以通过设置$wpsmiliestrans  对于数组,使用blogger键入的代码键和图像文件的值。
这是全球$wpsmiliestrans 阵列:
$wpsmiliestrans = array(
    \':mrgreen:\' => \'mrgreen.png\',
    \':neutral:\' => "\\xf0\\x9f\\x98\\x90",
    \':twisted:\' => "\\xf0\\x9f\\x98\\x88",
    \':arrow:\' => "\\xe2\\x9e\\xa1",
    \':shock:\' => "\\xf0\\x9f\\x98\\xaf",
    \':smile:\' => "\\xf0\\x9f\\x99\\x82",
    \':???:\' => "\\xf0\\x9f\\x98\\x95",
    \':cool:\' => "\\xf0\\x9f\\x98\\x8e",
    \':evil:\' => "\\xf0\\x9f\\x91\\xbf",
    \':grin:\' => "\\xf0\\x9f\\x98\\x80",
    \':idea:\' => "\\xf0\\x9f\\x92\\xa1",
    \':oops:\' => "\\xf0\\x9f\\x98\\xb3",
    \':razz:\' => "\\xf0\\x9f\\x98\\x9b",
    \':roll:\' => \'rolleyes.png\',
    \':wink:\' => "\\xf0\\x9f\\x98\\x89",
    \':cry:\' => "\\xf0\\x9f\\x98\\xa5",
    \':eek:\' => "\\xf0\\x9f\\x98\\xae",
    \':lol:\' => "\\xf0\\x9f\\x98\\x86",
    \':mad:\' => "\\xf0\\x9f\\x98\\xa1",
    \':sad:\' => "\\xf0\\x9f\\x99\\x81",
    \'8-)\' => "\\xf0\\x9f\\x98\\x8e",
    \'8-O\' => "\\xf0\\x9f\\x98\\xaf",
    \':-(\' => "\\xf0\\x9f\\x99\\x81",
    \':-)\' => "\\xf0\\x9f\\x99\\x82",
    \':-?\' => "\\xf0\\x9f\\x98\\x95",
    \':-D\' => "\\xf0\\x9f\\x98\\x80",
    \':-P\' => "\\xf0\\x9f\\x98\\x9b",
    \':-o\' => "\\xf0\\x9f\\x98\\xae",
    \':-x\' => "\\xf0\\x9f\\x98\\xa1",
    \':-|\' => "\\xf0\\x9f\\x98\\x90",
    \';-)\' => "\\xf0\\x9f\\x98\\x89",
    // This one transformation breaks regular text with frequency.
    //     \'8)\' => "\\xf0\\x9f\\x98\\x8e",
    \'8O\' => "\\xf0\\x9f\\x98\\xaf",
    \':(\' => "\\xf0\\x9f\\x99\\x81",
    \':)\' => "\\xf0\\x9f\\x99\\x82",
    \':?\' => "\\xf0\\x9f\\x98\\x95",
    \':D\' => "\\xf0\\x9f\\x98\\x80",
    \':P\' => "\\xf0\\x9f\\x98\\x9b",
    \':o\' => "\\xf0\\x9f\\x98\\xae",
    \':x\' => "\\xf0\\x9f\\x98\\xa1",
    \':|\' => "\\xf0\\x9f\\x98\\x90",
    \';)\' => "\\xf0\\x9f\\x98\\x89",
    \':!:\' => "\\xe2\\x9d\\x97",
    \':?:\' => "\\xe2\\x9d\\x93",
);
 或更好的K排序显示:
Array
(
    [;-)] => 
    [;)] => 
    [:|] => 
    [:x] => 
    [:wink:] => 
    [:twisted:] => 
    [:smile:] => 
    [:shock:] => 
    [:sad:] => 
    [:roll:] => rolleyes.png
    [:razz:] => 
    [:oops:] => 
    [:o] => 
    [:neutral:] => 
    [:mrgreen:] => mrgreen.png
    [:mad:] => 
    [:lol:] => 
    [:idea:] => 
    [:grin:] => 
    [:evil:] => 
    [:eek:] => 
    [:cry:] => 
    [:cool:] => 
    [:arrow:] => ➡
    [:P] => 
    [:D] => 
    [:???:] => 
    [:?:] => ❓
    [:?] => 
    [:-|] => 
    [:-x] => 
    [:-o] => 
    [:-P] => 
    [:-D] => 
    [:-?] => 
    [:-)] => 
    [:-(] => 
    [:)] => 
    [:(] => 
    [:!:] => ❗
    [8O] => 
    [8-O] => 
    [8-)] => 
)
 因此,如果我正确理解上述核心意见,那么我们可以做以下工作:
/**
 * :) as the cool emoji
 */
add_action( \'init\', function() use ( &$wpsmiliestrans )
{
    if( is_array( $wpsmiliestrans ) && get_option( \'use_smilies\' ) )
        $wpsmiliestrans[\':)\'] = $wpsmiliestrans[\':cool:\'];
}, 6 );
 但这只适用于预定义的笑脸键
$wp_smiliessearch 工作。
但我不喜欢这种建议的方法,修改全局数组!希望还有更好的
演示插件-
我试着为它设计一个应用程序。我不确定这是否已经存在,但它在这里:
<?php
/**
 * Plugin Name: Santa\'s Smile In December
 * Description: Change the emoji of :) to the Santa Claus emoji, but only in December
 * Plugin URI:  https://wordpress.stackexchange.com/a/218496/26350
 */
add_action( \'init\', function() use ( &$wpsmiliestrans )
{
    // :) as Santa Claus
    if( 
           is_array( $wpsmiliestrans ) 
        && get_option( \'use_smilies\' ) 
        && 12 == current_time( \'n\' ) 
    )
        $wpsmiliestrans[\':)\'] = "\\xF0\\x9F\\x8E\\x85";
}, 6 );
 感谢
Ismael Miguel 对于全球
comment, 我相应地重写了片段。
这是newly created 票#35905 通过Pieter Goosen, 关于新的smilies_trans 滤器
更新-WordPress 4.7+
新过滤器将
available 在WordPress 4.7+,但它的名称将是
smilies 不
smilies_trans.
我们上面的例子可以写成:
add_filter( \'smilies\', function( $smilies )
{
    if( isset( $smilies[\':cool:\'] ) )
        $smilies[\':)\'] = $smilies[\':cool:\'];
    return $smilies;
} );
 或明确使用:
add_filter( \'smilies\', function( $smilies )
{
    $smilies[\':)\'] = "\\xf0\\x9f\\x98\\x8e";
    return $smilies;
} );
 演示插件变成:
<?php
/**
 * Plugin Name: Santa\'s Smile In December
 * Description: Change the emoji of :) to the Santa Claus emoji, but only in December
 * Plugin URI:  https://wordpress.stackexchange.com/a/218496/26350
 */
add_filter( \'smilies\', function( $smilies )
{
    // :) as Santa Claus
    if( get_option( \'use_smilies\' ) && 12 == current_time( \'n\' ) )
        $smilies[\':)\'] = "\\xF0\\x9F\\x8E\\x85";
    return $smilies;
} );
 我们不需要和全球
$wpsmiliestrans 阵列不再存在!