class.wpcom-json-api-get-media-v1-2-endpoint.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. jetpack_require_lib( 'class.media' );
  3. new WPCOM_JSON_API_Get_Media_v1_2_Endpoint( array(
  4. 'description' => 'Get a single media item (by ID).',
  5. 'group' => 'media',
  6. 'stat' => 'media:1',
  7. 'min_version' => '1.2',
  8. 'max_version' => '1.2',
  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. 'revision_history' => '(object) An object with `items` and `original` keys. ' .
  37. '`original` is an object with data about the original image. ' .
  38. '`items` is an array of snapshots of the previous images of this Media. ' .
  39. 'Each item has the `URL`, `file, `extension`, `date`, and `mime_type` fields.'
  40. ),
  41. 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/82974409/media/934',
  42. 'example_request_data' => array(
  43. 'headers' => array(
  44. 'authorization' => 'Bearer YOUR_API_TOKEN'
  45. )
  46. )
  47. ) );
  48. class WPCOM_JSON_API_Get_Media_v1_2_Endpoint extends WPCOM_JSON_API_Get_Media_v1_1_Endpoint {
  49. function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
  50. $response = parent::callback( $path, $blog_id, $media_id );
  51. if ( is_wp_error( $response ) ) {
  52. return $response;
  53. }
  54. $media_item = get_post( $media_id );
  55. $response->modified = (string) $this->format_date( $media_item->post_modified_gmt, $media_item->post_modified );
  56. // expose `revision_history` object
  57. $response->revision_history = (object) array(
  58. 'items' => (array) Jetpack_Media::get_revision_history( $media_id ),
  59. 'original' => (object) Jetpack_Media::get_original_media( $media_id )
  60. );
  61. return $response;
  62. }
  63. }