[wp-trac] [WordPress Trac] #16635: Handle grouped MIME-Types
WordPress Trac
wp-trac at lists.automattic.com
Thu Feb 24 13:41:14 UTC 2011
#16635: Handle grouped MIME-Types
------------------------------+-----------------------------
Reporter: sergiu.paraschiv | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 3.1
Severity: minor | Keywords: has-patch
------------------------------+-----------------------------
I'm trying to add a filter in the Media Library for common archive file
types. The problem is that there are a lot of MIME-Types for archive files
and none have a common prefix. Wildcards are not a solution here.
POC:
{{{
add_filter('post_mime_types', 'modify_post_mime_types');
function modify_post_mime_types($post_mime_types) {
$type = 'application/zip,application/x-tar';
$labels = array(
__('Archive'),
__('Manage Archives'),
__ngettext_noop('Archive <span class="count">(%s)</span>',
'Archives <span class="count">(%s)</span>')
);
$post_mime_types[$type] = $labels;
return $post_mime_types;
}
}}}
I've tried using "|" (regexp) as a separator:
{{{
$type = 'application/zip|application/x-tar';
}}}
This works ok in wp_match_mime_types but fails in wp_post_mime_type_where.
I've found two possible solutions:
1) Change
{{{
$post_mime_types = array_map('trim', explode(',', $post_mime_types));
}}}
to
{{{
$post_mime_types = array_map('trim', preg_split('/,|\|/',
$post_mime_types));
}}}
in wp_post_mime_type_where and use "|" as a separator;
2) Handle this in wp_match_mime_type (see code in attached file) and use
"," as a separator.
I'm aware that this is not a widely used filter but in my case this
enhancement makes a lot of sense. If it works for images why shouldn't it
work for archives? Also, why is wp_post_mime_type_where designed for
comma-separated lists of MIME-Types if it's never used that way?
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16635>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list