Yanıtlar:
İçerik ifadeleri şu şekilde dönüştürülür:
add_filter( 'the_content', 'convert_smilies' );
nerede bu bölüm içinde convert_smilies()işlevinin önem taşımaktadır:
$content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
Eğer göz atarsak aşağıdakileritranslate_smiley() buluruz :
// Don't convert smilies that aren't images - they're probably emoji.
if ( ! in_array( $ext, $image_exts ) ) {
return $img;
}
smilies_srcfiltre uygulanmadan önce .
Yani bu filtre :)gülen yüz için mevcut değildir .
İfadeler şu şekilde başlatıldı:
add_action( 'init', 'smilies_init', 5 );
ve fonksiyon açıklaması içinde aşağıdakilerismilies_init() okuyabiliriz :
Eklentiler
$wpsmiliestrans, blogger'ın yazdığı kod ve resim dosyası değeri ile bir diziye ayarlanarak varsayılan gülen yüz listesini geçersiz kılabilir .
İşte küresel $wpsmiliestransdizi:
$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",
);
veya daha güzel ksorted ekran:
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-)] => 😎
)
Yukarıdaki temel yorumu doğru bir şekilde anlarsam, aşağıdakileri yapabiliriz:
/**
* :) as the cool emoji
*/
add_action( 'init', function() use ( &$wpsmiliestrans )
{
if( is_array( $wpsmiliestrans ) && get_option( 'use_smilies' ) )
$wpsmiliestrans[':)'] = $wpsmiliestrans[':cool:'];
}, 6 );
ancak bu yalnızca önceden tanımlanmış smiley anahtarları $wp_smiliessearchiçin işe yarar.
Ama bu önerilen yaklaşımı sevmiyorum, küresel diziyi değiştiriyorum! Umarım başka bir tane daha vardır!
Bunun için bir uygulama bulmaya çalıştım. Bunun zaten var olup olmadığından emin değilim, ama işte burada:
<?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 );
Küresel yorum için Ismael Miguel'e teşekkürler , parçacıkları buna göre yeniden yazdım.
İşte Pieter Goosen tarafından yeni bir filtre ile ilgili yeni oluşturulan # 35905 bileti .smilies_trans
Yeni filtre olacak mevcut 4.7+ WordPress, ama onun adı olacaktır smiliesdeğildir smilies_trans.
Yukarıdaki örneklerimiz şöyle yazılabilir:
add_filter( 'smilies', function( $smilies )
{
if( isset( $smilies[':cool:'] ) )
$smilies[':)'] = $smilies[':cool:'];
return $smilies;
} );
veya açıkça:
add_filter( 'smilies', function( $smilies )
{
$smilies[':)'] = "\xf0\x9f\x98\x8e";
return $smilies;
} );
Demo eklentisi:
<?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;
} );
$wpsmiliestransArtık küresel dizi ile uğraşmak zorunda değiliz!
add_action( 'init', function() use (&$wpsmiliestrans){ $wpsmiliestrans[':)'] = "\xf0\x9f\x98\x8e"; }, 6 );?
useburada cevaplarımda anahtar kelimeyi çok kullanıyorum , ancak küreseller ile ilgili iyi bir hatırlatma, tekrar teşekkürler (:) <- belki herkes için daha iyi erişilebilirlik için simetrik bir gülen yüz kullanabiliriz @IsmaelMiguel
İfadeleri kullanma konusunda WordPress Codex'a göre :
Aynı ada sahip istediğiniz resimleri sunucunuza yükleyin (wp-content / images / smilies şeklinde söyleyin) ve bunu temanızın işlevine yerleştirin. Php:
add_filter ('smilies_src', 'my_custom_smilies_src', 10, 3); işlev my_custom_smilies_src ($ img_src, $ img, $ siteurl) { $ siteurl. '/ wp-content / images / smilies /'.$ img; }Yani yerini alacak http://example.com/wp-includes/images/smilies/icon_question.gif ile http://example.com/wp-content/images/smilies/icon_question.gif
3ayarlayarak, 1gibi kod başarısız olur $img, $siteurlgöz ardı edilir ve bunun filtrenizde :-) tanımlanmamış edilecek