This repository has been archived on 2022-08-01. You can view files and clone it, but cannot push or open issues or pull requests.
Oldphaloskepsis/plugins/jetpack/json-endpoints/class.wpcom-json-api-delete-media-endpoint.php
2017-01-12 23:10:07 +00:00

24 lines
672 B
PHP

<?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;
}
}