PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.5.2
Jetpack – WP Security, Backup, Speed, & Growth v13.5.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / json-endpoints / class.wpcom-json-api-delete-media-endpoint.php
class.wpcom-json-api-delete-media-endpoint.php
71 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
2
3 new WPCOM_JSON_API_Delete_Media_Endpoint(
4 array(
5 'description' => 'Delete a piece of media.',
6 'group' => 'media',
7 'stat' => 'media:1:delete',
8 'method' => 'POST',
9 'path' => '/sites/%s/media/%d/delete',
10 'deprecated' => true,
11 'new_version' => '1.1',
12 'max_version' => '1',
13 'path_labels' => array(
14 '$site' => '(int|string) Site ID or domain',
15 '$media_ID' => '(int) The media ID',
16 ),
17
18 'response_format' => array(
19 'status' => '(string) Returns deleted if the media was successfully deleted',
20 'id' => '(int) The ID of the media item',
21 'date' => '(ISO 8601 datetime) The date the media was uploaded',
22 'parent' => '(int) ID of the post this media is attached to',
23 'link' => '(string) URL to the file',
24 'title' => '(string) File name',
25 'caption' => '(string) User provided caption of the file',
26 'description' => '(string) Description of the file',
27 'metadata' => '(array) Misc array of information about the file, such as exif data or sizes',
28 ),
29
30 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/$media_ID/delete',
31 'example_request_data' => array(
32 'headers' => array(
33 'authorization' => 'Bearer YOUR_API_TOKEN',
34 ),
35 ),
36 )
37 );
38
39 /**
40 * Delete media endpoint class.
41 */
42 class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
43 /**
44 * API callback.
45 *
46 * @param string $path - the path.
47 * @param int $blog_id - the blog ID.
48 * @param int $media_id - the media ID.
49 */
50 public function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
51 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
52 if ( is_wp_error( $blog_id ) ) {
53 return $blog_id;
54 }
55
56 if ( ! current_user_can( 'delete_post', $media_id ) ) {
57 return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
58 }
59
60 $item = $this->get_media_item( $media_id );
61
62 if ( is_wp_error( $item ) ) {
63 return new WP_Error( 'unknown_media', 'Unknown Media', 404 );
64 }
65
66 wp_delete_post( $media_id );
67 $item->status = 'deleted';
68 return $item;
69 }
70 }
71