Make WordPress Core

Changeset 54941


Ignore:
Timestamp:
12/06/2022 07:22:24 PM (15 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r54661 r54941  
    111111            )
    112112        );
    113 
    114         update_post_parent_caches( $wp_query->posts );
     113        if ( $wp_query->posts ) {
     114            update_post_thumbnail_cache( $wp_query );
     115            update_post_parent_caches( $wp_query->posts );
     116        }
    115117    }
    116118
     
    425427        list( $mime ) = explode( '/', $post->post_mime_type );
    426428
     429        $attachment_id = $post->ID;
     430
     431        if ( has_post_thumbnail( $post ) ) {
     432            $thumbnail_id = get_post_thumbnail_id( $post );
     433
     434            if ( ! empty( $thumbnail_id ) ) {
     435                $attachment_id = $thumbnail_id;
     436            }
     437        }
     438
    427439        $title      = _draft_or_post_title();
    428         $thumb      = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
     440        $thumb      = wp_get_attachment_image( $attachment_id, array( 60, 60 ), true, array( 'alt' => '' ) );
    429441        $link_start = '';
    430442        $link_end   = '';
Note: See TracChangeset for help on using the changeset viewer.