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 | jetpack_require_lib( 'class.media' ); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 4 | |||
| 5 | new WPCOM_JSON_API_List_Media_v1_2_Endpoint( array( |
||
| 6 | 'description' => 'Get a list of items in the media library.', |
||
| 7 | 'group' => 'media', |
||
| 8 | 'stat' => 'media', |
||
| 9 | 'min_version' => '1.2', |
||
| 10 | 'max_version' => '1.2', |
||
| 11 | 'method' => 'GET', |
||
| 12 | 'path' => '/sites/%s/media/', |
||
| 13 | 'path_labels' => array( |
||
| 14 | '$site' => '(int|string) Site ID or domain', |
||
| 15 | ), |
||
| 16 | |||
| 17 | 'query_parameters' => array( |
||
| 18 | 'number' => '(int=20) The number of media items to return. Limit: 100.', |
||
| 19 | 'offset' => '(int=0) 0-indexed offset.', |
||
| 20 | 'page' => '(int) Return the Nth 1-indexed page of posts. Takes precedence over the <code>offset</code> parameter.', |
||
| 21 | 'page_handle' => '(string) A page handle, returned from a previous API call as a <code>meta.next_page</code> property. This is the most efficient way to fetch the next page of results.', |
||
| 22 | 'order' => array( |
||
| 23 | 'DESC' => 'Return files in descending order. For dates, that means newest to oldest.', |
||
| 24 | 'ASC' => 'Return files in ascending order. For dates, that means oldest to newest.', |
||
| 25 | ), |
||
| 26 | 'order_by' => array( |
||
| 27 | 'date' => 'Order by the uploaded time of each file.', |
||
| 28 | 'title' => "Order lexicographically by file titles.", |
||
| 29 | 'ID' => 'Order by media ID.', |
||
| 30 | ), |
||
| 31 | 'search' => '(string) Search query.', |
||
| 32 | 'post_ID' => '(int) Default is showing all items. The post where the media item is attached. 0 shows unattached media items.', |
||
| 33 | 'mime_type' => "(string) Default is empty. Filter by mime type (e.g., 'image/jpeg', 'application/pdf'). Partial searches also work (e.g. passing 'image' will search for all image files).", |
||
| 34 | 'after' => '(ISO 8601 datetime) Return media items uploaded after the specified datetime.', |
||
| 35 | 'before' => '(ISO 8601 datetime) Return media items uploaded before the specified datetime.', |
||
| 36 | ), |
||
| 37 | |||
| 38 | 'response_format' => array( |
||
| 39 | 'media' => '(array) Array of media objects', |
||
| 40 | 'found' => '(int) The number of total results found', |
||
| 41 | 'meta' => '(object) Meta data', |
||
| 42 | ), |
||
| 43 | |||
| 44 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/82974409/media', |
||
| 45 | 'example_request_data' => array( |
||
| 46 | 'headers' => array( |
||
| 47 | 'authorization' => 'Bearer YOUR_API_TOKEN' |
||
| 48 | ) |
||
| 49 | ) |
||
| 50 | ) ); |
||
| 51 | |||
| 52 | class WPCOM_JSON_API_List_Media_v1_2_Endpoint extends WPCOM_JSON_API_List_Media_v1_1_Endpoint { |
||
| 53 | function callback( $path = '', $blog_id = 0 ) { |
||
| 54 | $response = parent::callback( $path, $blog_id ); |
||
| 55 | |||
| 56 | if ( is_wp_error( $response ) ) { |
||
| 57 | return $response; |
||
| 58 | } |
||
| 59 | |||
| 60 | $media_list = $response['media']; |
||
| 61 | |||
| 62 | if ( count( $media_list ) < 1 ) { |
||
| 63 | return $response; |
||
| 64 | } |
||
| 65 | |||
| 66 | foreach ( $media_list as $index => $media_item ) { |
||
| 67 | // expose `revision_history` object for each image |
||
| 68 | $media_item->revision_history = (object) array( |
||
| 69 | 'items' => (array) Media::get_revision_history( $media_item->ID ), |
||
| 70 | 'original' => (object) Media::get_original_media( $media_item->ID ) |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | |||
| 74 | return $response; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 |