wp_staticize_emoji

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

WordPress Version: 6.5

/**
 * Converts emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (!str_contains($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (str_contains($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/15.0.3/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0] && str_contains($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (!str_contains($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 6.3

/**
 * Converts emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (!str_contains($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (str_contains($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/14.0.0/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0] && str_contains($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (!str_contains($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 6.1

/**
 * Converts emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/14.0.0/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.8

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/13.1.0/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.6

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/13.0.1/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.5

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/13.0.0/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.4

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/12.0.0-1/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block?
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters.
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.3

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            $possible_emoji[$emojum] = html_entity_decode($emojum);
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/12.0.0-1/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.2

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    $compat = version_compare(phpversion(), '5.4', '<');
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if ($compat) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/12.0.0-1/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 5.1

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    $compat = version_compare(phpversion(), '5.4', '<');
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if ($compat) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/11.2.0/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 9.8

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if (version_compare(phpversion(), '5.4', '<')) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/11/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 9.3

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if (version_compare(phpversion(), '5.4', '<')) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/2.4/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: .20

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if (version_compare(phpversion(), '5.4', '<')) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/11/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 9.2

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if (version_compare(phpversion(), '5.4', '<')) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/2.3/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: .10

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if (version_compare(phpversion(), '5.4', '<')) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/11/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 4.9

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    if (false === strpos($text, '&#x')) {
        if (function_exists('mb_check_encoding') && mb_check_encoding($text, 'ASCII') || !preg_match('/[^\x00-\x7F]/', $text)) {
            // The text doesn't contain anything that might be emoji, so we can return early.
            return $text;
        } else {
            $encoded_text = wp_encode_emoji($text);
            if ($encoded_text === $text) {
                return $encoded_text;
            }
            $text = $encoded_text;
        }
    }
    $emoji = _wp_emoji_list('entities');
    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    $possible_emoji = array();
    foreach ($emoji as $emojum) {
        if (false !== strpos($text, $emojum)) {
            if (version_compare(phpversion(), '5.4', '<')) {
                $possible_emoji[$emojum] = html_entity_decode($emojum, ENT_COMPAT, 'UTF-8');
            } else {
                $possible_emoji[$emojum] = html_entity_decode($emojum);
            }
        }
    }
    if (!$possible_emoji) {
        return $text;
    }
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/2.3/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0] && false !== strpos($content, '&#x')) {
            foreach ($possible_emoji as $emojum => $emoji_char) {
                if (false === strpos($content, $emojum)) {
                    continue;
                }
                $file = str_replace(';&#x', '-', $emojum);
                $file = str_replace(array('&#x', ';'), '', $file);
                $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char);
                $content = str_replace($emojum, $entity, $content);
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    // Finally, remove any stray U+FE0F characters
    $output = str_replace('&#xfe0f;', '', $output);
    return $output;
}

WordPress Version: 4.8

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    $text = wp_encode_emoji($text);
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/2.3/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0]) {
            $matches = array();
            if (preg_match_all('/(&#x1f1(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches)) {
                if (!empty($matches[0])) {
                    foreach ($matches[0] as $flag) {
                        $chars = str_replace(array('&#x', ';'), '', $flag);
                        list($char1, $char2) = str_split($chars, 5);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode($flag));
                        $content = str_replace($flag, $entity, $content);
                    }
                }
            }
            // Loosely match the Emoji Unicode range.
            $regex = '/(&#x[2-3][0-9a-f]{3};|&#x1f[1-6][0-9a-f]{2};)/';
            $matches = array();
            if (preg_match_all($regex, $content, $matches)) {
                if (!empty($matches[1])) {
                    foreach ($matches[1] as $emoji) {
                        $char = str_replace(array('&#x', ';'), '', $emoji);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode($emoji));
                        $content = str_replace($emoji, $entity, $content);
                    }
                }
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    return $output;
}

WordPress Version: 4.7

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    $text = wp_encode_emoji($text);
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/2.2.1/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0]) {
            $matches = array();
            if (preg_match_all('/(&#x1f1(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches)) {
                if (!empty($matches[0])) {
                    foreach ($matches[0] as $flag) {
                        $chars = str_replace(array('&#x', ';'), '', $flag);
                        list($char1, $char2) = str_split($chars, 5);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode($flag));
                        $content = str_replace($flag, $entity, $content);
                    }
                }
            }
            // Loosely match the Emoji Unicode range.
            $regex = '/(&#x[2-3][0-9a-f]{3};|&#x1f[1-6][0-9a-f]{2};)/';
            $matches = array();
            if (preg_match_all($regex, $content, $matches)) {
                if (!empty($matches[1])) {
                    foreach ($matches[1] as $emoji) {
                        $char = str_replace(array('&#x', ';'), '', $emoji);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode($emoji));
                        $content = str_replace($emoji, $entity, $content);
                    }
                }
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    return $output;
}

WordPress Version: 4.6

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    $text = wp_encode_emoji($text);
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/2/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0]) {
            $matches = array();
            if (preg_match_all('/(&#x1f1(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches)) {
                if (!empty($matches[0])) {
                    foreach ($matches[0] as $flag) {
                        $chars = str_replace(array('&#x', ';'), '', $flag);
                        list($char1, $char2) = str_split($chars, 5);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode($flag));
                        $content = str_replace($flag, $entity, $content);
                    }
                }
            }
            // Loosely match the Emoji Unicode range.
            $regex = '/(&#x[2-3][0-9a-f]{3};|&#x1f[1-6][0-9a-f]{2};)/';
            $matches = array();
            if (preg_match_all($regex, $content, $matches)) {
                if (!empty($matches[1])) {
                    foreach ($matches[1] as $emoji) {
                        $char = str_replace(array('&#x', ';'), '', $emoji);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode($emoji));
                        $content = str_replace($emoji, $entity, $content);
                    }
                }
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    return $output;
}

WordPress Version: .10

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    $text = wp_encode_emoji($text);
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', 'https://s.w.org/images/core/emoji/72x72/');
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0]) {
            $matches = array();
            if (preg_match_all('/(&#x1f1(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches)) {
                if (!empty($matches[0])) {
                    foreach ($matches[0] as $flag) {
                        $chars = str_replace(array('&#x', ';'), '', $flag);
                        list($char1, $char2) = str_split($chars, 5);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode($flag));
                        $content = str_replace($flag, $entity, $content);
                    }
                }
            }
            // Loosely match the Emoji Unicode range.
            $regex = '/(&#x[2-3][0-9a-f]{3};|&#x1f[1-6][0-9a-f]{2};)/';
            $matches = array();
            if (preg_match_all($regex, $content, $matches)) {
                if (!empty($matches[1])) {
                    foreach ($matches[1] as $emoji) {
                        $char = str_replace(array('&#x', ';'), '', $emoji);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode($emoji));
                        $content = str_replace($emoji, $entity, $content);
                    }
                }
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    return $output;
}

WordPress Version: 4.2

/**
 * Convert emoji to a static img element.
 *
 * @since 4.2.0
 *
 * @param string $text The content to encode.
 * @return string The encoded content.
 */
