translate_smiley

Convert one smiley code to the icon graphic file equivalent.

Description

(string) translate_smiley( (array) $matches ); 

Callback handler for convert_smilies().

Looks up one smiley code in the $wpsmiliestrans global array and returns an '' string for that smiley.

Returns (string)

Image string for smiley.

Parameters (1)

0. $matches (array)
Single match. Smiley code to convert to image.

Usage

  1. if ( !function_exists( 'translate_smiley' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // Single match. Smiley code to convert to image. 
  5. $matches = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = translate_smiley($matches); 
  9.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function translate_smiley( $matches ) { 
  2. global $wpsmiliestrans; 
  3.  
  4. if ( count( $matches ) == 0 ) 
  5. return ''; 
  6.  
  7. $smiley = trim( reset( $matches ) ); 
  8. $img = $wpsmiliestrans[ $smiley ]; 
  9.  
  10. $matches = array(); 
  11. $ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false; 
  12. $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); 
  13.  
  14. // Don't convert smilies that aren't images - they're probably emoji. 
  15. if ( ! in_array( $ext, $image_exts ) ) { 
  16. return $img; 
  17.  
  18. /** 
  19. * Filters the Smiley image URL before it's used in the image element. 
  20. * @since 2.9.0 
  21. * @param string $smiley_url URL for the smiley image. 
  22. * @param string $img Filename for the smiley image. 
  23. * @param string $site_url Site URL, as returned by site_url(). 
  24. */ 
  25. $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() ); 
  26.  
  27. return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );