|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
new WPCOM_JSON_API_Update_Media_Endpoint( array( |
|
4
|
|
|
'description' => 'Edit basic information about a media item.', |
|
5
|
|
|
'group' => 'media', |
|
6
|
|
|
'stat' => 'media:1:POST', |
|
7
|
|
|
'method' => 'POST', |
|
8
|
|
|
'path' => '/sites/%s/media/%d', |
|
9
|
|
|
'deprecated' => true, |
|
10
|
|
|
'max_version' => '1', |
|
11
|
|
|
'new_version' => '1.1', |
|
12
|
|
|
'path_labels' => array( |
|
13
|
|
|
'$site' => '(int|string) Site ID or domain', |
|
14
|
|
|
'$media_ID' => '(int) The ID of the media item', |
|
15
|
|
|
), |
|
16
|
|
|
|
|
17
|
|
|
'request_format' => array( |
|
18
|
|
|
'title' => '(string) The file name.', |
|
19
|
|
|
'caption' => '(string) File caption.', |
|
20
|
|
|
'description' => '(HTML) Description of the file.', |
|
21
|
|
|
), |
|
22
|
|
|
|
|
23
|
|
|
'response_format' => array( |
|
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) Array of metadata about the file, such as Exif data or sizes', |
|
32
|
|
|
), |
|
33
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/446', |
|
34
|
|
|
'example_request_data' => array( |
|
35
|
|
|
'headers' => array( |
|
36
|
|
|
'authorization' => 'Bearer YOUR_API_TOKEN' |
|
37
|
|
|
), |
|
38
|
|
|
'body' => array( |
|
39
|
|
|
'title' => 'Updated Title' |
|
40
|
|
|
) |
|
41
|
|
|
) |
|
42
|
|
|
) ); |
|
43
|
|
|
|
|
44
|
|
|
class WPCOM_JSON_API_Update_Media_Endpoint extends WPCOM_JSON_API_Endpoint { |
|
45
|
|
|
function callback( $path = '', $blog_id = 0, $media_id = 0 ) { |
|
46
|
|
|
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
|
47
|
|
|
if ( is_wp_error( $blog_id ) ) { |
|
48
|
|
|
return $blog_id; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if ( !current_user_can( 'upload_files', $media_id ) ) { |
|
52
|
|
|
return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$item = $this->get_media_item( $media_id ); |
|
56
|
|
|
|
|
57
|
|
|
if ( is_wp_error( $item ) ) { |
|
58
|
|
|
return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$input = $this->input( true ); |
|
62
|
|
|
$insert = array(); |
|
63
|
|
|
|
|
64
|
|
|
if ( !empty( $input['title'] ) ) { |
|
65
|
|
|
$insert['post_title'] = $input['title']; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ( !empty( $input['caption'] ) ) |
|
69
|
|
|
$insert['post_excerpt'] = $input['caption']; |
|
70
|
|
|
|
|
71
|
|
|
if ( !empty( $input['description'] ) ) |
|
72
|
|
|
$insert['post_content'] = $input['description']; |
|
73
|
|
|
|
|
74
|
|
|
$insert['ID'] = $media_id; |
|
75
|
|
|
wp_update_post( (object) $insert ); |
|
76
|
|
|
|
|
77
|
|
|
$item = $this->get_media_item( $media_id ); |
|
78
|
|
|
return $item; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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.