Make WordPress Core


Ignore:
Timestamp:
02/21/2024 07:25:18 PM (7 months ago)
Author:
joedolson
Message:

Media: Ensure wp_mine_type_icon() returns expected file type.

Add an argument to wp_mime_type_icon() to control the file type returned. Following [57638], there are two file formats in the media icons directory. Different systems would pull up different files by default dependent on the order loaded into the cached array, causing intermittent test failures and unpredictable behavior.

Function update allows core usages to always return the .svg while maintaining backwards compatibility for any extended usage that expects a .png. Follow up to [57638].

Also handles a missed case in media list view.

Props SergeyBiryukov, sabernhardt, joedolson, antpb.
Fixes #31352.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r57597 r57687  
    973973
    974974        if ( $icon ) {
    975             $src = wp_mime_type_icon( $attachment_id );
     975            $src = wp_mime_type_icon( $attachment_id, '.svg' );
    976976
    977977            if ( $src ) {
     
    979979                $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
    980980
    981                 $src_file               = $icon_dir . '/' . wp_basename( $src );
     981                $src_file = $icon_dir . '/' . wp_basename( $src );
    982982                list( $width, $height ) = wp_getimagesize( $src_file );
     983                $ext      = strtolower( substr( $src_file, -4 ) );
     984                if ( '.svg' === $ext ) {
     985                    // SVG does not have true dimensions, so this assigns width and height directly.
     986                    $width  = 48;
     987                    $height = 64;
     988                } else {
     989                    list( $width, $height ) = wp_getimagesize( $src_file );
     990                }
    983991            }
    984992        }
     
    30683076                $track['thumb']               = compact( 'src', 'width', 'height' );
    30693077            } else {
    3070                 $src            = wp_mime_type_icon( $attachment->ID );
     3078                $src            = wp_mime_type_icon( $attachment->ID, '.svg' );
    30713079                $width          = 48;
    30723080                $height         = 64;
     
    43404348        'type'          => $type,
    43414349        'subtype'       => $subtype,
    4342         'icon'          => wp_mime_type_icon( $attachment->ID ),
     4350        'icon'          => wp_mime_type_icon( $attachment->ID, '.svg' ),
    43434351        'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ),
    43444352        'nonces'        => array(
     
    45114519            $response['thumb']            = compact( 'src', 'width', 'height' );
    45124520        } else {
    4513             $src               = wp_mime_type_icon( $attachment->ID );
     4521            $src               = wp_mime_type_icon( $attachment->ID, '.svg' );
    45144522            $width             = 48;
    45154523            $height            = 64;
Note: See TracChangeset for help on using the changeset viewer.