Media: Add information about additional MIME type sources to attachments REST endpoints.

This changeset is a follow-up to [53751] which ensures the additional `sources` information stored in attachment metadata are available under `media_details` for each image size in the REST API responses for attachments.

Props mukesh27, eugenemanuilov, mitogh, flixos90, aaemnnosttv.
See #55443.

Built from https://develop.svn.wordpress.org/trunk@53786


git-svn-id: http://core.svn.wordpress.org/trunk@53345 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2022-07-27 15:15:15 +00:00
parent c6235a37c7
commit b39a441f3a
2 changed files with 19 additions and 1 deletions

View File

@ -783,6 +783,15 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
}
$size_data['source_url'] = $image_src[0];
if ( empty( $size_data['sources'] ) || ! is_array( $size_data['sources'] ) ) {
continue;
}
$image_url_basename = wp_basename( $image_src[0] );
foreach ( $size_data['sources'] as $mime => &$mime_details ) {
$mime_details['source_url'] = str_replace( $image_url_basename, $mime_details['file'], $image_src[0] );
}
}
$full_src = wp_get_attachment_image_src( $post->ID, 'full' );
@ -795,6 +804,15 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
'mime_type' => $post->post_mime_type,
'source_url' => $full_src[0],
);
if ( ! empty( $data['media_details']['sources'] ) ) {
$full_url_basename = wp_basename( $full_src[0] );
foreach ( $data['media_details']['sources'] as $mime => &$mime_details ) {
$mime_details['source_url'] = str_replace( $full_url_basename, $mime_details['file'], $full_src[0] );
}
$data['media_details']['sizes']['full']['sources'] = $data['media_details']['sources'];
unset( $data['media_details']['sources'] );
}
}
} else {
$data['media_details']['sizes'] = new stdClass;

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53785';
$wp_version = '6.1-alpha-53786';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.