Wenn Sie in WordPress :)
eingeben, wird dieser automatisch ersetzt durch:
Gibt es eine Möglichkeit, einen anderen Smiley für den :)
zu verwenden?
Die inhaltlichen Smilies werden konvertiert mit:
add_filter( 'the_content', 'convert_smilies' );
wo dieser Teil der Funktion convert_smilies()
von Bedeutung ist:
$content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
Wenn wir in translate_smiley()
hineinschauen, finden wir das folgende :
// Don't convert smilies that aren't images - they're probably emoji.
if ( ! in_array( $ext, $image_exts ) ) {
return $img;
}
bevor der smilies_src
filter angewendet wird.
Daher ist dieser Filter beim :)
smiley nicht verfügbar.
Wir haben die Smilies initialisiert mit:
add_action( 'init', 'smilies_init', 5 );
und in der Funktionsbeschreibung für smilies_init()
können wir lesen folgend :
Plugins können die Standard-Smiley-Liste überschreiben, indem sie den
$wpsmiliestrans
auf ein Array setzen, wobei der Schlüssel den Code, den der Blogger eingibt, und den Wert der Bilddatei enthält.
Hier ist das globale $wpsmiliestrans
Array:
$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",
);
oder das schönere ksortierte Display:
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-)] => ????
)
Wenn ich also den obigen Kernkommentar richtig verstehe, können wir Folgendes tun:
/**
* :) as the cool emoji
*/
add_action( 'init', function() use ( &$wpsmiliestrans )
{
if( is_array( $wpsmiliestrans ) && get_option( 'use_smilies' ) )
$wpsmiliestrans[':)'] = $wpsmiliestrans[':cool:'];
}, 6 );
dies funktioniert jedoch nur bei vordefinierten Smiley-Schlüsseln, damit der $wp_smiliessearch
funktioniert.
Aber ich mag diesen vorgeschlagenen Ansatz nicht, der das globale Array modifiziert! Hoffentlich gibt es noch einen besseren!
Ich habe versucht, einen Antrag dafür zu stellen. Ich bin mir nicht sicher, ob dies bereits existiert, aber hier ist es:
<?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 );
Dank Ismael Miguel für den globalen Kommentar habe ich die Snippets entsprechend umgeschrieben.
Hier ist das neu erstellte Ticket # 35905 von Pieter Goosen bezüglich eines neuen smilies_trans
Filters.
Der neue Filter wird verfügbar in WordPress 4.7+ sein, aber sein Name wird smilies
nicht smilies_trans
sein.
Unsere obigen Beispiele können wie folgt geschrieben werden:
add_filter( 'smilies', function( $smilies )
{
if( isset( $smilies[':cool:'] ) )
$smilies[':)'] = $smilies[':cool:'];
return $smilies;
} );
oder ausdrücklich mit:
add_filter( 'smilies', function( $smilies )
{
$smilies[':)'] = "\xf0\x9f\x98\x8e";
return $smilies;
} );
Das Demo-Plugin wird:
<?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;
} );
Wir müssen nicht mehr mit dem globalen $wpsmiliestrans
-Array herumspielen!
Laut dem WordPress Codex zur Verwendung von Smilies :
Laden Sie die gewünschten Bilder mit demselben Namen auf Ihren Server hoch (z. B. in wp-content/images/smilies) und fügen Sie dies in die function.php Ihres Themas ein:
add_filter ('smilies_src', 'my_custom_smilies_src', 10, 3); function my_custom_smilies_src ($ img_src, $ img, $ siteurl) { return $ siteurl. '/ wp-content/images/Smilies /'.$ img; }Das ersetzt http://example.com/wp-includes/images/smilies/icon_question.gif mit http://example.com/wp-content/images/smilies/ icon_question.gif