检索允许的mime类型和文件扩展名列表。

原型

get_allowed_mime_types( int|WP_User $user = null )

参数

$user (int|WP_User) (Optional)  用户检查。默认为当前用户。

返回值

(array)  由与这些类型对应的文件扩展名正则表达式键入的mime类型数组。

源文件

路径:wp-includes/functions.php

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

其他

英文文档:https://developer.wordpress.org/reference/functions/get_allowed_mime_types/