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_Update_Media_v1_1_Endpoint( array( |
||
| 4 | 'description' => 'Edit basic information about a media item.', |
||
| 5 | 'group' => 'media', |
||
| 6 | 'stat' => 'media:1:POST', |
||
| 7 | 'min_version' => '1.1', |
||
| 8 | 'max_version' => '1.1', |
||
| 9 | 'method' => 'POST', |
||
| 10 | 'path' => '/sites/%s/media/%d', |
||
| 11 | 'path_labels' => array( |
||
| 12 | '$site' => '(int|string) Site ID or domain', |
||
| 13 | '$media_ID' => '(int) The ID of the media item', |
||
| 14 | ), |
||
| 15 | |||
| 16 | 'request_format' => array( |
||
| 17 | 'parent_id' => '(int) ID of the post this media is attached to', |
||
| 18 | 'title' => '(string) The file name.', |
||
| 19 | 'caption' => '(string) File caption.', |
||
| 20 | 'description' => '(HTML) Description of the file.', |
||
| 21 | 'alt' => "(string) Alternative text for image files.", |
||
| 22 | 'artist' => "(string) Audio Only. Artist metadata for the audio track.", |
||
| 23 | 'album' => "(string) Audio Only. Album metadata for the audio track.", |
||
| 24 | ), |
||
| 25 | |||
| 26 | 'response_format' => array( |
||
| 27 | 'ID' => '(int) The ID of the media item', |
||
| 28 | 'date' => '(ISO 8601 datetime) The date the media was uploaded', |
||
| 29 | 'post_ID' => '(int) ID of the post this media is attached to', |
||
| 30 | 'author_ID' => '(int) ID of the user who uploaded the media', |
||
| 31 | 'URL' => '(string) URL to the file', |
||
| 32 | 'guid' => '(string) Unique identifier', |
||
| 33 | 'file' => '(string) File name', |
||
| 34 | 'extension' => '(string) File extension', |
||
| 35 | 'mime_type' => '(string) File mime type', |
||
| 36 | 'title' => '(string) File name', |
||
| 37 | 'caption' => '(string) User provided caption of the file', |
||
| 38 | 'description' => '(string) Description of the file', |
||
| 39 | 'alt' => '(string) Alternative text for image files.', |
||
| 40 | 'thumbnails' => '(object) Media item thumbnail URL options', |
||
| 41 | 'height' => '(int) (Image & video only) Height of the media item', |
||
| 42 | 'width' => '(int) (Image & video only) Width of the media item', |
||
| 43 | 'length' => '(int) (Video & audio only) Duration of the media item, in seconds', |
||
| 44 | 'exif' => '(array) (Image & audio only) Exif (meta) information about the media item', |
||
| 45 | 'videopress_guid' => '(string) (Video only) VideoPress GUID of the video when uploaded on a blog with VideoPress', |
||
| 46 | 'videopress_processing_done' => '(bool) (Video only) If the video is uploaded on a blog with VideoPress, this will return the status of processing on the video.' |
||
| 47 | ), |
||
| 48 | |||
| 49 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/446', |
||
| 50 | 'example_request_data' => array( |
||
| 51 | 'headers' => array( |
||
| 52 | 'authorization' => 'Bearer YOUR_API_TOKEN' |
||
| 53 | ), |
||
| 54 | 'body' => array( |
||
| 55 | 'title' => 'Updated Title' |
||
| 56 | ) |
||
| 57 | ) |
||
| 58 | ) ); |
||
| 59 | |||
| 60 | class WPCOM_JSON_API_Update_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint { |
||
| 61 | function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
||
| 62 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
| 63 | if ( is_wp_error( $blog_id ) ) { |
||
| 64 | return $blog_id; |
||
| 65 | } |
||
| 66 | |||
| 67 | if ( ! current_user_can( 'upload_files', $media_id ) ) { |
||
| 68 | return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); |
||
|
0 ignored issues
–
show
|
|||
| 69 | } |
||
| 70 | |||
| 71 | $item = $this->get_media_item_v1_1( $media_id ); |
||
| 72 | |||
| 73 | if ( is_wp_error( $item ) ) { |
||
| 74 | 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...
|
|||
| 75 | } |
||
| 76 | |||
| 77 | $input = $this->input( true ); |
||
| 78 | $insert = array(); |
||
| 79 | |||
| 80 | if ( isset( $input['title'] ) ) { |
||
| 81 | $insert['post_title'] = $input['title']; |
||
| 82 | } |
||
| 83 | |||
| 84 | if ( isset( $input['caption'] ) ) { |
||
| 85 | $insert['post_excerpt'] = $input['caption']; |
||
| 86 | } |
||
| 87 | |||
| 88 | if ( isset( $input['description'] ) ) { |
||
| 89 | $insert['post_content'] = $input['description']; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ( isset( $input['parent_id'] ) ) { |
||
| 93 | $insert['post_parent'] = $input['parent_id']; |
||
| 94 | } |
||
| 95 | |||
| 96 | View Code Duplication | if ( isset( $input['alt'] ) ) { |
|
| 97 | $alt = wp_strip_all_tags( $input['alt'], true ); |
||
| 98 | update_post_meta( $media_id, '_wp_attachment_image_alt', $alt ); |
||
| 99 | } |
||
| 100 | |||
| 101 | // audio only artist/album info |
||
| 102 | if ( 0 === strpos( $item->mime_type, 'audio/' ) ) { |
||
| 103 | $changed = false; |
||
| 104 | $id3data = wp_get_attachment_metadata( $media_id ); |
||
| 105 | |||
| 106 | if ( ! is_array( $id3data ) ) { |
||
| 107 | $changed = true; |
||
| 108 | $id3data = array(); |
||
| 109 | } |
||
| 110 | |||
| 111 | $id3_keys = array( |
||
| 112 | 'artist' => __( 'Artist', 'jetpack' ), |
||
| 113 | 'album' => __( 'Album', 'jetpack' ) |
||
| 114 | ); |
||
| 115 | |||
| 116 | foreach ( $id3_keys as $key => $label ) { |
||
| 117 | if ( isset( $input[ $key ] ) ) { |
||
| 118 | $changed = true; |
||
| 119 | $id3data[ $key ] = wp_strip_all_tags( $input[ $key ], true ); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | if ( $changed ) { |
||
| 124 | wp_update_attachment_metadata( $media_id, $id3data ); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | $insert['ID'] = $media_id; |
||
| 129 | wp_update_post( (object) $insert ); |
||
| 130 | |||
| 131 | $item = $this->get_media_item_v1_1( $media_id ); |
||
| 132 | return $item; |
||
| 133 | } |
||
| 134 | } |
||
| 135 |
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.