Completed
Push — update/crm-integration-fixes ( a3fc2b )
by Jeremy
14:51 queued 06:26
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
new WPCOM_JSON_API_Get_Media_v1_1_Endpoint( array(
4
	'description' => 'Get a single media item (by ID).',
5
	'group'       => 'media',
6
	'stat'        => 'media:1',
7
	'min_version' => '1.1',
8
	'max_version' => '1.1',
9
	'method'      => 'GET',
10
	'path'        => '/sites/%s/media/%d',
11
	'path_labels' => array(
12
		'$site'    => '(int|string) Site ID or domain',
13
		'$media_ID' => '(int) The ID of the media item',
14
	),
15
	'response_format' => array(
16
		'ID'               => '(int) The ID of the media item',
17
		'date'             => '(ISO 8601 datetime) The date the media was uploaded',
18
		'post_ID'          => '(int) ID of the post this media is attached to',
19
		'author_ID'        => '(int) ID of the user who uploaded the media',
20
		'URL'              => '(string) URL to the file',
21
		'guid'             => '(string) Unique identifier',
22
		'file'			   => '(string) Filename',
23
		'extension'        => '(string) File extension',
24
		'mime_type'        => '(string) File MIME type',
25
		'title'            => '(string) Filename',
26
		'caption'          => '(string) User-provided caption of the file',
27
		'description'      => '(string) Description of the file',
28
		'alt'              => '(string)  Alternative text for image files.',
29
		'thumbnails'       => '(object) Media item thumbnail URL options',
30
		'height'           => '(int) (Image & video only) Height of the media item',
31
		'width'            => '(int) (Image & video only) Width of the media item',
32
		'length'           => '(int) (Video & audio only) Duration of the media item, in seconds',
33
		'exif'             => '(array) (Image & audio only) Exif (meta) information about the media item',
34
		'videopress_guid'  => '(string) (Video only) VideoPress GUID of the video when uploaded on a blog with VideoPress',
35
		'videopress_processing_done'  => '(bool) (Video only) If the video is uploaded on a blog with VideoPress, this will return the status of processing on the video.'
36
	),
37
38
	'example_request'      => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/934',
39
	'example_request_data' =>  array(
40
		'headers' => array(
41
			'authorization' => 'Bearer YOUR_API_TOKEN'
42
		)
43
	)
44
) );
45
46
class WPCOM_JSON_API_Get_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint {
47
	function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
48
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
49
		if ( is_wp_error( $blog_id ) ) {
50
			return $blog_id;
51
		}
52
53
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
54
			$this->load_theme_functions();
55
		}
56
57
		//upload_files can probably be used for other endpoints but we want contributors to be able to use media too
58
		if ( ! current_user_can( 'edit_posts', $media_id ) ) {
59
			return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
0 ignored issues
show
The call to WP_Error::__construct() has too many arguments starting with 'unauthorized'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
		}
61
62
		return $this->get_media_item_v1_1( $media_id );
63
	}
64
}
65