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/post.php

    r57644 r57687  
    68046804 * @since 2.1.0
    68056805 *
    6806  * @param string|int $mime MIME type or attachment ID.
     6806 * @param string|int $mime          MIME type or attachment ID.
     6807 * @param string     $preferred_ext File format to prefer in return. Default .png.
    68076808 * @return string|false Icon, false otherwise.
    68086809 */
    6809 function wp_mime_type_icon( $mime = 0 ) {
     6810function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) {
    68106811    if ( ! is_numeric( $mime ) ) {
    68116812        $icon = wp_cache_get( "mime_type_icon_$mime" );
     
    68866887                            continue;
    68876888                        }
    6888                         $icon_files[ "$dir/$file" ] = "$uri/$file";
     6889                        if ( $ext === $preferred_ext ) {
     6890                            $icon_files[ "$dir/$file" ] = "$uri/$file";
     6891                        }
    68896892                    }
    68906893                    closedir( $dh );
Note: See TracChangeset for help on using the changeset viewer.