From 352e997f92ed922df4ccecf0f17a43a79fd92421 Mon Sep 17 00:00:00 2001 From: Mike Schroder Date: Thu, 1 Dec 2016 00:01:38 +0000 Subject: [PATCH] Media: Fix regression with display of small images in media library. Fixes a regression in the media library after [38949], which caused small images (< thumbnail size) to not display within the media library. Accounts for images that have no intermediate sizes in `wp_prepare_attachment_for_js()`. Adds test. Fixes #38965. Props joemcgill, clorith, mikeschroder. git-svn-id: https://develop.svn.wordpress.org/trunk@39396 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 2 +- tests/phpunit/tests/media.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index a3a8088a15..ba52555932 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -3139,7 +3139,7 @@ function wp_prepare_attachment_for_js( $attachment ) { if ( current_user_can( 'delete_post', $attachment->ID ) ) $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); - if ( $meta && ! empty( $meta['sizes'] ) ) { + if ( $meta && ( 'image' === $type || ! empty( $meta['sizes'] ) ) ) { $sizes = array(); /** This filter is documented in wp-admin/includes/media.php */ diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 2453a47d95..d8c28c2191 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -269,6 +269,31 @@ https://w.org' $this->assertEquals( '', $prepped['subtype'] ); } + /** + * @ticket 38965 + */ + function test_wp_prepare_attachment_for_js_without_image_sizes() { + // Create the attachement post. + $id = wp_insert_attachment( array( + 'post_title' => 'Attachment Title', + 'post_type' => 'attachment', + 'post_parent' => 0, + 'post_mime_type' => 'image/jpeg', + 'guid' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-image.jpg', + ) ); + + // Add attachment metadata without sizes. + wp_update_attachment_metadata( $id, array( + 'width' => 50, + 'height' => 50, + 'file' => 'test-image.jpg', + ) ); + + $prepped = wp_prepare_attachment_for_js( get_post( $id ) ); + + $this->assertTrue( isset( $prepped['sizes'] ) ); + } + /** * @ticket 19067 * @expectedDeprecated wp_convert_bytes_to_hr