Нет описания

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. new WPCOM_JSON_API_Get_Media_v1_1_Endpoint(
  3. array(
  4. 'description' => 'Get a single media item (by ID).',
  5. 'group' => 'media',
  6. 'stat' => 'media:1',
  7. 'min_version' => '1.1',
  8. 'max_version' => '1.1',
  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. 'rating' => '(string) (Video only) VideoPress rating of the video',
  35. 'display_embed' => '(string) Video only. Whether to share or not the video.',
  36. 'videopress_guid' => '(string) (Video only) VideoPress GUID of the video when uploaded on a blog with VideoPress',
  37. '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.',
  38. ),
  39. 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/934',
  40. 'example_request_data' => array(
  41. 'headers' => array(
  42. 'authorization' => 'Bearer YOUR_API_TOKEN',
  43. ),
  44. ),
  45. )
  46. );
  47. class WPCOM_JSON_API_Get_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint {
  48. function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
  49. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
  50. if ( is_wp_error( $blog_id ) ) {
  51. return $blog_id;
  52. }
  53. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
  54. $this->load_theme_functions();
  55. }
  56. //upload_files can probably be used for other endpoints but we want contributors to be able to use media too
  57. if ( ! current_user_can( 'edit_posts', $media_id ) ) {
  58. return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
  59. }
  60. return $this->get_media_item_v1_1( $media_id );
  61. }
  62. }