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_Endpoint( array( |
||
| 4 | 'description' => 'Delete a piece of media.', |
||
| 5 | 'group' => 'media', |
||
| 6 | 'stat' => 'media:1:delete', |
||
| 7 | 'method' => 'POST', |
||
| 8 | 'path' => '/sites/%s/media/%d/delete', |
||
| 9 | 'deprecated' => true, |
||
| 10 | 'new_version' => '1.1', |
||
| 11 | 'max_version' => '1', |
||
| 12 | 'path_labels' => array( |
||
| 13 | '$site' => '(int|string) Site ID or domain', |
||
| 14 | '$media_ID' => '(int) The media ID', |
||
| 15 | ), |
||
| 16 | |||
| 17 | 'response_format' => array( |
||
| 18 | 'status' => '(string) Returns deleted if the media was successfully deleted', |
||
| 19 | 'id' => '(int) The ID of the media item', |
||
| 20 | 'date' => '(ISO 8601 datetime) The date the media was uploaded', |
||
| 21 | 'parent' => '(int) ID of the post this media is attached to', |
||
| 22 | 'link' => '(string) URL to the file', |
||
| 23 | 'title' => '(string) File name', |
||
| 24 | 'caption' => '(string) User provided caption of the file', |
||
| 25 | 'description' => '(string) Description of the file', |
||
| 26 | 'metadata' => '(array) Misc array of information about the file, such as exif data or sizes', |
||
| 27 | ), |
||
| 28 | |||
| 29 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/$media_ID/delete', |
||
| 30 | 'example_request_data' => array( |
||
| 31 | 'headers' => array( |
||
| 32 | 'authorization' => 'Bearer YOUR_API_TOKEN' |
||
| 33 | ) |
||
| 34 | ) |
||
| 35 | ) ); |
||
| 36 | |||
| 37 | View Code Duplication | class WPCOM_JSON_API_Delete_Media_Endpoint extends WPCOM_JSON_API_Endpoint { |
|
| 38 | function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
||
| 39 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
| 40 | if ( is_wp_error( $blog_id ) ) { |
||
| 41 | return $blog_id; |
||
| 42 | } |
||
| 43 | |||
| 44 | if ( ! current_user_can( 'delete_post', $media_id ) ) { |
||
| 45 | return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); |
||
|
0 ignored issues
–
show
|
|||
| 46 | } |
||
| 47 | |||
| 48 | $item = $this->get_media_item( $media_id ); |
||
| 49 | |||
| 50 | if ( is_wp_error( $item ) ) { |
||
| 51 | 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...
|
|||
| 52 | } |
||
| 53 | |||
| 54 | wp_delete_post( $media_id ); |
||
| 55 | $item->status = 'deleted'; |
||
| 56 | return $item; |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
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.