convert_smilies

Convert text equivalent of smilies to images.

Description

(string) convert_smilies( (string) $text ); 

Will only convert smilies if the option use_smilies is true and the global used in the function isn't empty.

Returns (string)

Converted content with text smilies replaced with images.

Parameters (1)

0. $text (string)
Content to convert smilies from text.

Usage

  1. if ( !function_exists( 'convert_smilies' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // Content to convert smilies from text. 
  5. $text = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = convert_smilies($text); 
  9.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function convert_smilies( $text ) { 
  2. global $wp_smiliessearch; 
  3. $output = ''; 
  4. if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) { 
  5. // HTML loop taken from texturize function, could possible be consolidated 
  6. $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between 
  7. $stop = count( $textarr );// loop stuff 
  8.  
  9. // Ignore proessing of specific tags 
  10. $tags_to_ignore = 'code|pre|style|script|textarea'; 
  11. $ignore_block_element = ''; 
  12.  
  13. for ( $i = 0; $i < $stop; $i++ ) { 
  14. $content = $textarr[$i]; 
  15.  
  16. // If we're in an ignore block, wait until we find its closing tag 
  17. if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) { 
  18. $ignore_block_element = $matches[1]; 
  19.  
  20. // If it's not a tag and not in ignore block 
  21. if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) { 
  22. $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content ); 
  23.  
  24. // did we exit ignore block 
  25. if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) { 
  26. $ignore_block_element = ''; 
  27.  
  28. $output .= $content; 
  29. } else { 
  30. // return default text. 
  31. $output = $text; 
  32. return $output;