wp_ext2type

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

WordPress Version: 6.1

/**
 * Retrieves the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|void The file type, example: audio, video, document, spreadsheet, etc.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    $ext2type = wp_get_ext_types();
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts, true)) {
            return $type;
        }
    }
}

WordPress Version: 5.5

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|void The file type, example: audio, video, document, spreadsheet, etc.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    $ext2type = wp_get_ext_types();
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts, true)) {
            return $type;
        }
    }
}

WordPress Version: 4.6

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|void The file type, example: audio, video, document, spreadsheet, etc.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    $ext2type = wp_get_ext_types();
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
}

WordPress Version: 4.3

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|void The file type, example: audio, video, document, spreadsheet, etc.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    /**
     * Filter file type based on the extension name.
     *
     * @since 2.5.0
     *
     * @see wp_ext2type()
     *
     * @param array $ext2type Multi-dimensional array with extensions for a default set
     *                        of file types.
     */
    $ext2type = apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
}

WordPress Version: 4.2

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|null The file type, example: audio, video, document, spreadsheet, etc.
 *                     Null if not found.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    /**
     * Filter file type based on the extension name.
     *
     * @since 2.5.0
     *
     * @see wp_ext2type()
     *
     * @param array $ext2type Multi-dimensional array with extensions for a default set
     *                        of file types.
     */
    $ext2type = apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
    return null;
}

WordPress Version: 4.1

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|null The file type, example: audio, video, document, spreadsheet, etc.
 *                     Null if not found.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    /**
     * Filter file type based on the extension name.
     *
     * @since 2.5.0
     *
     * @see wp_ext2type()
     *
     * @param array $ext2type Multi-dimensional array with extensions for a default set
     *                        of file types.
     */
    $ext2type = apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
    return null;
}

WordPress Version: 4.0

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|null The file type, example: audio, video, document, spreadsheet, etc.
 *                     Null if not found.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    /**
     * Filter file type based on the extension name.
     *
     * @since 2.5.0
     *
     * @see wp_ext2type()
     *
     * @param array $ext2type Multi-dimensional array with extensions for a default set
     *                        of file types.
     */
    $ext2type = apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
    return null;
}

WordPress Version: 3.9

/**
 * Retrieve the file type based on the extension name.
 *
 * @since 2.5.0
 *
 * @param string $ext The extension to search.
 * @return string|null The file type, example: audio, video, document, spreadsheet, etc.
 *                     Null if not found.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    /**
     * Filter file type based on the extension name.
     *
     * @since 2.5.0
     *
     * @see wp_ext2type()
     *
     * @param array $ext2type Multi-dimensional array with extensions for a default set
     *                        of file types.
     */
    $ext2type = apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
    return null;
}

WordPress Version: 3.7

/**
 * Retrieve the file type based on the extension name.
 *
 * @package WordPress
 * @since 2.5.0
 * @uses apply_filters() Calls 'ext2type' hook on default supported types.
 *
 * @param string $ext The extension to search.
 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.
 */
function wp_ext2type($ext)
{
    $ext = strtolower($ext);
    $ext2type = apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
    foreach ($ext2type as $type => $exts) {
        if (in_array($ext, $exts)) {
            return $type;
        }
    }
    return null;
}