class.wpcom-json-api-get-media-v1-1-endpoint.php 2.8 KB

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