Make WordPress Core


Ignore:
Timestamp:
07/27/2022 03:13:16 PM (2 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r52068 r53786  
    784784
    785785                    $size_data['source_url'] = $image_src[0];
     786
     787                    if ( empty( $size_data['sources'] ) || ! is_array( $size_data['sources'] ) ) {
     788                        continue;
     789                    }
     790
     791                    $image_url_basename = wp_basename( $image_src[0] );
     792                    foreach ( $size_data['sources'] as $mime => &$mime_details ) {
     793                        $mime_details['source_url'] = str_replace( $image_url_basename, $mime_details['file'], $image_src[0] );
     794                    }
    786795                }
    787796
     
    796805                        'source_url' => $full_src[0],
    797806                    );
     807
     808                    if ( ! empty( $data['media_details']['sources'] ) ) {
     809                        $full_url_basename = wp_basename( $full_src[0] );
     810                        foreach ( $data['media_details']['sources'] as $mime => &$mime_details ) {
     811                            $mime_details['source_url'] = str_replace( $full_url_basename, $mime_details['file'], $full_src[0] );
     812                        }
     813                        $data['media_details']['sizes']['full']['sources'] = $data['media_details']['sources'];
     814                        unset( $data['media_details']['sources'] );
     815                    }
    798816                }
    799817            } else {
Note: See TracChangeset for help on using the changeset viewer.