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

WPCOM_JSON_API_Get_Media_Endpoint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A callback() 0 13 3
1
<?php
2
3
class WPCOM_JSON_API_Get_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
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
		//upload_files can probably be used for other endpoints but we want contributors to be able to use media too
11
		if ( !current_user_can( 'edit_posts', $media_id ) ) {
12
			return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
13
		}
14
15
		return $this->get_media_item( $media_id );
16
	}
17
}
18