WordPress.org

Make WordPress Core

Ticket #17262: 17262.4.diff

File 17262.4.diff, 2.3 KB (added by swissspidy, 4 years ago)
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 72ffc8d..6ada1b2 100644
    function wp_get_attachment_url( $post_id = 0 ) { 
    50605060}
    50615061
    50625062/**
    5063  * Retrieve thumbnail for an attachment.
     5063 * Retrieves the thumbnail for an attachment.
    50645064 *
    50655065 * @since 2.1.0
    50665066 *
    function wp_get_attachment_thumb_file( $post_id = 0 ) { 
    50745074        if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) )
    50755075                return false;
    50765076
     5077        $thumbfile = false;
    50775078        $file = get_attached_file( $post->ID );
    50785079
    5079         if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) {
     5080        if ( isset( $imagedata['sizes']['thumbnail']['file'] ) ) {
     5081                $thumbfile = $imagedata['sizes']['thumbnail']['file'];
     5082        } elseif ( isset( $imagedata['thumb'] ) ) {
     5083                $thumbfile = $imagedata['thumb'];
     5084        }
     5085
     5086        if ( $thumbfile && file_exists( str_replace( basename( $file ), $thumbfile, $file ) ) ) {
    50805087                /**
    5081                  * Filter the attachment thumbnail file path.
     5088                 * Filters the attachment thumbnail file path.
    50825089                 *
    50835090                 * @since 2.1.0
    50845091                 *
    50855092                 * @param string $thumbfile File path to the attachment thumbnail.
    50865093                 * @param int    $post_id   Attachment ID.
    50875094                 */
    5088                 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     5095                $thumbfile = apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
    50895096        }
    5090         return false;
     5097
     5098        return $thumbfile;
    50915099}
    50925100
    50935101/**
  • tests/phpunit/tests/post/attachments.php

    diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
    index 3df4ce4..7d8030f 100644
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    520520
    521521                $this->assertContains( 'images/media/video.png', $icon );
    522522        }
     523
     524        /**
     525         * @ticket 17262
     526         */
     527        public function test_wp_get_attachment_thumb_file() {
     528                $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' );
     529                $contents = file_get_contents( $filename );
     530
     531                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     532                $this->assertTrue( empty( $upload['error'] ) );
     533
     534                $id = $this->_make_attachment( $upload );
     535
     536                $this->assertFalse( wp_get_attachment_thumb_file() );
     537                $this->assertEquals( 'a2-small-150x150.jpg', wp_get_attachment_thumb_file( $id ) );
     538        }
    523539}