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
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ public function prepare_item_for_response( $item, $request ) {
$data['missing_image_sizes'] = array_keys( wp_get_missing_image_subsizes( $post->ID ) );
}

if ( in_array( 'trashable', $fields, true ) ) {
$data['trashable'] = ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH );
}

$context = ! empty( $request['context'] ) ? $request['context'] : 'view';

$data = $this->filter_response_by_context( $data, $context );
Expand Down Expand Up @@ -1083,6 +1087,13 @@ public function get_item_schema() {
'readonly' => true,
);

$schema['properties']['trashable'] = array(
'description' => __( 'Whether the attachment can be moved to the trash.' ),
'type' => 'boolean',
'context' => array( 'view', 'edit' ),
'readonly' => true,
);

unset( $schema['properties']['password'] );

$this->schema = $schema;
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/tests/rest-api/rest-attachments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ public function test_get_item_schema() {
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 29, $properties );
$this->assertCount( 30, $properties );
$this->assertArrayHasKey( 'author', $properties );
$this->assertArrayHasKey( 'alt_text', $properties );
$this->assertArrayHasKey( 'caption', $properties );
Expand Down Expand Up @@ -1704,6 +1704,7 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'rendered', $properties['title']['properties'] );
$this->assertArrayHasKey( 'type', $properties );
$this->assertArrayHasKey( 'missing_image_sizes', $properties );
$this->assertArrayHasKey( 'trashable', $properties );
$this->assertArrayHasKey( 'featured_media', $properties );
$this->assertArrayHasKey( 'class_list', $properties );
}
Expand Down
4 changes: 3 additions & 1 deletion tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -13079,6 +13079,7 @@ mockedApiResponse.MediaCollection = [
"media_details": {},
"post": null,
"source_url": "http://example.org/wp-content/uploads//tmp/canola.jpg",
"trashable": false,
"_links": {
"self": [
{
Expand Down Expand Up @@ -13156,7 +13157,8 @@ mockedApiResponse.MediaModel = {
"mime_type": "image/jpeg",
"media_details": {},
"post": null,
"source_url": "http://example.org/wp-content/uploads//tmp/canola.jpg"
"source_url": "http://example.org/wp-content/uploads//tmp/canola.jpg",
"trashable": false
};

mockedApiResponse.TypesCollection = {
Expand Down