PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / json-endpoints / class.wpcom-json-api-get-media-endpoint.php

class.wpcom-json-api-get-media-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.7, at json-endpoints/class.wpcom-json-api-get-media-endpoint.php

69 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 new WPCOM_JSON_API_Get_Media_Endpoint(
8 array(
9 'description' => 'Get a single media item (by ID).',
10 'group' => 'media',
11 'stat' => 'media:1',
12 'method' => 'GET',
13 'path' => '/sites/%s/media/%d',
14 'deprecated' => true,
15 'new_version' => '1.1',
16 'max_version' => '1',
17 'path_labels' => array(
18 '$site' => '(int|string) Site ID or domain',
19 '$media_ID' => '(int) The ID of the media item',
20 ),
21 'response_format' => array(
22 'id' => '(int) The ID of the media item',
23 'date' => '(ISO 8601 datetime) The date the media was uploaded',
24 'parent' => '(int) ID of the post this media is attached to',
25 'link' => '(string) URL to the file',
26 'title' => '(string) Filename',
27 'caption' => '(string) User-provided caption of the file',
28 'description' => '(string) Description of the file',
29 'metadata' => '(array) Array of metadata about the file, such as Exif data or sizes',
30 ),
31
32 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/82974409/media/934',
33 'example_request_data' => array(
34 'headers' => array(
35 'authorization' => 'Bearer YOUR_API_TOKEN',
36 ),
37 ),
38 )
39 );
40
41 /**
42 * GET Media endpoint class.
43 *
44 * @phan-constructor-used-for-side-effects
45 */
46 class WPCOM_JSON_API_Get_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
47 /**
48 *
49 * API callback.
50 *
51 * @param string $path - the path.
52 * @param int $blog_id - the blog ID.
53 * @param int $media_id - the media ID.
54 */
55 public function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
56 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
57 if ( is_wp_error( $blog_id ) ) {
58 return $blog_id;
59 }
60
61 // upload_files can probably be used for other endpoints but we want contributors to be able to use media too.
62 if ( ! current_user_can( 'edit_posts', $media_id ) ) {
63 return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
64 }
65
66 return $this->get_media_item( $media_id );
67 }
68 }
69