[wp-trac] [WordPress Trac] #35905: Filter to filter default smilies

WordPress Trac noreply at wordpress.org
Mon Feb 22 18:38:15 UTC 2016


#35905: Filter to filter default smilies
-----------------------------+-----------------------------
 Reporter:  pietergoosen     |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  General          |    Version:  4.4.2
 Severity:  normal           |   Keywords:
  Focuses:  ui               |
-----------------------------+-----------------------------
 My request comes from the following question on WPSE

 - [http://wordpress.stackexchange.com/q/218474/31545 Display different
 smiley when entering “:)”]

 At this stage, if we need to override a default smiley in the
 {{{smilies_init()}}} function, we need to modify the {{{$wpsmiliestrans}}}
 global. This is from the doc block of the {{{smilies_init()}}} function -
 [https://github.com/WordPress/WordPress/blob/ae2657dd32a273a5746354629252bb00c5df689f
 /wp-includes/functions.php#L3171 Source]


 {{{
 Plugins may override the default smiley list by setting the
 $wpsmiliestrans
 to an array, with the key the code the blogger types in and the value the
 image file.
 }}}


 Can we add a filter so that we make this filterable. There is really no
 need why we should alter global variables, it is messy and really hard to
 debug.

 Proposed syntax:


 {{{
 if ( !isset( $wpsmiliestrans ) ) {
         $wpsmiliestrans = apply_filters( 'smilies_trans', array(
         ':mrgreen:' => 'mrgreen.png',
         ':neutral:' => "\xf0\x9f\x98\x90",
         ':twisted:' => "\xf0\x9f\x98\x88",
           ':arrow:' => "\xe2\x9e\xa1",
           ':shock:' => "\xf0\x9f\x98\xaf",
           ':smile:' => 'simple-smile.png',
                 ':???:' => "\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:' => 'frownie.png',
                   '8-)' => "\xf0\x9f\x98\x8e",
                   '8-O' => "\xf0\x9f\x98\xaf",
                   ':-(' => 'frownie.png',
                   ':-)' => 'simple-smile.png',
                   ':-?' => "\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",
                    ':(' => 'frownie.png',
                    ':)' => 'simple-smile.png',
                    ':?' => "\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",
         ) );
 }
 }}}

 We can then use the filter as follow


 {{{
 add_filter( 'smilies_trans', function( $smilies )
 {
         $smilies[':)'] = "\xf0\x9f\x98\x8e";

         return $smilies;
 });
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35905>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list