wp_mime_type_icon

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

WordPress Version: 6.5

/**
 * Retrieves the icon for a MIME type or attachment.
 *
 * @since 2.1.0
 * @since 6.5.0 Added the `$preferred_ext` parameter.
 *
 * @param string|int $mime          MIME type or attachment ID.
 * @param string     $preferred_ext File format to prefer in return. Default '.png'.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0, $preferred_ext = '.png')
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            $post = get_post($mime);
            if ($post) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    $ext_type = wp_ext2type($ext);
                    if ($ext_type) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the array of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param string[] $uris Array of icon directory URIs keyed by directory absolute path.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            $all_icons = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                $dh = opendir($dir);
                if ($dh) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if (str_starts_with($file, '.')) {
                            continue;
                        }
                        $ext = strtolower(substr($file, -4));
                        if (!in_array($ext, array('.svg', '.png', '.gif', '.jpg'), true)) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $all_icons["{$dir}/{$file}"] = "{$uri}/{$file}";
                        if ($ext === $preferred_ext) {
                            $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                        }
                    }
                    closedir($dh);
                }
            }
            // If directory only contained icons of a non-preferred format, return those.
            if (empty($icon_files)) {
                $icon_files = $all_icons;
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 6.3

/**
 * Retrieves the icon for a MIME type or attachment.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            $post = get_post($mime);
            if ($post) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    $ext_type = wp_ext2type($ext);
                    if ($ext_type) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the array of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param string[] $uris Array of icon directory URIs keyed by directory absolute path.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                $dh = opendir($dir);
                if ($dh) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if (str_starts_with($file, '.')) {
                            continue;
                        }
                        $ext = strtolower(substr($file, -4));
                        if (!in_array($ext, array('.png', '.gif', '.jpg'), true)) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 6.1

/**
 * Retrieves the icon for a MIME type or attachment.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            $post = get_post($mime);
            if ($post) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    $ext_type = wp_ext2type($ext);
                    if ($ext_type) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the array of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param string[] $uris Array of icon directory URIs keyed by directory absolute path.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                $dh = opendir($dir);
                if ($dh) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if ('.' === substr($file, 0, 1)) {
                            continue;
                        }
                        $ext = strtolower(substr($file, -4));
                        if (!in_array($ext, array('.png', '.gif', '.jpg'), true)) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 5.5

/**
 * Retrieve the icon for a MIME type or attachment.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            $post = get_post($mime);
            if ($post) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    $ext_type = wp_ext2type($ext);
                    if ($ext_type) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the array of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param string[] $uris Array of icon directory URIs keyed by directory absolute path.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                $dh = opendir($dir);
                if ($dh) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if ('.' === substr($file, 0, 1)) {
                            continue;
                        }
                        $ext = strtolower(substr($file, -4));
                        if (!in_array($ext, array('.png', '.gif', '.jpg'), true)) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 5.4

/**
 * Retrieve the icon for a MIME type or attachment.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            $post = get_post($mime);
            if ($post) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    $ext_type = wp_ext2type($ext);
                    if ($ext_type) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the array of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param string[] $uris Array of icon directory URIs keyed by directory absolute path.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                $dh = opendir($dir);
                if ($dh) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 5.3

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            $post = get_post($mime);
            if ($post) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    $ext_type = wp_ext2type($ext);
                    if ($ext_type) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                $dh = opendir($dir);
                if ($dh) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 5.2

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = wp_basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon wp_basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', wp_basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 4.6

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filters the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filters the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filters the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filters the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 4.4

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filter the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filter the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filter the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filter the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 4.3

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filter the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filter the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filter the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            if (isset($types[$wilds[0]])) {
                $icon = $types[$wilds[0]];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break;
            }
        }
    }
    /**
     * Filter the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 4.2

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|bool Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filter the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filter the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filter the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            if (isset($types[$wilds[0]])) {
                $icon = $types[$wilds[0]];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break;
            }
        }
    }
    /**
     * Filter the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 4.0

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|bool Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filter the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filter the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filter the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        // Icon basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            if (isset($types[$wilds[0]])) {
                $icon = $types[$wilds[0]];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break;
            }
        }
    }
    /**
     * Filter the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 3.9

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|bool
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filter the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filter the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filter the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        // Icon basename - extension = MIME wildcard
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            if (isset($types[$wilds[0]])) {
                $icon = $types[$wilds[0]];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break;
            }
        }
    }
    /**
     * Filter the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}

WordPress Version: 3.7

/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|bool
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/crystal');
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/crystal'));
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== $file = readdir($dh)) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        // Icon basename - extension = MIME wildcard
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            if (isset($types[$wilds[0]])) {
                $icon = $types[$wilds[0]];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break;
            }
        }
    }
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
    // Last arg is 0 if function pass mime type.
}