jetpack
2 years ago
class.wpcom-json-api-add-widget-endpoint.php
2 years ago
class.wpcom-json-api-autosave-post-v1-1-endpoint.php
5 years ago
class.wpcom-json-api-bulk-delete-post-endpoint.php
4 years ago
class.wpcom-json-api-bulk-restore-post-endpoint.php
2 years ago
class.wpcom-json-api-bulk-update-comments-endpoint.php
3 years ago
class.wpcom-json-api-comment-endpoint.php
2 years ago
class.wpcom-json-api-delete-media-endpoint.php
4 years ago
class.wpcom-json-api-delete-media-v1-1-endpoint.php
4 years ago
class.wpcom-json-api-edit-media-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-get-autosave-v1-1-endpoint.php
5 years ago
class.wpcom-json-api-get-comment-counts-endpoint.php
4 years ago
class.wpcom-json-api-get-comment-endpoint.php
4 years ago
class.wpcom-json-api-get-comment-history-endpoint.php
4 years ago
class.wpcom-json-api-get-comments-tree-endpoint.php
4 years ago
class.wpcom-json-api-get-comments-tree-v1-1-endpoint.php
4 years ago
class.wpcom-json-api-get-comments-tree-v1-2-endpoint.php
4 years ago
class.wpcom-json-api-get-customcss.php
2 years ago
class.wpcom-json-api-get-media-endpoint.php
4 years ago
class.wpcom-json-api-get-media-v1-1-endpoint.php
4 years ago
class.wpcom-json-api-get-media-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-get-post-counts-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-get-post-endpoint.php
2 years ago
class.wpcom-json-api-get-post-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-get-site-endpoint.php
1 year ago
class.wpcom-json-api-get-site-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-get-taxonomies-endpoint.php
2 years ago
class.wpcom-json-api-get-taxonomy-endpoint.php
4 years ago
class.wpcom-json-api-get-term-endpoint.php
4 years ago
class.wpcom-json-api-list-comments-endpoint.php
2 years ago
class.wpcom-json-api-list-dropdown-pages-endpoint.php
3 years ago
class.wpcom-json-api-list-embeds-endpoint.php
4 years ago
class.wpcom-json-api-list-media-endpoint.php
2 years ago
class.wpcom-json-api-list-media-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-list-media-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
4 years ago
class.wpcom-json-api-list-post-types-endpoint.php
3 years ago
class.wpcom-json-api-list-posts-endpoint.php
2 years ago
class.wpcom-json-api-list-posts-v1-1-endpoint.php
3 years ago
class.wpcom-json-api-list-posts-v1-2-endpoint.php
3 years ago
class.wpcom-json-api-list-roles-endpoint.php
2 years ago
class.wpcom-json-api-list-shortcodes-endpoint.php
4 years ago
class.wpcom-json-api-list-terms-endpoint.php
2 years ago
class.wpcom-json-api-list-users-endpoint.php
2 years ago
class.wpcom-json-api-menus-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-post-endpoint.php
2 years ago
class.wpcom-json-api-post-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-render-embed-endpoint.php
2 years ago
class.wpcom-json-api-render-embed-reversal-endpoint.php
2 years ago
class.wpcom-json-api-render-endpoint.php
3 years ago
class.wpcom-json-api-render-shortcode-endpoint.php
3 years ago
class.wpcom-json-api-sharing-buttons-endpoint.php
2 years ago
class.wpcom-json-api-site-settings-endpoint.php
1 year ago
class.wpcom-json-api-site-settings-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-site-settings-v1-3-endpoint.php
2 years ago
class.wpcom-json-api-site-settings-v1-4-endpoint.php
1 year ago
class.wpcom-json-api-site-user-endpoint.php
2 years ago
class.wpcom-json-api-taxonomy-endpoint.php
4 years ago
class.wpcom-json-api-update-comment-endpoint.php
2 years ago
class.wpcom-json-api-update-customcss.php
2 years ago
class.wpcom-json-api-update-media-endpoint.php
4 years ago
class.wpcom-json-api-update-media-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-update-post-endpoint.php
3 years ago
class.wpcom-json-api-update-post-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-update-post-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-update-site-homepage-endpoint.php
4 years ago
class.wpcom-json-api-update-site-logo-endpoint.php
2 years ago
class.wpcom-json-api-update-taxonomy-endpoint.php
4 years ago
class.wpcom-json-api-update-term-endpoint.php
4 years ago
class.wpcom-json-api-update-user-endpoint.php
3 years ago
class.wpcom-json-api-upload-media-endpoint.php
3 years ago
class.wpcom-json-api-upload-media-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-update-media-endpoint.php
102 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Update media item info endpoint. |
| 4 | * |
| 5 | * Endpoint: /sites/%s/media/%d |
| 6 | */ |
| 7 | |
| 8 | new WPCOM_JSON_API_Update_Media_Endpoint( |
| 9 | array( |
| 10 | 'description' => 'Edit basic information about a media item.', |
| 11 | 'group' => 'media', |
| 12 | 'stat' => 'media:1:POST', |
| 13 | 'method' => 'POST', |
| 14 | 'path' => '/sites/%s/media/%d', |
| 15 | 'deprecated' => true, |
| 16 | 'max_version' => '1', |
| 17 | 'new_version' => '1.1', |
| 18 | 'path_labels' => array( |
| 19 | '$site' => '(int|string) Site ID or domain', |
| 20 | '$media_ID' => '(int) The ID of the media item', |
| 21 | ), |
| 22 | |
| 23 | 'request_format' => array( |
| 24 | 'title' => '(string) The file name.', |
| 25 | 'caption' => '(string) File caption.', |
| 26 | 'description' => '(HTML) Description of the file.', |
| 27 | ), |
| 28 | |
| 29 | 'response_format' => array( |
| 30 | 'id' => '(int) The ID of the media item', |
| 31 | 'date' => '(ISO 8601 datetime) The date the media was uploaded', |
| 32 | 'parent' => '(int) ID of the post this media is attached to', |
| 33 | 'link' => '(string) URL to the file', |
| 34 | 'title' => '(string) File name', |
| 35 | 'caption' => '(string) User provided caption of the file', |
| 36 | 'description' => '(string) Description of the file', |
| 37 | 'metadata' => '(array) Array of metadata about the file, such as Exif data or sizes', |
| 38 | ), |
| 39 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/446', |
| 40 | 'example_request_data' => array( |
| 41 | 'headers' => array( |
| 42 | 'authorization' => 'Bearer YOUR_API_TOKEN', |
| 43 | ), |
| 44 | 'body' => array( |
| 45 | 'title' => 'Updated Title', |
| 46 | ), |
| 47 | ), |
| 48 | ) |
| 49 | ); |
| 50 | |
| 51 | /** |
| 52 | * Update media item info class. |
| 53 | */ |
| 54 | class WPCOM_JSON_API_Update_Media_Endpoint extends WPCOM_JSON_API_Endpoint { |
| 55 | /** |
| 56 | * Update media item info API callback. |
| 57 | * |
| 58 | * @param string $path API path. |
| 59 | * @param int $blog_id Blog ID. |
| 60 | * @param int $media_id Media ID. |
| 61 | * |
| 62 | * @return object|WP_Error |
| 63 | */ |
| 64 | public function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
| 65 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
| 66 | if ( is_wp_error( $blog_id ) ) { |
| 67 | return $blog_id; |
| 68 | } |
| 69 | |
| 70 | if ( ! current_user_can( 'upload_files', $media_id ) ) { |
| 71 | return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); |
| 72 | } |
| 73 | |
| 74 | $item = $this->get_media_item( $media_id ); |
| 75 | |
| 76 | if ( is_wp_error( $item ) ) { |
| 77 | return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); |
| 78 | } |
| 79 | |
| 80 | $input = $this->input( true ); |
| 81 | $insert = array(); |
| 82 | |
| 83 | if ( ! empty( $input['title'] ) ) { |
| 84 | $insert['post_title'] = $input['title']; |
| 85 | } |
| 86 | |
| 87 | if ( ! empty( $input['caption'] ) ) { |
| 88 | $insert['post_excerpt'] = $input['caption']; |
| 89 | } |
| 90 | |
| 91 | if ( ! empty( $input['description'] ) ) { |
| 92 | $insert['post_content'] = $input['description']; |
| 93 | } |
| 94 | |
| 95 | $insert['ID'] = $media_id; |
| 96 | wp_update_post( (object) $insert ); |
| 97 | |
| 98 | $item = $this->get_media_item( $media_id ); |
| 99 | return $item; |
| 100 | } |
| 101 | } |
| 102 |