Make WordPress Core

Changeset 57603

Timestamp:
02/12/2024 10:15:45 PM (6 months ago)
Author:
swissspidy
Message:

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.

Location:
trunk
Files:
5 edited

Legend:

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

    r57524 r57603  
    172172        }
    173173
     174
     175
     176
     177
     178
     179
     180
     181
    174182        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
    175183            $meta_update = $this->meta->update_value( $request['meta'], $attachment_id );
     
    324332
    325333    /**
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
    326371     * Updates a single attachment.
    327372     *
     
    355400
    356401        $attachment = get_post( $request['id'] );
     402
     403
     404
     405
     406
     407
     408
     409
    357410
    358411        $fields_update = $this->update_additional_fields_for_object( $attachment, $request );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r57230 r57603  
    23782378                'revisions',
    23792379                'custom-fields',
     2380
    23802381            ),
    23812382        );
  • trunk/tests/phpunit/includes/testcase-rest-post-type-controller.php

    r56549 r57603  
    7878        }
    7979
    80         if ( post_type_supports( $post->post_type, 'thumbnail' ) ) {
     80        if (
     81            post_type_supports( $post->post_type, 'thumbnail' ) ||
     82            (
     83                'attachment' === $post->post_type &&
     84                (
     85                    post_type_supports( 'attachment:audio', 'thumbnail' ) ||
     86                    post_type_supports( 'attachment:video', 'thumbnail' )
     87                )
     88            )
     89        ) {
    8190            $this->assertSame( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] );
    8291        } else {
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r57380 r57603  
    10661066        $term = wp_get_post_terms( $attachment['id'], 'category' );
    10671067        $this->assertSame( $category['term_id'], $term[0]->term_id );
     1068
     1069
     1070
     1071
     1072
     1073
     1074
     1075
     1076
     1077
     1078
     1079
     1080
     1081
     1082
     1083
     1084
     1085
     1086
     1087
     1088
     1089
     1090
     1091
     1092
     1093
     1094
     1095
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
     1113
     1114
     1115
     1116
     1117
     1118
     1119
     1120
     1121
     1122
     1123
     1124
     1125
     1126
     1127
     1128
     1129
     1130
     1131
     1132
     1133
     1134
     1135
     1136
     1137
     1138
    10681139    }
    10691140
     
    15771648        $data       = $response->get_data();
    15781649        $properties = $data['schema']['properties'];
    1579         $this->assertCount( 27, $properties );
     1650        $this->assertCount( 2, $properties );
    15801651        $this->assertArrayHasKey( 'author', $properties );
    15811652        $this->assertArrayHasKey( 'alt_text', $properties );
     
    16111682        $this->assertArrayHasKey( 'type', $properties );
    16121683        $this->assertArrayHasKey( 'missing_image_sizes', $properties );
     1684
    16131685    }
    16141686
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r57548 r57603  
    73167316                            "required": false
    73177317                        },
     7318
     7319
     7320
     7321
     7322
    73187323                        "comment_status": {
    73197324                            "description": "Whether or not comments are open on the post.",
     
    75157520                        "author": {
    75167521                            "description": "The ID for the author of the post.",
     7522
     7523
     7524
     7525
     7526
    75177527                            "type": "integer",
    75187528                            "required": false
     
    1269412704        },
    1269512705        "author": 0,
     12706
    1269612707        "comment_status": "open",
    1269712708        "ping_status": "closed",
     
    1275512766    },
    1275612767    "author": 0,
     12768
    1275712769    "comment_status": "open",
    1275812770    "ping_status": "closed",
Note: See TracChangeset for help on using the changeset viewer.