| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit( 0 ); |
| 5 |
} |
| 6 |
|
| 7 |
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.media.php'; |
| 8 |
|
| 9 |
new WPCOM_JSON_API_Get_Media_v1_2_Endpoint( |
| 10 |
array( |
| 11 |
'description' => 'Get a single media item (by ID).', |
| 12 |
'group' => 'media', |
| 13 |
'stat' => 'media:1', |
| 14 |
'min_version' => '1.2', |
| 15 |
'max_version' => '1.2', |
| 16 |
'method' => 'GET', |
| 17 |
'path' => '/sites/%s/media/%d', |
| 18 |
'path_labels' => array( |
| 19 |
'$site' => '(int|string) Site ID or domain', |
| 20 |
'$media_ID' => '(int) The ID of the media item', |
| 21 |
), |
| 22 |
'response_format' => array( |
| 23 |
'ID' => '(int) The ID of the media item', |
| 24 |
'date' => '(ISO 8601 datetime) The date the media was uploaded', |
| 25 |
'post_ID' => '(int) ID of the post this media is attached to', |
| 26 |
'author_ID' => '(int) ID of the user who uploaded the media', |
| 27 |
'URL' => '(string) URL to the file', |
| 28 |
'guid' => '(string) Unique identifier', |
| 29 |
'file' => '(string) Filename', |
| 30 |
'extension' => '(string) File extension', |
| 31 |
'mime_type' => '(string) File MIME type', |
| 32 |
'title' => '(string) Filename', |
| 33 |
'caption' => '(string) User-provided caption of the file', |
| 34 |
'description' => '(string) Description of the file', |
| 35 |
'alt' => '(string) Alternative text for image files.', |
| 36 |
'thumbnails' => '(object) Media item thumbnail URL options', |
| 37 |
'height' => '(int) (Image & video only) Height of the media item', |
| 38 |
'width' => '(int) (Image & video only) Width of the media item', |
| 39 |
'length' => '(int) (Video & audio only) Duration of the media item, in seconds', |
| 40 |
'exif' => '(array) (Image & audio only) Exif (meta) information about the media item', |
| 41 |
'rating' => '(string) (Video only) VideoPress rating of the video', |
| 42 |
'display_embed' => '(string) Video only. Whether to share or not the video.', |
| 43 |
'allow_download' => '(string) Video only. Whether the video can be downloaded or not.', |
| 44 |
'videopress_guid' => '(string) (Video only) VideoPress GUID of the video when uploaded on a blog with VideoPress', |
| 45 |
'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.', |
| 46 |
'revision_history' => '(object) An object with `items` and `original` keys. ' . |
| 47 |
'`original` is an object with data about the original image. ' . |
| 48 |
'`items` is an array of snapshots of the previous images of this Media. ' . |
| 49 |
'Each item has the `URL`, `file, `extension`, `date`, and `mime_type` fields.', |
| 50 |
), |
| 51 |
|
| 52 |
'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/82974409/media/934', |
| 53 |
'example_request_data' => array( |
| 54 |
'headers' => array( |
| 55 |
'authorization' => 'Bearer YOUR_API_TOKEN', |
| 56 |
), |
| 57 |
), |
| 58 |
) |
| 59 |
); |
| 60 |
|
| 61 |
/** |
| 62 |
* GET Media v1_2 endpoint class. |
| 63 |
* |
| 64 |
* @phan-constructor-used-for-side-effects |
| 65 |
*/ |
| 66 |
class WPCOM_JSON_API_Get_Media_v1_2_Endpoint extends WPCOM_JSON_API_Get_Media_v1_1_Endpoint { //phpcs:ignore |
| 67 |
/** |
| 68 |
* |
| 69 |
* API callback. |
| 70 |
* |
| 71 |
* @param string $path - the path. |
| 72 |
* @param int $blog_id - the blog ID. |
| 73 |
* @param int $media_id - the media ID. |
| 74 |
*/ |
| 75 |
public function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
| 76 |
$response = parent::callback( $path, $blog_id, $media_id ); |
| 77 |
|
| 78 |
if ( is_wp_error( $response ) ) { |
| 79 |
return $response; |
| 80 |
} |
| 81 |
|
| 82 |
$media_item = get_post( $media_id ); |
| 83 |
$response->modified = (string) $this->format_date( $media_item->post_modified_gmt, $media_item->post_modified ); |
| 84 |
|
| 85 |
// expose `revision_history` object. |
| 86 |
$response->revision_history = (object) array( |
| 87 |
'items' => (array) Jetpack_Media::get_revision_history( $media_id ), |
| 88 |
'original' => (object) Jetpack_Media::get_original_media( $media_id ), |
| 89 |
); |
| 90 |
|
| 91 |
return $response; |
| 92 |
} |
| 93 |
} |
| 94 |
|