Completed
Push — update/crm-integration-fixes ( a3fc2b )
by Jeremy
14:51 queued 06:26
created

class.wpcom-json-api-get-media-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_Endpoint( array(
4
	'description' => 'Get a single media item (by ID).',
5
	'group'       => 'media',
6
	'stat'        => 'media:1',
7
	'method'      => 'GET',
8
	'path'        => '/sites/%s/media/%d',
9
	'deprecated'  => true,
10
	'new_version' => '1.1',
11
	'max_version' => '1',
12
	'path_labels' => array(
13
		'$site'    => '(int|string) Site ID or domain',
14
		'$media_ID' => '(int) The ID of the media item',
15
	),
16
	'response_format' => array(
17
		'id'    => '(int) The ID of the media item',
18
		'date' =>  '(ISO 8601 datetime) The date the media was uploaded',
19
		'parent'           => '(int) ID of the post this media is attached to',
20
		'link'             => '(string) URL to the file',
21
		'title'            => '(string) Filename',
22
		'caption'          => '(string) User-provided caption of the file',
23
		'description'      => '(string) Description of the file',
24
		'metadata'         => '(array) Array of metadata about the file, such as Exif data or sizes',
25
	),
26
27
	'example_request'      => 'https://public-api.wordpress.com/rest/v1/sites/82974409/media/934',
28
	'example_request_data' =>  array(
29
		'headers' => array(
30
			'authorization' => 'Bearer YOUR_API_TOKEN'
31
		)
32
	)
33
) );
34
35
class WPCOM_JSON_API_Get_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
36
	function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
37
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
38
		if ( is_wp_error( $blog_id ) ) {
39
			return $blog_id;
40
		}
41
42
		//upload_files can probably be used for other endpoints but we want contributors to be able to use media too
43
		if ( !current_user_can( 'edit_posts', $media_id ) ) {
44
			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...
45
		}
46
47
		return $this->get_media_item( $media_id );
48
	}
49
}
50