#35905 closed enhancement (fixed)
Filter to filter default smilies
Reported by: | pietergoosen | Owned by: | pento |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Formatting | Keywords: | has-patch has-unit-tests |
Focuses: | ui | Cc: |
Description
My request comes from the following question on WPSE
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 - 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; });
Attachments (2)
Change History (10)
#1
@
9 years ago
- Component changed from General to Formatting
- Keywords needs-patch added
- Type changed from feature request to enhancement
#4
@
8 years ago
- Keywords needs-refresh needs-unit-tests added; dev-feedback removed
- Milestone changed from Awaiting Review to 4.7
- Version 4.4.2 deleted
Yeah, I'm cool with adding this.
Let's call the filter smilies
, there's no need for the wp_
prefix.
I'd also like to see a unit test for it.
#5
@
8 years ago
- Keywords has-unit-tests added; needs-refresh needs-unit-tests removed
Patch is updated and includes two unit tests.
Note: See
TracTickets for help on using
tickets.
That patch contain the filter
wp_smilies
and the PHPDoc section for it.