Code Duplication    Length = 22-22 lines in 2 locations

json-endpoints/class.wpcom-json-api-delete-media-endpoint.php 1 location

@@ 37-58 (lines=22) @@
34
	)
35
) );
36
37
class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
38
	function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
39
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
40
		if ( is_wp_error( $blog_id ) ) {
41
			return $blog_id;
42
		}
43
44
		if ( ! current_user_can( 'delete_post', $media_id ) ) {
45
			return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
46
		}
47
48
		$item = $this->get_media_item( $media_id );
49
50
		if ( is_wp_error( $item ) ) {
51
			return new WP_Error( 'unknown_media', 'Unknown Media', 404 );
52
		}
53
54
		wp_delete_post( $media_id );
55
		$item->status = 'deleted';
56
		return $item;
57
	}
58
}
59

json-endpoints/class.wpcom-json-api-delete-media-v1-1-endpoint.php 1 location

@@ 48-69 (lines=22) @@
45
	)
46
) );
47
48
class WPCOM_JSON_API_Delete_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint {
49
	function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
50
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
51
		if ( is_wp_error( $blog_id ) ) {
52
			return $blog_id;
53
		}
54
55
		if ( ! current_user_can( 'delete_post', $media_id ) ) {
56
			return new WP_Error( 'unauthorized', 'User is not authorized delete media', 403 );
57
		}
58
59
		$item = $this->get_media_item_v1_1( $media_id );
60
61
		if ( is_wp_error( $item ) ) {
62
			return new WP_Error( 'unknown_media', 'Unknown Media', 404 );
63
		}
64
65
		wp_delete_post( $media_id, true );
66
		$item->status = 'deleted';
67
		return $item;
68
	}
69
}
70