Нет описания

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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. jetpack_require_lib( 'class.media' );
  3. new WPCOM_JSON_API_Get_Media_v1_2_Endpoint(
  4. array(
  5. 'description' => 'Get a single media item (by ID).',
  6. 'group' => 'media',
  7. 'stat' => 'media:1',
  8. 'min_version' => '1.2',
  9. 'max_version' => '1.2',
  10. 'method' => 'GET',
  11. 'path' => '/sites/%s/media/%d',
  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. 'post_ID' => '(int) ID of the post this media is attached to',
  20. 'author_ID' => '(int) ID of the user who uploaded the media',
  21. 'URL' => '(string) URL to the file',
  22. 'guid' => '(string) Unique identifier',
  23. 'file' => '(string) Filename',
  24. 'extension' => '(string) File extension',
  25. 'mime_type' => '(string) File MIME type',
  26. 'title' => '(string) Filename',
  27. 'caption' => '(string) User-provided caption of the file',
  28. 'description' => '(string) Description of the file',
  29. 'alt' => '(string) Alternative text for image files.',
  30. 'thumbnails' => '(object) Media item thumbnail URL options',
  31. 'height' => '(int) (Image & video only) Height of the media item',
  32. 'width' => '(int) (Image & video only) Width of the media item',
  33. 'length' => '(int) (Video & audio only) Duration of the media item, in seconds',
  34. 'exif' => '(array) (Image & audio only) Exif (meta) information about the media item',
  35. 'rating' => '(string) (Video only) VideoPress rating of the video',
  36. 'display_embed' => '(string) Video only. Whether to share or not the video.',
  37. 'videopress_guid' => '(string) (Video only) VideoPress GUID of the video when uploaded on a blog with VideoPress',
  38. '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.',
  39. 'revision_history' => '(object) An object with `items` and `original` keys. ' .
  40. '`original` is an object with data about the original image. ' .
  41. '`items` is an array of snapshots of the previous images of this Media. ' .
  42. 'Each item has the `URL`, `file, `extension`, `date`, and `mime_type` fields.',
  43. ),
  44. 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/82974409/media/934',
  45. 'example_request_data' => array(
  46. 'headers' => array(
  47. 'authorization' => 'Bearer YOUR_API_TOKEN',
  48. ),
  49. ),
  50. )
  51. );
  52. class WPCOM_JSON_API_Get_Media_v1_2_Endpoint extends WPCOM_JSON_API_Get_Media_v1_1_Endpoint {
  53. function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
  54. $response = parent::callback( $path, $blog_id, $media_id );
  55. if ( is_wp_error( $response ) ) {
  56. return $response;
  57. }
  58. $media_item = get_post( $media_id );
  59. $response->modified = (string) $this->format_date( $media_item->post_modified_gmt, $media_item->post_modified );
  60. // expose `revision_history` object.
  61. $response->revision_history = (object) array(
  62. 'items' => (array) Jetpack_Media::get_revision_history( $media_id ),
  63. 'original' => (object) Jetpack_Media::get_original_media( $media_id )
  64. );
  65. return $response;
  66. }
  67. }