WordPress.org

Make WordPress Core

Ticket #17262: 17262.3.diff

File 17262.3.diff, 2.1 KB (added by romulodl, 4 years ago)
  • src/wp-includes/post.php

     
    50735073        if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) )
    50745074                return false;
    50755075
     5076        $thumbfile = false;
    50765077        $file = get_attached_file( $post->ID );
    50775078
    5078         if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) {
     5079        if ( isset( $imagedata['sizes']['thumbnail']['file']) ) {
     5080                $thumbfile = $imagedata['sizes']['thumbnail']['file'];
     5081        } elseif ( isset( $imagedata['thumb'] ) ) {
     5082                $thumbfile = $imagedata['thumb'];
     5083        }
     5084
     5085        if ($thumbfile && file_exists(str_replace(basename($file), $thumbfile, $file)) ) {
    50795086                /**
    50805087                 * Filter the attachment thumbnail file path.
    50815088                 *
     
    50845091                 * @param string $thumbfile File path to the attachment thumbnail.
    50855092                 * @param int    $post_id   Attachment ID.
    50865093                 */
    5087                 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     5094                $thumbfile = apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
    50885095        }
    5089         return false;
     5096
     5097        return $thumbfile;
    50905098}
    50915099
    50925100/**
  • tests/phpunit/tests/post/attachments.php

     
    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                if ( !function_exists( 'imagejpeg' ) )
     529                        $this->markTestSkipped( 'jpeg support unavailable' );
     530
     531                $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
     532                $contents = file_get_contents($filename);
     533
     534                $upload = wp_upload_bits(basename($filename), null, $contents);
     535                $this->assertTrue( empty($upload['error']) );
     536
     537                $id = $this->_make_attachment($upload);
     538
     539                $this->assertFalse(wp_get_attachment_thumb_file());
     540                $this->assertEquals('a2-small-150x150.jpg', wp_get_attachment_thumb_file($id));
     541        }
    523542}