get_allowed_mime_types( int|WP_User $user = null )
Retrieve list of allowed mime types and file extensions.
Description Description
Parameters Parameters
- $user
-
(int|WP_User) (Optional) User to check. Defaults to current user.
Default value: null
Return Return
(array) Array of mime types keyed by the file extension regex corresponding to those types.
Source Source
File: wp-includes/functions.php
function get_allowed_mime_types( $user = null ) {
$t = wp_get_mime_types();
unset( $t['swf'], $t['exe'] );
if ( function_exists( 'current_user_can' ) ) {
$unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
}
if ( empty( $unfiltered ) ) {
unset( $t['htm|html'], $t['js'] );
}
/**
* Filters list of allowed mime types and file extensions.
*
* @since 2.0.0
*
* @param array $t Mime types keyed by the file extension regex corresponding to
* those types. 'swf' and 'exe' removed from full list. 'htm|html' also
* removed depending on '$user' capabilities.
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
*/
return apply_filters( 'upload_mimes', $t, $user );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 2.8.6 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Function to retrieve the mime type icon of a file by its extension.
<?php /** * Get mime type icon URL based on file extension. * * @param $file_ext The file extension to get the icon for. * @return string Icon URL. */ function wpdocs_get_icon_by_file_extension($file_ext) { $mimes = get_allowed_mime_types(); if ( ! empty( $mimes ) ) { foreach ($ mimes as $type => $mime ) { if ( false !== strpos( $type, $file_ext ) ) { return wp_mime_type_icon($mime); } } } } ?> <img src="<?php echo esc_url( wpdocs_get_icon_by_file_extension( 'mp4' ) ); ?>" />Expand full source codeCollapse full source code