diff --git a/wp-includes/customize/class-wp-customize-media-control.php b/wp-includes/customize/class-wp-customize-media-control.php index 3bdc4e2dc1..ba8d8e9d31 100644 --- a/wp-includes/customize/class-wp-customize-media-control.php +++ b/wp-includes/customize/class-wp-customize-media-control.php @@ -99,7 +99,7 @@ class WP_Customize_Media_Control extends WP_Customize_Control { 'id' => 1, 'url' => $this->setting->default, 'type' => $type, - 'icon' => wp_mime_type_icon( $type ), + 'icon' => wp_mime_type_icon( $type, '.svg' ), 'title' => wp_basename( $this->setting->default ), ); diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 45b4f89a9e..4de4a93039 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -1910,7 +1910,7 @@ function get_attachment_icon_src( $id = 0, $fullsize = false ) { $src = wp_get_attachment_url( $post->ID ); $src_file = & $file; - } elseif ( $src = wp_mime_type_icon( $post->ID ) ) { + } elseif ( $src = wp_mime_type_icon( $post->ID, '.svg' ) ) { // No thumb, no image. We'll look for a mime-related icon instead. /** This filter is documented in wp-includes/post.php */ diff --git a/wp-includes/media.php b/wp-includes/media.php index b5e477e7f7..5fb5a27230 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -972,14 +972,22 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon $src = false; if ( $icon ) { - $src = wp_mime_type_icon( $attachment_id ); + $src = wp_mime_type_icon( $attachment_id, '.svg' ); if ( $src ) { /** This filter is documented in wp-includes/post.php */ $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); - $src_file = $icon_dir . '/' . wp_basename( $src ); + $src_file = $icon_dir . '/' . wp_basename( $src ); list( $width, $height ) = wp_getimagesize( $src_file ); + $ext = strtolower( substr( $src_file, -4 ) ); + if ( '.svg' === $ext ) { + // SVG does not have true dimensions, so this assigns width and height directly. + $width = 48; + $height = 64; + } else { + list( $width, $height ) = wp_getimagesize( $src_file ); + } } } @@ -3067,7 +3075,7 @@ function wp_playlist_shortcode( $attr ) { list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); $track['thumb'] = compact( 'src', 'width', 'height' ); } else { - $src = wp_mime_type_icon( $attachment->ID ); + $src = wp_mime_type_icon( $attachment->ID, '.svg' ); $width = 48; $height = 64; $track['image'] = compact( 'src', 'width', 'height' ); @@ -4339,7 +4347,7 @@ function wp_prepare_attachment_for_js( $attachment ) { 'mime' => $attachment->post_mime_type, 'type' => $type, 'subtype' => $subtype, - 'icon' => wp_mime_type_icon( $attachment->ID ), + 'icon' => wp_mime_type_icon( $attachment->ID, '.svg' ), 'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ), 'nonces' => array( 'update' => false, @@ -4510,7 +4518,7 @@ function wp_prepare_attachment_for_js( $attachment ) { list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' ); $response['thumb'] = compact( 'src', 'width', 'height' ); } else { - $src = wp_mime_type_icon( $attachment->ID ); + $src = wp_mime_type_icon( $attachment->ID, '.svg' ); $width = 48; $height = 64; $response['image'] = compact( 'src', 'width', 'height' ); diff --git a/wp-includes/post.php b/wp-includes/post.php index 04fb143a1d..d035acb045 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -6803,10 +6803,11 @@ function wp_attachment_is_image( $post = null ) { * * @since 2.1.0 * - * @param string|int $mime MIME type or attachment ID. + * @param string|int $mime MIME type or attachment ID. + * @param string $preferred_ext File format to prefer in return. Default .png. * @return string|false Icon, false otherwise. */ -function wp_mime_type_icon( $mime = 0 ) { +function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) { if ( ! is_numeric( $mime ) ) { $icon = wp_cache_get( "mime_type_icon_$mime" ); } @@ -6885,7 +6886,9 @@ function wp_mime_type_icon( $mime = 0 ) { } continue; } - $icon_files[ "$dir/$file" ] = "$uri/$file"; + if ( $ext === $preferred_ext ) { + $icon_files[ "$dir/$file" ] = "$uri/$file"; + } } closedir( $dh ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 480150e084..93893221ec 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-beta2-57686'; +$wp_version = '6.5-beta2-57687'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.