function wp_match_mime_types($wildcard_mime_types, $real_mime_types) {}

Check a MIME-Type against a list.
If the wildcard_mime_types parameter is a string, it must be comma separated list. If the real_mime_types is a string, it is also comma separated to create the list.


  • string|array $wildcard_mime_types: e.g. audio/mpeg or image (same as image/*) or flash (same as *flash*).
  • string|array $real_mime_types: post_mime_type values

Return values

returns:array(wildcard=>array(real types))

Source code

function wp_match_mime_types($wildcard_mime_types, $real_mime_types) {

	$matches = array();

	if ( is_string($wildcard_mime_types) )

		$wildcard_mime_types = array_map('trim', explode(',', $wildcard_mime_types));

	if ( is_string($real_mime_types) )

		$real_mime_types = array_map('trim', explode(',', $real_mime_types));

	$wild = '[-._a-z0-9]*';

	foreach ( (array) $wildcard_mime_types as $type ) {

		$type = str_replace('*', $wild, $type);

		$patternses[1][$type] = "^$type$";

		if ( false === strpos($type, '/') ) {

			$patternses[2][$type] = "^$type/";

			$patternses[3][$type] = $type;




	foreach ( $patternses as $patterns )

		foreach ( $patterns as $type => $pattern )

			foreach ( (array) $real_mime_types as $real )

				if ( preg_match("#$pattern#", $real) && ( empty($matches[$type]) || false === array_search($real, $matches[$type]) ) )

					$matches[$type][] = $real;

	return $matches;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: