| 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_v1_1_Endpoint( |
| 8 |
array( |
| 9 |
'description' => 'Get a single media item (by ID).', |
| 10 |
'group' => 'media', |
| 11 |
'stat' => 'media:1', |
| 12 |
'min_version' => '1.1', |
| 13 |
'max_version' => '1.1', |
| 14 |
'method' => 'GET', |
| 15 |
'path' => '/sites/%s/media/%d', |
| 16 |
'path_labels' => array( |
| 17 |
'$site' => '(int|string) Site ID or domain', |
| 18 |
'$media_ID' => '(int) The ID of the media item', |
| 19 |
), |
| 20 |
'response_format' => array( |
| 21 |
'ID' => '(int) The ID of the media item', |
| 22 |
'date' => '(ISO 8601 datetime) The date the media was uploaded', |
| 23 |
'post_ID' => '(int) ID of the post this media is attached to', |
| 24 |
'author_ID' => '(int) ID of the user who uploaded the media', |
| 25 |
'URL' => '(string) URL to the file', |
| 26 |
'guid' => '(string) Unique identifier', |
| 27 |
'file' => '(string) Filename', |
| 28 |
'extension' => '(string) File extension', |
| 29 |
'mime_type' => '(string) File MIME type', |
| 30 |
'title' => '(string) Filename', |
| 31 |
'caption' => '(string) User-provided caption of the file', |
| 32 |
'description' => '(string) Description of the file', |
| 33 |
'alt' => '(string) Alternative text for image files.', |
| 34 |
'thumbnails' => '(object) Media item thumbnail URL options', |
| 35 |
'height' => '(int) (Image & video only) Height of the media item', |
| 36 |
'width' => '(int) (Image & video only) Width of the media item', |
| 37 |
'length' => '(int) (Video & audio only) Duration of the media item, in seconds', |
| 38 |
'exif' => '(array) (Image & audio only) Exif (meta) information about the media item', |
| 39 |
'rating' => '(string) (Video only) VideoPress rating of the video', |
| 40 |
'display_embed' => '(string) Video only. Whether to share or not the video.', |
| 41 |
'allow_download' => '(string) Video only. Whether the video can be downloaded or not.', |
| 42 |
'videopress_guid' => '(string) (Video only) VideoPress GUID of the video when uploaded on a blog with VideoPress', |
| 43 |
'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.', |
| 44 |
), |
| 45 |
|
| 46 |
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/934', |
| 47 |
'example_request_data' => array( |
| 48 |
'headers' => array( |
| 49 |
'authorization' => 'Bearer YOUR_API_TOKEN', |
| 50 |
), |
| 51 |
), |
| 52 |
) |
| 53 |
); |
| 54 |
|
| 55 |
/** |
| 56 |
* GET Media v1_1 endpoint. |
| 57 |
* |
| 58 |
* @phan-constructor-used-for-side-effects |
| 59 |
*/ |
| 60 |
class WPCOM_JSON_API_Get_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint { //phpcs:ignore |
| 61 |
/** |
| 62 |
* |
| 63 |
* API callback. |
| 64 |
* |
| 65 |
* @param string $path - the path. |
| 66 |
* @param int $blog_id - the blog ID. |
| 67 |
* @param int $media_id - the media ID. |
| 68 |
*/ |
| 69 |
public function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
| 70 |
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
| 71 |
if ( is_wp_error( $blog_id ) ) { |
| 72 |
return $blog_id; |
| 73 |
} |
| 74 |
|
| 75 |
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 76 |
$this->load_theme_functions(); |
| 77 |
} |
| 78 |
|
| 79 |
// upload_files can probably be used for other endpoints but we want contributors to be able to use media too. |
| 80 |
if ( ! current_user_can( 'edit_posts', $media_id ) ) { |
| 81 |
return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); |
| 82 |
} |
| 83 |
|
| 84 |
return $this->get_media_item_v1_1( $media_id ); |
| 85 |
} |
| 86 |
} |
| 87 |
|