WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 4 months ago

#24430 new defect (bug)

inconsistent icon_dir/icon_dirs use in wp_mime_type_icon and wp_get_attachment_image_src

Reported by: dglingren Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: Media Keywords: has-patch
Focuses: Cc:
PR Number:

Description

/wp-includes/post.php function wp_mime_type_icon allows for multiple icon image directories by applying the "icon_dirs" filter:

if ( !is_array($icon_files) ) {
    $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
    $icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url('images/crystal') );
    $dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) );
    $icon_files = array();
    while ( $dirs ) {
    ...

However, /wp-includes/media.php function wp_get_attachment_image_src does not apply the "icon_dirs" filter:

if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
    $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
    $src_file = $icon_dir . '/' . wp_basename($src);
    @list($width, $height) = getimagesize($src_file);
}

The base filename is always combined with the default Wordress directory path and passed to getimagesize. This means that any additional directories will never be passed to getimagesize(), and an incorrect size or no size at all will be used for any icon image files not sourced from the WordPress default directory.

Attachments (1)

24430.diff (1.1 KB) - added by joostdekeijzer 5 years ago.
method now uses 'icon_files' cache created by wp_mime_type_icon

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
6 years ago

  • Component changed from Plugins to Media
  • Version changed from 3.5.1 to 2.5

Related: #20205

@joostdekeijzer
5 years ago

method now uses 'icon_files' cache created by wp_mime_type_icon

#2 @joostdekeijzer
5 years ago

  • Keywords has-patch added

Attached patch for this issue and fixed brace style

This ticket was mentioned in Slack in #core by joostdekeijzer. View the logs.


4 years ago

This ticket was mentioned in Slack in #core by jorbin. View the logs.


4 years ago

#5 @jorbin
4 years ago

  • Keywords reporter-feedback added

I'm not quite sure how to reproduce this based on the description. Some sample code and/or instructions would help here.

#6 @dglingren
4 years ago

  • Keywords reporter-feedback removed

Thank you for looking into this issue. To reproduce the problem:

  1. Create a directory and put an icon in it, e.g.,

/wp-content/plugins/media-library-assistant/images/crystal/pdf.png'

  1. Hook the 'ext2type' filter and add an association from a file type to the icon, e.g.,

array( 'pdf' => array ( 0 => 'pdf', )

  1. Hook the 'icon_dirs' filter and add the directory and url to the array, e.g.,

function mla_icon_dirs_filter( $path_uri_array ) {
$path_uri_array [ MLA_PLUGIN_PATH . 'images/crystal' ] = MLA_PLUGIN_URL . 'images/crystal';
return $path_uri_array;
}

wp_mime_type_icon() will find pdf.png in the added directory, but wp_get_attachment_image_src() will discard the path and look for the file in the WordPress default directory; " $src_file = $icon_dir . '/' . wp_basename($src); ".

I regret that the initial description was unclear, and if you need anything else I am happy to expand on the above.

#7 @joostdekeijzer
4 years ago

@jorbin alternatively you could install and enable https://wordpress.org/plugins/oembed-in-library/

Add and Vimeo or Youtube video (Media > oEmbed). Then go to the Media library in list mode. You should get an icon based on the mime type (Vimeo or Youtube logo) but you get an empty space (no icon).

Note: See TracTickets for help on using tickets.