Media: Use featured image if available for attachment as preview instead of icon.

When rendering a list of attachments in `WP_Media_List_Table` class, none image attachments, show a generic icon. However, attachment types like audio and video support adding a featured image. For attachments that have featured images, us this image instead of the icon. This featured image is a better preview than a generic icon. 

Props spacedmonkey, samful, johnbillion, JavierCasares, seanchayes, antpb, cadic, JeffPaul.
Fixes #49852.

git-svn-id: https://develop.svn.wordpress.org/trunk@54941 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris 2022-12-06 19:22:24 +00:00
parent 08dfd2b550
commit ed6fa5c090

View File

@ -110,8 +110,10 @@ class WP_Media_List_Table extends WP_List_Table {
'per_page' => $wp_query->query_vars['posts_per_page'],
)
);
update_post_parent_caches( $wp_query->posts );
if ( $wp_query->posts ) {
update_post_thumbnail_cache( $wp_query );
update_post_parent_caches( $wp_query->posts );
}
}
/**
@ -424,8 +426,18 @@ class WP_Media_List_Table extends WP_List_Table {
public function column_title( $post ) {
list( $mime ) = explode( '/', $post->post_mime_type );
$attachment_id = $post->ID;
if ( has_post_thumbnail( $post ) ) {
$thumbnail_id = get_post_thumbnail_id( $post );
if ( ! empty( $thumbnail_id ) ) {
$attachment_id = $thumbnail_id;
}
}
$title = _draft_or_post_title();
$thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
$thumb = wp_get_attachment_image( $attachment_id, array( 60, 60 ), true, array( 'alt' => '' ) );
$link_start = '';
$link_end = '';