WPCOM_JSON_API_Update_Media_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Update Media Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/class.wpcom-json-api-update-media-endpoint.php  
  1. class WPCOM_JSON_API_Update_Media_Endpoint extends WPCOM_JSON_API_Endpoint { 
  2. function callback( $path = '', $blog_id = 0, $media_id = 0 ) { 
  3. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  4. if ( is_wp_error( $blog_id ) ) { 
  5. return $blog_id; 
  6.  
  7. if ( !current_user_can( 'upload_files', $media_id ) ) { 
  8. return new WP_Error( 'unauthorized', 'User cannot view media', 403 ); 
  9.  
  10. $item = $this->get_media_item( $media_id ); 
  11.  
  12. if ( is_wp_error( $item ) ) { 
  13. return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); 
  14.  
  15. $input = $this->input( true ); 
  16. $insert = array(); 
  17.  
  18. if ( !empty( $input['title'] ) ) { 
  19. $insert['post_title'] = $input['title']; 
  20.  
  21. if ( !empty( $input['caption'] ) ) 
  22. $insert['post_excerpt'] = $input['caption']; 
  23.  
  24. if ( !empty( $input['description'] ) ) 
  25. $insert['post_content'] = $input['description']; 
  26.  
  27. $insert['ID'] = $media_id; 
  28. wp_update_post( (object) $insert ); 
  29.  
  30. $item = $this->get_media_item( $media_id ); 
  31. return $item;