Code Duplication    Length = 22-22 lines in 2 locations

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

@@ 3-24 (lines=22) @@
1
<?php
2
3
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 ) );
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

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

@@ 3-24 (lines=22) @@
1
<?php
2
3
class WPCOM_JSON_API_Delete_Media_v1_1_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 ) );
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 is not authorized delete media', 403 );
12
		}
13
14
		$item = $this->get_media_item_v1_1( $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, true );
21
		$item->status = 'deleted';
22
		return $item;
23
	}
24
}
25