smilies_init()
Convert smiley code to the icon graphic file equivalent.
Description Description
You can turn off smilies, by going to the write setting screen and unchecking the box, or by setting ‘use_smilies’ option to false or removing the option.
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.
The $wp_smiliessearch global is for the regular expression and is set each time the function is called.
The full list of smilies can be found in the function and won’t be listed in the description. Probably should create a Codex page for it, so that it is available.
Source Source
File: wp-includes/functions.php
3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 | function smilies_init() { global $wpsmiliestrans , $wp_smiliessearch ; // don't bother setting up smilies if they are disabled if ( ! get_option( 'use_smilies' ) ) { return ; } if ( ! isset( $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:' => "\xf0\x9f\x99\x84" , ':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" , ); } /** * Filters all the smilies. * * This filter must be added before `smilies_init` is run, as * it is normally only run once to setup the smilies regex. * * @since 4.7.0 * * @param array $wpsmiliestrans List of the smilies. */ $wpsmiliestrans = apply_filters( 'smilies' , $wpsmiliestrans ); if ( count ( $wpsmiliestrans ) == 0 ) { return ; } /* * NOTE: we sort the smilies in reverse key order. This is to make sure * we match the longest possible smilie (:???: vs :?) as the regular * expression used below is first-match */ krsort( $wpsmiliestrans ); $spaces = wp_spaces_regexp(); // Begin first "subpattern" $wp_smiliessearch = '/(?<=' . $spaces . '|^)' ; $subchar = '' ; foreach ( ( array ) $wpsmiliestrans as $smiley => $img ) { $firstchar = substr ( $smiley , 0, 1 ); $rest = substr ( $smiley , 1 ); // new subpattern? if ( $firstchar != $subchar ) { if ( $subchar != '' ) { $wp_smiliessearch .= ')(?=' . $spaces . '|$)' ; // End previous "subpattern" $wp_smiliessearch .= '|(?<=' . $spaces . '|^)' ; // Begin another "subpattern" } $subchar = $firstchar ; $wp_smiliessearch .= preg_quote( $firstchar , '/' ) . '(?:' ; } else { $wp_smiliessearch .= '|' ; } $wp_smiliessearch .= preg_quote( $rest , '/' ); } $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m' ; } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.2.0 | Introduced. |