get_allowed_mime_types

函数
get_allowed_mime_types ( $user = null )
参数
  • (int|WP_User) $user Optional. User to check. Defaults to current user.
    Required:
    Default: null
返回值
  • (string[]) Array of mime types keyed by the file extension regex corresponding to those types.
定义位置
相关方法
get_allowed_block_typesget_post_mime_typesget_post_mime_typeget_available_post_mime_typesget_allowed_themes
引入
2.8.6
弃用
-

get_allowed_mime_types: 这个函数返回一个允许上传文件的MIME类型数组。

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

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 the 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 );
}

常见问题

FAQs
查看更多 >