Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/wp-includes/embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,12 @@ function get_oembed_response_data_rich( $data, $post, $width, $height ) {
}

if ( $thumbnail_id ) {
list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) );
$data['thumbnail_url'] = $thumbnail_url;
$data['thumbnail_width'] = $thumbnail_width;
$data['thumbnail_height'] = $thumbnail_height;
$thumbnail_src = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) );
if ( is_array( $thumbnail_src ) ) {
$data['thumbnail_url'] = $thumbnail_src[0];
$data['thumbnail_width'] = $thumbnail_src[1];
$data['thumbnail_height'] = $thumbnail_src[2];
}
}

return $data;
Expand Down
49 changes: 39 additions & 10 deletions src/wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,8 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon

$src_file = $icon_dir . '/' . wp_basename( $src );

list( $width, $height ) = wp_getimagesize( $src_file );
$width = 0;
$height = 0;

$ext = strtolower( substr( $src_file, -4 ) );

Expand All @@ -997,7 +998,11 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
$width = 48;
$height = 64;
} else {
list( $width, $height ) = wp_getimagesize( $src_file );
$imagesize = wp_getimagesize( $src_file );
if ( is_array( $imagesize ) ) {
$width = $imagesize[0];
$height = $imagesize[1];
}
}
}
}
Expand Down Expand Up @@ -3230,10 +3235,22 @@ function wp_playlist_shortcode( $attr ) {
if ( $atts['images'] ) {
$thumb_id = get_post_thumbnail_id( $attachment->ID );
if ( ! empty( $thumb_id ) ) {
list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' );
$track['image'] = compact( 'src', 'width', 'height' );
list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
$track['thumb'] = compact( 'src', 'width', 'height' );
$image_src = wp_get_attachment_image_src( $thumb_id, 'full' );
if ( is_array( $image_src ) ) {
$track['image'] = array(
'src' => $image_src[0],
'width' => $image_src[1],
'height' => $image_src[2],
);
}
$thumb_src = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
if ( is_array( $thumb_src ) ) {
$track['thumb'] = array(
'src' => $thumb_src[0],
'width' => $thumb_src[1],
'height' => $thumb_src[2],
);
}
} else {
$src = wp_mime_type_icon( $attachment->ID, '.svg' );
$width = 48;
Expand Down Expand Up @@ -4711,10 +4728,22 @@ function wp_prepare_attachment_for_js( $attachment ) {

$id = get_post_thumbnail_id( $attachment->ID );
if ( ! empty( $id ) ) {
list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' );
$response['image'] = compact( 'src', 'width', 'height' );
list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' );
$response['thumb'] = compact( 'src', 'width', 'height' );
$image_src = wp_get_attachment_image_src( $id, 'full' );
if ( is_array( $image_src ) ) {
$response['image'] = array(
'src' => $image_src[0],
'width' => $image_src[1],
'height' => $image_src[2],
);
}
$thumb_src = wp_get_attachment_image_src( $id, 'thumbnail' );
if ( is_array( $thumb_src ) ) {
$response['thumb'] = array(
'src' => $thumb_src[0],
'width' => $thumb_src[1],
'height' => $thumb_src[2],
);
}
} else {
$src = wp_mime_type_icon( $attachment->ID, '.svg' );
$width = 48;
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/tests/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -7283,6 +7283,35 @@ private function get_insufficient_width_height_for_high_priority(): array {
'height' => 100,
);
}

/**
* @ticket 64742
*/
public function test_wp_get_attachment_image_src_returns_false_for_invalid_attachment() {
$result = wp_get_attachment_image_src( 99999, 'thumbnail' );
$this->assertFalse( $result );
}

/**
* @ticket 64742
*/
public function test_wp_prepare_attachment_for_js_with_invalid_thumbnail_does_not_warn() {
$attachment_id = self::factory()->attachment->create_object(
DIR_TESTDATA . '/uploads/test-image.jpg',
0,
array(
'post_mime_type' => 'audio/mpeg',
'post_type' => 'attachment',
)
);

// Set _thumbnail_id to a non-existent attachment ID.
update_post_meta( $attachment_id, '_thumbnail_id', 99999 );

$result = wp_prepare_attachment_for_js( $attachment_id );

$this->assertIsArray( $result );
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/tests/oembed/getResponseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,21 @@ public function test_get_oembed_response_data_for_attachment() {
$this->assertArrayHasKey( 'thumbnail_height', $data );
$this->assertLessThanOrEqual( 400, $data['thumbnail_width'] );
}

/**
* @ticket 64742
*/
public function test_get_oembed_response_data_with_invalid_thumbnail_does_not_warn() {
$post = self::factory()->post->create_and_get();

// Set _thumbnail_id to a non-existent attachment ID.
update_post_meta( $post->ID, '_thumbnail_id', 99999 );

$data = get_oembed_response_data( $post, 400 );

$this->assertIsArray( $data );
$this->assertArrayNotHasKey( 'thumbnail_url', $data );
$this->assertArrayNotHasKey( 'thumbnail_width', $data );
$this->assertArrayNotHasKey( 'thumbnail_height', $data );
}
}
Loading