Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | new WPCOM_JSON_API_Delete_Media_v1_1_Endpoint( array( |
||
| 4 | 'description' => 'Delete a piece of media. Note: Media is deleted and not trashed.', |
||
| 5 | 'group' => 'media', |
||
| 6 | 'stat' => 'media:1:delete', |
||
| 7 | 'min_version' => '1.1', |
||
| 8 | 'max_version' => '1.1', |
||
| 9 | 'method' => 'POST', |
||
| 10 | 'path' => '/sites/%s/media/%d/delete', |
||
| 11 | 'path_labels' => array( |
||
| 12 | '$site' => '(int|string) Site ID or domain', |
||
| 13 | '$media_ID' => '(int) The media ID', |
||
| 14 | ), |
||
| 15 | |||
| 16 | 'response_format' => array( |
||
| 17 | 'status' => '(string) Returns deleted if the media was successfully deleted', |
||
| 18 | 'ID' => '(int) The ID of the media item', |
||
| 19 | 'date' => '(ISO 8601 datetime) The date the media was uploaded', |
||
| 20 | 'post_ID' => '(int) ID of the post this media is attached to', |
||
| 21 | 'author_ID' => '(int) ID of the user who uploaded the media', |
||
| 22 | 'URL' => '(string) URL to the file', |
||
| 23 | 'guid' => '(string) Unique identifier', |
||
| 24 | 'file' => '(string) File name', |
||
| 25 | 'extension' => '(string) File extension', |
||
| 26 | 'mime_type' => '(string) File mime type', |
||
| 27 | 'title' => '(string) File name', |
||
| 28 | 'caption' => '(string) User-provided caption of the file', |
||
| 29 | 'description' => '(string) Description of the file', |
||
| 30 | 'alt' => '(string) Alternative text for image files.', |
||
| 31 | 'thumbnails' => '(object) Media item thumbnail URL options', |
||
| 32 | 'height' => '(int) (Image & video only) Height of the media item', |
||
| 33 | 'width' => '(int) (Image & video only) Width of the media item', |
||
| 34 | 'length' => '(int) (Video & audio only) Duration of the media item, in seconds', |
||
| 35 | 'exif' => '(array) (Image & audio only) Exif (meta) information about the media item', |
||
| 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 Uuploaded on a blog with VideoPress, this will return the status of processing on the Video' |
||
| 38 | ), |
||
| 39 | |||
| 40 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/$media_ID/delete', |
||
| 41 | 'example_request_data' => array( |
||
| 42 | 'headers' => array( |
||
| 43 | 'authorization' => 'Bearer YOUR_API_TOKEN' |
||
| 44 | ) |
||
| 45 | ) |
||
| 46 | ) ); |
||
| 47 | |||
| 48 | View Code Duplication | class WPCOM_JSON_API_Delete_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint { |
|
| 49 | function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
||
| 50 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
| 51 | if ( is_wp_error( $blog_id ) ) { |
||
| 52 | return $blog_id; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ( ! current_user_can( 'delete_post', $media_id ) ) { |
||
| 56 | return new WP_Error( 'unauthorized', 'User is not authorized delete media', 403 ); |
||
|
0 ignored issues
–
show
|
|||
| 57 | } |
||
| 58 | |||
| 59 | $item = $this->get_media_item_v1_1( $media_id ); |
||
| 60 | |||
| 61 | if ( is_wp_error( $item ) ) { |
||
| 62 | return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); |
||
|
0 ignored issues
–
show
The call to
WP_Error::__construct() has too many arguments starting with 'unknown_media'.
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the Loading history...
|
|||
| 63 | } |
||
| 64 | |||
| 65 | wp_delete_post( $media_id, true ); |
||
| 66 | $item->status = 'deleted'; |
||
| 67 | return $item; |
||
| 68 | } |
||
| 69 | } |
||
| 70 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.