REST API: Add featured_media field to attachments endpoint.

Audio and video attachments can have a featured image, also known as a poster image. This functionality is now properly exposed by the `wp/v2/media` endpoint.

Props swissspidy, timothyblynjacobs, wonderboymusic, dlh, spacedmonkey.
Fixes #41692.

git-svn-id: https://develop.svn.wordpress.org/trunk@57603 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2024-02-12 22:15:45 +00:00
parent 35feae5c75
commit 54d72c5dee
5 changed files with 149 additions and 2 deletions

View File

@@ -77,7 +77,16 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C
$this->assertSame( get_page_template_slug( $post->ID ), $data['template'] );
}
if ( post_type_supports( $post->post_type, 'thumbnail' ) ) {
if (
post_type_supports( $post->post_type, 'thumbnail' ) ||
(
'attachment' === $post->post_type &&
(
post_type_supports( 'attachment:audio', 'thumbnail' ) ||
post_type_supports( 'attachment:video', 'thumbnail' )
)
)
) {
$this->assertSame( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] );
} else {
$this->assertArrayNotHasKey( 'featured_media', $data );