Opened 8 years ago
Last modified 3 years ago
#36418 new defect (bug)
Custom MIME type icons lost in WP Media List view
Reported by: | jhorowitz | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | dev-feedback |
Focuses: | administration | Cc: |
Description
The ability to define custom MIME icons has been possible since at least v2.5, by hooking into several filters, one of which is icons_dir
.
icons_dir
allows you to specify additional directory/uri pairs for the wp_mime_type_icon
routine to search, ideally adding icon support for additional MIME types.
However, going through SVN history, it seems that almost from the beginning of the availability of that hook, there has been a loophole where the additional icon directories are ignored!
Specifically:
wp_get_attachment_image_src
calls wp_mime_type_icon
, which in theory could select a custom icon directory added by the icon_dirs
hook. It then attempts to fetch width and height information from the selected icon file, but only checks the default wp-includes/images/media directory. Of course, this prevents the custom icons from displaying when fetched through wp_get_attachment_image_src
.
Attachments (1)
Change History (5)
This ticket was mentioned in Slack in #core-media by desrosj. View the logs.
7 years ago
#4
@
3 years ago
This bug still exists if you try to load custom icon images by filtering wp_mime_type_icon
. They work fine in Grid view of the Media Library, but if you view as List, it ignores the custom path and tries to find them in the core media directory, throws PHP errors, and no image is loaded at all.
Here's an example I tried in functions.php of a custom theme. Works in Grid view, fails in List view.
<?php add_filter( 'wp_mime_type_icon', function( $icon, $mime, $post_id ) { if( 'text/plain' === $mime && $post_id > 0 ) $icon = get_template_directory_uri() . '/library/images/icons/txt.png'; if( 'application/pdf' === $mime && $post_id > 0 ) $icon = get_template_directory_uri() . '/library/images/icons/pdf.png'; return $icon; }, 10, 3 );
Patch to make wp_get_attachment_image_src check the same icon file directories as wp_mime_type_icon