translate_smiley

The timeline below displays how wordpress function translate_smiley has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Converts one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for convert_smilies().
 *
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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', 'avif');
    // 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));
}

WordPress Version: 6.3

/**
 * Converts one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for convert_smilies().
 *
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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));
}

WordPress Version: 6.1

/**
 * Converts one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for convert_smilies().
 *
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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));
}

WordPress Version: 5.8

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for convert_smilies().
 *
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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));
}

WordPress Version: 5.5

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for convert_smilies().
 *
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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');
    // 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));
}

WordPress Version: 4.6

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for convert_smilies().
 *
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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');
    // Don't convert smilies that aren't images - they're probably emoji.
    if (!in_array($ext, $image_exts)) {
        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));
}

WordPress Version: 4.3

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for {@link convert_smilies()}.
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @since 2.8.0
 *
 * @global array $wpsmiliestrans
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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');
    // Don't convert smilies that aren't images - they're probably emoji.
    if (!in_array($ext, $image_exts)) {
        return $img;
    }
    /**
     * Filter 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));
}

WordPress Version: 4.2

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for {@link convert_smilies()}.
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @global array $wpsmiliestrans
 * @since 2.8.0
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
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');
    // Don't convert smilies that aren't images - they're probably emoji.
    if (!in_array($ext, $image_exts)) {
        return $img;
    }
    /**
     * Filter 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));
}

WordPress Version: 4.1

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for {@link convert_smilies()}.
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * `<img>` string for that smiley.
 *
 * @global array $wpsmiliestrans
 * @since 2.8.0
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
function translate_smiley($matches)
{
    global $wpsmiliestrans;
    if (count($matches) == 0) {
        return '';
    }
    $smiley = trim(reset($matches));
    $img = $wpsmiliestrans[$smiley];
    /**
     * Filter 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" />', esc_url($src_url), esc_attr($smiley));
}

WordPress Version: 4.0

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for {@link convert_smilies()}.
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * <img> string for that smiley.
 *
 * @global array $wpsmiliestrans
 * @since 2.8.0
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
function translate_smiley($matches)
{
    global $wpsmiliestrans;
    if (count($matches) == 0) {
        return '';
    }
    $smiley = trim(reset($matches));
    $img = $wpsmiliestrans[$smiley];
    /**
     * Filter 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" />', esc_url($src_url), esc_attr($smiley));
}

WordPress Version: 3.8

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for {@link convert_smilies()}.
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * <img> string for that smiley.
 *
 * @global array $wpsmiliestrans
 * @since 2.8.0
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
function translate_smiley($matches)
{
    global $wpsmiliestrans;
    if (count($matches) == 0) {
        return '';
    }
    $smiley = trim(reset($matches));
    $img = $wpsmiliestrans[$smiley];
    /**
     * Filter 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" /> ', esc_url($src_url), esc_attr($smiley));
}

WordPress Version: 3.7

/**
 * Convert one smiley code to the icon graphic file equivalent.
 *
 * Callback handler for {@link convert_smilies()}.
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
 * <img> string for that smiley.
 *
 * @global array $wpsmiliestrans
 * @since 2.8.0
 *
 * @param array $matches Single match. Smiley code to convert to image.
 * @return string Image string for smiley.
 */
function translate_smiley($matches)
{
    global $wpsmiliestrans;
    if (count($matches) == 0) {
        return '';
    }
    $smiley = trim(reset($matches));
    $img = $wpsmiliestrans[$smiley];
    $smiley_masked = esc_attr($smiley);
    $src_url = apply_filters('smilies_src', includes_url("images/smilies/{$img}"), $img, site_url());
    return " <img src='{$src_url}' alt='{$smiley_masked}' class='wp-smiley' /> ";
}