Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | View Code Duplication | class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint { |
|
| 4 | function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
||
| 5 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 6 | if ( is_wp_error( $blog_id ) ) { |
||
| 7 | return $blog_id; |
||
| 8 | } |
||
| 9 | |||
| 10 | if ( ! current_user_can( 'delete_post', $media_id ) ) { |
||
| 11 | return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); |
||
| 12 | } |
||
| 13 | |||
| 14 | $item = $this->get_media_item( $media_id ); |
||
| 15 | |||
| 16 | if ( is_wp_error( $item ) ) { |
||
| 17 | return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); |
||
| 18 | } |
||
| 19 | |||
| 20 | wp_delete_post( $media_id ); |
||
| 21 | $item->status = 'deleted'; |
||
| 22 | return $item; |
||
| 23 | } |
||
| 24 | } |
||
| 25 |