From c6c7d5080a03d82efe75b3068a166b84cf05c427 Mon Sep 17 00:00:00 2001 From: joedolson Date: Fri, 15 Mar 2024 16:37:11 +0000 Subject: [PATCH] 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 sabernhardt, swissspidy, sabernhardt, antpb, joedolson. Fixes #60740. Built from https://develop.svn.wordpress.org/trunk@57845 git-svn-id: http://core.svn.wordpress.org/trunk@57346 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 6 ++++++ wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 2a02400bd1..7645043a47 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7dcd9f8969..1016092e84 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-57842'; +$wp_version = '6.6-alpha-57845'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.