From d0997b8e96e29e19892ce711d6b962748c49ae1a Mon Sep 17 00:00:00 2001 From: joedolson Date: Fri, 15 Mar 2024 20:58:12 +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 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 --- 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 91c009f7a9..b9bbd7c16f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.