mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-09 07:00:01 +00:00
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. Built from https://develop.svn.wordpress.org/trunk@57687 git-svn-id: http://core.svn.wordpress.org/trunk@57188 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4ee39b4d76
commit
5fd767d87d
@ -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 ),
|
||||
);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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' );
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user