wp_staticize_emoji_for_email

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

WordPress Version: 6.3

/**
 * Converts emoji in emails into static images.
 *
 * @since 4.2.0
 *
 * @param array $mail The email data array.
 * @return array The email data array, with emoji in the message staticized.
 */
function wp_staticize_emoji_for_email($mail)
{
    if (!isset($mail['message'])) {
        return $mail;
    }
    /*
     * We can only transform the emoji into images if it's a `text/html` email.
     * To do that, here's a cut down version of the same process that happens
     * in wp_mail() - get the `Content-Type` from the headers, if there is one,
     * then pass it through the {@see 'wp_mail_content_type'} filter, in case
     * a plugin is handling changing the `Content-Type`.
     */
    $headers = array();
    if (isset($mail['headers'])) {
        if (is_array($mail['headers'])) {
            $headers = $mail['headers'];
        } else {
            $headers = explode("\n", str_replace("\r\n", "\n", $mail['headers']));
        }
    }
    foreach ($headers as $header) {
        if (!str_contains($header, ':')) {
            continue;
        }
        // Explode them out.
        list($name, $content) = explode(':', trim($header), 2);
        // Cleanup crew.
        $name = trim($name);
        $content = trim($content);
        if ('content-type' === strtolower($name)) {
            if (str_contains($content, ';')) {
                list($type, $charset) = explode(';', $content);
                $content_type = trim($type);
            } else {
                $content_type = trim($content);
            }
            break;
        }
    }
    // Set Content-Type if we don't have a content-type from the input headers.
    if (!isset($content_type)) {
        $content_type = 'text/plain';
    }
    /** This filter is documented in wp-includes/pluggable.php */
    $content_type = apply_filters('wp_mail_content_type', $content_type);
    if ('text/html' === $content_type) {
        $mail['message'] = wp_staticize_emoji($mail['message']);
    }
    return $mail;
}

WordPress Version: 6.1

/**
 * Converts emoji in emails into static images.
 *
 * @since 4.2.0
 *
 * @param array $mail The email data array.
 * @return array The email data array, with emoji in the message staticized.
 */
function wp_staticize_emoji_for_email($mail)
{
    if (!isset($mail['message'])) {
        return $mail;
    }
    /*
     * We can only transform the emoji into images if it's a `text/html` email.
     * To do that, here's a cut down version of the same process that happens
     * in wp_mail() - get the `Content-Type` from the headers, if there is one,
     * then pass it through the {@see 'wp_mail_content_type'} filter, in case
     * a plugin is handling changing the `Content-Type`.
     */
    $headers = array();
    if (isset($mail['headers'])) {
        if (is_array($mail['headers'])) {
            $headers = $mail['headers'];
        } else {
            $headers = explode("\n", str_replace("\r\n", "\n", $mail['headers']));
        }
    }
    foreach ($headers as $header) {
        if (strpos($header, ':') === false) {
            continue;
        }
        // Explode them out.
        list($name, $content) = explode(':', trim($header), 2);
        // Cleanup crew.
        $name = trim($name);
        $content = trim($content);
        if ('content-type' === strtolower($name)) {
            if (strpos($content, ';') !== false) {
                list($type, $charset) = explode(';', $content);
                $content_type = trim($type);
            } else {
                $content_type = trim($content);
            }
            break;
        }
    }
    // Set Content-Type if we don't have a content-type from the input headers.
    if (!isset($content_type)) {
        $content_type = 'text/plain';
    }
    /** This filter is documented in wp-includes/pluggable.php */
    $content_type = apply_filters('wp_mail_content_type', $content_type);
    if ('text/html' === $content_type) {
        $mail['message'] = wp_staticize_emoji($mail['message']);
    }
    return $mail;
}

WordPress Version: 5.9

/**
 * Convert emoji in emails into static images.
 *
 * @since 4.2.0
 *
 * @param array $mail The email data array.
 * @return array The email data array, with emoji in the message staticized.
 */
function wp_staticize_emoji_for_email($mail)
{
    if (!isset($mail['message'])) {
        return $mail;
    }
    /*
     * We can only transform the emoji into images if it's a `text/html` email.
     * To do that, here's a cut down version of the same process that happens
     * in wp_mail() - get the `Content-Type` from the headers, if there is one,
     * then pass it through the {@see 'wp_mail_content_type'} filter, in case
     * a plugin is handling changing the `Content-Type`.
     */
    $headers = array();
    if (isset($mail['headers'])) {
        if (is_array($mail['headers'])) {
            $headers = $mail['headers'];
        } else {
            $headers = explode("\n", str_replace("\r\n", "\n", $mail['headers']));
        }
    }
    foreach ($headers as $header) {
        if (strpos($header, ':') === false) {
            continue;
        }
        // Explode them out.
        list($name, $content) = explode(':', trim($header), 2);
        // Cleanup crew.
        $name = trim($name);
        $content = trim($content);
        if ('content-type' === strtolower($name)) {
            if (strpos($content, ';') !== false) {
                list($type, $charset) = explode(';', $content);
                $content_type = trim($type);
            } else {
                $content_type = trim($content);
            }
            break;
        }
    }
    // Set Content-Type if we don't have a content-type from the input headers.
    if (!isset($content_type)) {
        $content_type = 'text/plain';
    }
    /** This filter is documented in wp-includes/pluggable.php */
    $content_type = apply_filters('wp_mail_content_type', $content_type);
    if ('text/html' === $content_type) {
        $mail['message'] = wp_staticize_emoji($mail['message']);
    }
    return $mail;
}

WordPress Version: 4.2

/**
 * Convert emoji in emails into static images.
 *
 * @since 4.2.0
 *
 * @param array $mail The email data array.
 * @return array The email data array, with emoji in the message staticized.
 */
function wp_staticize_emoji_for_email($mail)
{
    if (!isset($mail['message'])) {
        return $mail;
    }
    /*
     * We can only transform the emoji into images if it's a text/html email.
     * To do that, here's a cut down version of the same process that happens
     * in wp_mail() - get the Content-Type from the headers, if there is one,
     * then pass it through the wp_mail_content_type filter, in case a plugin
     * is handling changing the Content-Type.
     */
    $headers = array();
    if (isset($mail['headers'])) {
        if (is_array($mail['headers'])) {
            $headers = $mail['headers'];
        } else {
            $headers = explode("\n", str_replace("\r\n", "\n", $mail['headers']));
        }
    }
    foreach ($headers as $header) {
        if (strpos($header, ':') === false) {
            continue;
        }
        // Explode them out.
        list($name, $content) = explode(':', trim($header), 2);
        // Cleanup crew.
        $name = trim($name);
        $content = trim($content);
        if ('content-type' === strtolower($name)) {
            if (strpos($content, ';') !== false) {
                list($type, $charset) = explode(';', $content);
                $content_type = trim($type);
            } else {
                $content_type = trim($content);
            }
            break;
        }
    }
    // Set Content-Type if we don't have a content-type from the input headers.
    if (!isset($content_type)) {
        $content_type = 'text/plain';
    }
    /** This filter is documented in wp-includes/pluggable.php */
    $content_type = apply_filters('wp_mail_content_type', $content_type);
    if ('text/html' === $content_type) {
        $mail['message'] = wp_staticize_emoji($mail['message']);
    }
    return $mail;
}