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

WPCOM_JSON_API_Delete_Media_Endpoint::callback()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 4
nop 3
dl 20
loc 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3 View Code Duplication
class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
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