On this page
translate_smiley( array $matches ): string
Converts one smiley code to the icon graphic file equivalent.
Description
Callback handler for convert_smilies() .
Looks up one smiley code in the $wpsmiliestrans global array and returns an <img> string for that smiley.
Parameters
$matchesarray Required-
Single match. Smiley code to convert to image.
Return
string Image string for smiley.
Source
File: wp-includes/formatting.php. View all references
function translate_smiley( $matches ) {
global $wpsmiliestrans;
if ( count( $matches ) == 0 ) {
return '';
}
$smiley = trim( reset( $matches ) );
$img = $wpsmiliestrans[ $smiley ];
$matches = array();
$ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;
$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' );
// Don't convert smilies that aren't images - they're probably emoji.
if ( ! in_array( $ext, $image_exts, true ) ) {
return $img;
}
/**
* Filters the Smiley image URL before it's used in the image element.
*
* @since 2.9.0
*
* @param string $smiley_url URL for the smiley image.
* @param string $img Filename for the smiley image.
* @param string $site_url Site URL, as returned by site_url().
*/
$src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );
}
Hooks
- apply_filters( 'smilies_src',
string $smiley_url ,string $img ,string $site_url ) -
Filters the Smiley image URL before it’s used in the image element.
Related
Uses
| Uses | Description |
|---|---|
| includes_url() wp-includes/link-template.php | Retrieves the URL to the includes directory. |
| site_url() wp-includes/link-template.php | Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
| esc_url() wp-includes/formatting.php | Checks and cleans a URL. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/translate_smiley