get_allowed_mime_types() WordPress Function

The get_allowed_mime_types() function is used to return a list of allowed mime types and file extensions. This can be useful for determining which file types are allowed to be uploaded to a WordPress site.

get_allowed_mime_types( int|WP_User $user = null ) #

Retrieve list of allowed mime types and file extensions.


Parameters

$user

(int|WP_User)(Optional) User to check. Defaults to current user.

Default value: null


Top ↑

Return

(string[]) Array of mime types keyed by the file extension regex corresponding to those types.


Top ↑

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.
	 * @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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.6Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More