blob: 10d8ae2dd1fbc1c72144736b1ebeee023899545b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?php
class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
if ( is_wp_error( $blog_id ) ) {
return $blog_id;
}
if ( ! current_user_can( 'delete_post', $media_id ) ) {
return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
}
$item = $this->get_media_item( $media_id );
if ( is_wp_error( $item ) ) {
return new WP_Error( 'unknown_media', 'Unknown Media', 404 );
}
wp_delete_post( $media_id );
$item->status = 'deleted';
return $item;
}
}
|