Completed
Push — fix/normalize-www-in-site-url-... ( e67e76 )
by
unknown
13:13 queued 02:59
created

class.wpcom-json-api-delete-media-endpoint.php (1 issue)

Upgrade to new PHP Analysis Engine

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
Consider using a different name than the parameter $blog_id. This often makes code more readable.
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