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

class.wpcom-json-api-get-media-v1-1-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
class WPCOM_JSON_API_Get_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 ) );
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 ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
11
			$this->load_theme_functions();
12
		}
13
14
		//upload_files can probably be used for other endpoints but we want contributors to be able to use media too
15
		if ( ! current_user_can( 'edit_posts', $media_id ) ) {
16
			return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
17
		}
18
19
		return $this->get_media_item_v1_1( $media_id );
20
	}
21
}
22