function wp_staticize_emoji($text)
{
    $text = wp_encode_emoji($text);
    /** This filter is documented in wp-includes/formatting.php */
    $cdn_url = apply_filters('emoji_url', set_url_scheme('//s.w.org/images/core/emoji/72x72/'));
    /** This filter is documented in wp-includes/formatting.php */
    $ext = apply_filters('emoji_ext', '.png');
    $output = '';
    /*
     * HTML loop taken from smiley function, which was taken from texturize function.
     * It'll never be consolidated.
     *
     * First, capture the tags as well as in between.
     */
    $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    // Ignore processing of specific tags.
    $tags_to_ignore = 'code|pre|style|script|textarea';
    $ignore_block_element = '';
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        // If we're in an ignore block, wait until we find its closing tag.
        if ('' == $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
            $ignore_block_element = $matches[1];
        }
        // If it's not a tag and not in ignore block.
        if ('' == $ignore_block_element && strlen($content) > 0 && '<' != $content[0]) {
            $matches = array();
            if (preg_match_all('/(&#x1f1(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches)) {
                if (!empty($matches[0])) {
                    foreach ($matches[0] as $flag) {
                        $chars = str_replace(array('&#x', ';'), '', $flag);
                        list($char1, $char2) = str_split($chars, 5);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode($flag));
                        $content = str_replace($flag, $entity, $content);
                    }
                }
            }
            // Loosely match the Emoji Unicode range.
            $regex = '/(&#x[2-3][0-9a-f]{3};|&#x1f[1-6][0-9a-f]{2};)/';
            $matches = array();
            if (preg_match_all($regex, $content, $matches)) {
                if (!empty($matches[1])) {
                    foreach ($matches[1] as $emoji) {
                        $char = str_replace(array('&#x', ';'), '', $emoji);
                        $entity = sprintf('<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode($emoji));
                        $content = str_replace($emoji, $entity, $content);
                    }
                }
            }
        }
        // Did we exit ignore block.
        if ('' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content) {
            $ignore_block_element = '';
        }
        $output .= $content;
    }
    return $output;
}