PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 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 All 508 releases
← All changes | json-endpoints/class.wpcom-json-api-delete-media-endpoint.php +76 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,76 @@
1 +<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
2 +
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit( 0 );
5 +}
6 +
7 +new WPCOM_JSON_API_Delete_Media_Endpoint(
8 + array(
9 + 'description' => 'Delete a piece of media.',
10 + 'group' => 'media',
11 + 'stat' => 'media:1:delete',
12 + 'method' => 'POST',
13 + 'path' => '/sites/%s/media/%d/delete',
14 + 'deprecated' => true,
15 + 'new_version' => '1.1',
16 + 'max_version' => '1',
17 + 'path_labels' => array(
18 + '$site' => '(int|string) Site ID or domain',
19 + '$media_ID' => '(int) The media ID',
20 + ),
21 +
22 + 'response_format' => array(
23 + 'status' => '(string) Returns deleted if the media was successfully deleted',
24 + 'id' => '(int) The ID of the media item',
25 + 'date' => '(ISO 8601 datetime) The date the media was uploaded',
26 + 'parent' => '(int) ID of the post this media is attached to',
27 + 'link' => '(string) URL to the file',
28 + 'title' => '(string) File name',
29 + 'caption' => '(string) User provided caption of the file',
30 + 'description' => '(string) Description of the file',
31 + 'metadata' => '(array) Misc array of information about the file, such as exif data or sizes',
32 + ),
33 +
34 + 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/$media_ID/delete',
35 + 'example_request_data' => array(
36 + 'headers' => array(
37 + 'authorization' => 'Bearer YOUR_API_TOKEN',
38 + ),
39 + ),
40 + )
41 +);
42 +
43 +/**
44 + * Delete media endpoint class.
45 + *
46 + * @phan-constructor-used-for-side-effects
47 + */
48 +class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint {
49 + /**
50 + * API callback.
51 + *
52 + * @param string $path - the path.
53 + * @param int $blog_id - the blog ID.
54 + * @param int $media_id - the media ID.
55 + */
56 + public function callback( $path = '', $blog_id = 0, $media_id = 0 ) {
57 + $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
58 + if ( is_wp_error( $blog_id ) ) {
59 + return $blog_id;
60 + }
61 +
62 + if ( ! current_user_can( 'delete_post', $media_id ) ) {
63 + return new WP_Error( 'unauthorized', 'User cannot view media', 403 );
64 + }
65 +
66 + $item = $this->get_media_item( $media_id );
67 +
68 + if ( is_wp_error( $item ) ) {
69 + return new WP_Error( 'unknown_media', 'Unknown Media', 404 );
70 + }
71 +
72 + wp_delete_post( $media_id );
73 + $item->status = 'deleted';
74 + return $item;
75 + }
76 +}