Media: Fall back to available icons if SVG media icons not found.

Follow up to [57687]. If no icons of the preferred type are available, then the icon array should return the collection of valid icons found, rather than an empty array.

Props dglingren, sabernhardt, swissspidy, sabernhardt, antpb, joedolson.
Reviewed by swissspidy.
Merges [57845] to the 6.5 branch.
Fixes #60740.
Built from https://develop.svn.wordpress.org/branches/6.5@57846


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57347 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-03-15 20:58:12 +00:00
parent 8a78f7a907
commit d0997b8e96
2 changed files with 7 additions and 1 deletions

View File

@ -6868,6 +6868,7 @@ function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) {
*/
$dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) );
$icon_files = array();
$all_icons = array();
while ( $dirs ) {
$keys = array_keys( $dirs );
$dir = array_shift( $keys );
@ -6887,6 +6888,7 @@ function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) {
}
continue;
}
$all_icons[ "$dir/$file" ] = "$uri/$file";
if ( $ext === $preferred_ext ) {
$icon_files[ "$dir/$file" ] = "$uri/$file";
}
@ -6894,6 +6896,10 @@ function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) {
closedir( $dh );
}
}
// If directory only contained icons of a non-preferred format, return those.
if ( empty( $icon_files ) ) {
$icon_files = $all_icons;
}
wp_cache_add( 'icon_files', $icon_files, 'default', 600 );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5-RC2-57844';
$wp_version = '6.5-RC2-57846';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.