create_local_media_library_for_videopress_guid

Creates a local media library item of a remote VideoPress video.

Description

(int|object) create_local_media_library_for_videopress_guid( $guid, (int) $parent_id = 0 ); 

Returns (int|object)

Parameters (2)

0. $guid
The guid.
1. $parent_id — Optional. (int)
The parent id.

Usage

  1. if ( !function_exists( 'create_local_media_library_for_videopress_guid' ) ) { 
  2. require_once '/modules/videopress/utility-functions.php'; 
  3.  
  4. // The guid. 
  5. $guid = null; 
  6.  
  7. // The parent id. 
  8. $parent_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = create_local_media_library_for_videopress_guid($guid, $parent_id); 
  12.  

Defined (1)

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

/modules/videopress/utility-functions.php  
  1. function create_local_media_library_for_videopress_guid( $guid, $parent_id = 0 ) { 
  2. $vp_data = videopress_get_video_details( $guid ); 
  3. if ( ! $vp_data || is_wp_error( $vp_data ) ) { 
  4. return $vp_data; 
  5.  
  6. $args = array( 
  7. 'post_date' => $vp_data->upload_date,  
  8. 'post_title' => wp_kses( $vp_data->title, array() ),  
  9. 'post_content' => wp_kses( $vp_data->description, array() ),  
  10. 'post_mime_type' => 'video/videopress',  
  11. 'guid' => sprintf( 'https://videopress.com/v/%s', $guid ),  
  12. ); 
  13.  
  14. $attachment_id = wp_insert_attachment( $args, null, $parent_id ); 
  15.  
  16. if ( ! is_wp_error( $attachment_id ) ) { 
  17. update_post_meta( $attachment_id, 'videopress_guid', $guid ); 
  18. wp_update_attachment_metadata( $attachment_id, array( 
  19. 'width' => $vp_data->width,  
  20. 'height' => $vp_data->height,  
  21. ) ); 
  22.  
  23. $thumbnail_id = videopress_download_poster_image( $vp_data->poster, $attachment_id ); 
  24. update_post_meta( $attachment_id, '_thumbnail_id', $thumbnail_id ); 
  25.  
  26. return $attachment_id;