Opened 10 years ago
Closed 10 years ago
#30788 closed defect (bug) (fixed)
Media library views: inconsistent behaviour with mime type groups
Reported by: | mdgl | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 4.0 |
Component: | Media | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description
Custom media type groups defined using the post_mime_types
filter are not displayed as filter options by the media library "list" view if the group contains multiple MIME types separated by a comma. Such groups are displayed correctly by the "grid" and other JavaScript views.
For example, if you add a custom media group Documents
for MIME types text/plain,application/pdf
, this is not listed as a filter option in "list" mode but does appear in the "grid" view.
If there is just a single MIME type in the group (e.g. text/plain
) it appears correctly in both views.
It appears that function wp_match_mime_types()
is not correctly matching against such comma-separated MIME type values.
Further inconsistencies occur in the naming and display of the groups. In "list" view, each group name is appropriately pluralised and suffixed with the count of matching items but this does not occur in the JavaScript views. In addition, the filter to display all items is named All
in "list" view but All media items
in the JavaScript views (English translation).
Attachments (4)
Change History (13)
#2
@
10 years ago
- Keywords reporter-feedback removed
Sample code for a plugin "Ticket 30788" attached. Activate and ensure you have at least one text or PDF file uploaded.
Browsing the media library in "grid" mode, or through the "Add Media" button on the post edit screen displays an additional filter category "Documents" that displays all text and PDF files.
The additional filter category does not appear when browsing the media library in "list" mode.
#3
@
10 years ago
- Version changed from 4.1 to 4.0
So wp_match_mime_types() is not matching correctly, but some other code is? Has this worked anywhere in WP prior to the addition of the grid in 4.0?
#4
@
10 years ago
So wp_match_mime_types() is not matching correctly, but some other code is?
Some other code??? Welcome to the wonderful world of WordPress media handling :-)
I ran up fresh copies of WP3.5.2 and WP3.9.3 today and the problem still occurs in both of those releases, although at that time the mime type groups are just displayed in a simple list rather than a drop down on the Media Library screen. Again the JavaScript code works correctly, as does the PHP if there is only a single MIME type in the group.
#5
@
10 years ago
- Keywords 2nd-opinion added
Patch uploaded which allows wp_match_mime_types()
to deal with an array of comma-separated MIME types (effectively a double nesting issue). This appears to fix this problem but the code here is quite convoluted and I would like a second opinion on this solution. It is also unclear to me why the original code added a third regular expression to match the main MIME type pattern un-anchored, so I have removed this.
Also, because the screen filter selection value may now include a comma, I had to revert to the original solution presented in #30123, namely using esc_attr()
rather than sanitize_mime_type()
when preparing links for the filter dropdown. This seems more correct in any case.
#6
@
10 years ago
I did a lot more testing and code review on this today and am now much more confident in the (updated) patch.
It turns out that wp_match_mime_types()
is also used to match what are effectively file names and types by function wp_mime_type_icon()
so I have added back the third (and un-anchored) regular expression to retain backwards compatibility. The existing code in wp_mime_type_icon()
looks a bit iffy to me and likely to return unexpected results in some situations, but that should be the subject of another ticket.
I have not addressed the issue of inconsistencies in labelling and numbering between the PHP and JavaScript views. Again, those are perhaps better dealt with on a separate ticket.
Hi mdgl, thanks for the report. Would it be possible for you to post a code example we could use to reproduce this issue?