smilies_init

Convert smiley code to the icon graphic file equivalent.

Description

smilies_init(); 

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.


Usage

  1. if ( !function_exists( 'smilies_init' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = smilies_init(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function smilies_init() { 
  2. global $wpsmiliestrans, $wp_smiliessearch; 
  3.  
  4. // don't bother setting up smilies if they are disabled 
  5. if ( !get_option( 'use_smilies' ) ) 
  6. return; 
  7.  
  8. if ( !isset( $wpsmiliestrans ) ) { 
  9. $wpsmiliestrans = array( 
  10. ':mrgreen:' => 'mrgreen.png',  
  11. ':neutral:' => "\xf0\x9f\x98\x90",  
  12. ':twisted:' => "\xf0\x9f\x98\x88",  
  13. ':arrow:' => "\xe2\x9e\xa1",  
  14. ':shock:' => "\xf0\x9f\x98\xaf",  
  15. ':smile:' => "\xf0\x9f\x99\x82",  
  16. ':???:' => "\xf0\x9f\x98\x95",  
  17. ':cool:' => "\xf0\x9f\x98\x8e",  
  18. ':evil:' => "\xf0\x9f\x91\xbf",  
  19. ':grin:' => "\xf0\x9f\x98\x80",  
  20. ':idea:' => "\xf0\x9f\x92\xa1",  
  21. ':oops:' => "\xf0\x9f\x98\xb3",  
  22. ':razz:' => "\xf0\x9f\x98\x9b",  
  23. ':roll:' => "\xf0\x9f\x99\x84",  
  24. ':wink:' => "\xf0\x9f\x98\x89",  
  25. ':cry:' => "\xf0\x9f\x98\xa5",  
  26. ':eek:' => "\xf0\x9f\x98\xae",  
  27. ':lol:' => "\xf0\x9f\x98\x86",  
  28. ':mad:' => "\xf0\x9f\x98\xa1",  
  29. ':sad:' => "\xf0\x9f\x99\x81",  
  30. '8-)' => "\xf0\x9f\x98\x8e",  
  31. '8-O' => "\xf0\x9f\x98\xaf",  
  32. ':-(' => "\xf0\x9f\x99\x81",  
  33. ':-)' => "\xf0\x9f\x99\x82",  
  34. ':-?' => "\xf0\x9f\x98\x95",  
  35. ':-D' => "\xf0\x9f\x98\x80",  
  36. ':-P' => "\xf0\x9f\x98\x9b",  
  37. ':-o' => "\xf0\x9f\x98\xae",  
  38. ':-x' => "\xf0\x9f\x98\xa1",  
  39. ':-|' => "\xf0\x9f\x98\x90",  
  40. ';-)' => "\xf0\x9f\x98\x89",  
  41. // This one transformation breaks regular text with frequency. 
  42. // '8)' => "\xf0\x9f\x98\x8e",  
  43. '8O' => "\xf0\x9f\x98\xaf",  
  44. ':(' => "\xf0\x9f\x99\x81",  
  45. ':)' => "\xf0\x9f\x99\x82",  
  46. ':?' => "\xf0\x9f\x98\x95",  
  47. ':D' => "\xf0\x9f\x98\x80",  
  48. ':P' => "\xf0\x9f\x98\x9b",  
  49. ':o' => "\xf0\x9f\x98\xae",  
  50. ':x' => "\xf0\x9f\x98\xa1",  
  51. ':|' => "\xf0\x9f\x98\x90",  
  52. ';)' => "\xf0\x9f\x98\x89",  
  53. ':!:' => "\xe2\x9d\x97",  
  54. ':?:' => "\xe2\x9d\x93",  
  55. ); 
  56.  
  57. /** 
  58. * Filters all the smilies. 
  59. * This filter must be added before `smilies_init` is run, as 
  60. * it is normally only run once to setup the smilies regex. 
  61. * @since 4.7.0 
  62. * @param array $wpsmiliestrans List of the smilies. 
  63. */ 
  64. $wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans); 
  65.  
  66. if (count($wpsmiliestrans) == 0) { 
  67. return; 
  68.  
  69. /** 
  70. * NOTE: we sort the smilies in reverse key order. This is to make sure 
  71. * we match the longest possible smilie (:???: vs :?) as the regular 
  72. * expression used below is first-match 
  73. */ 
  74. krsort($wpsmiliestrans); 
  75.  
  76. $spaces = wp_spaces_regexp(); 
  77.  
  78. // Begin first "subpattern" 
  79. $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; 
  80.  
  81. $subchar = ''; 
  82. foreach ( (array) $wpsmiliestrans as $smiley => $img ) { 
  83. $firstchar = substr($smiley, 0, 1); 
  84. $rest = substr($smiley, 1); 
  85.  
  86. // new subpattern? 
  87. if ($firstchar != $subchar) { 
  88. if ($subchar != '') { 
  89. $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern" 
  90. $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern" 
  91. $subchar = $firstchar; 
  92. $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; 
  93. } else { 
  94. $wp_smiliessearch .= '|'; 
  95. $wp_smiliessearch .= preg_quote($rest, '/'); 
  96.  
  97. $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; 
  98.