WPCOM_JSON_API_Delete_Media_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Delete Media Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/class.wpcom-json-api-delete-media-endpoint.php  
  1. class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint { 
  2. function callback( $path = '', $blog_id = 0, $media_id = 0 ) { 
  3. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  4. if ( is_wp_error( $blog_id ) ) { 
  5. return $blog_id; 
  6.  
  7. if ( !current_user_can( 'upload_files', $media_id ) ) { 
  8. return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); 
  9.  
  10. $item = $this->get_media_item( $media_id ); 
  11.  
  12. if ( is_wp_error( $item ) ) { 
  13. return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); 
  14.  
  15. wp_delete_post( $media_id ); 
  16. $item->status = 'deleted'; 
  17. return $item;