videopress_get_attachment_url

From the given VideoPress post_id, return back the appropriate attachment URL.

Description

(string|null) videopress_get_attachment_url( (int) $post_id ); 

When the MP4 hasn't been processed yet or this is not a VideoPress video, this will return null.

Returns (string|null)

Parameters (1)

0. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( 'videopress_get_attachment_url' ) ) { 
  2. require_once '/modules/videopress/utility-functions.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = videopress_get_attachment_url($post_id); 
  9.  

Defined (1)

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

/modules/videopress/utility-functions.php  
  1. function videopress_get_attachment_url( $post_id ) { 
  2.  
  3. // We only handle VideoPress attachments. 
  4. if ( get_post_mime_type( $post_id ) !== 'video/videopress' ) { 
  5. return null; 
  6.  
  7. $meta = wp_get_attachment_metadata( $post_id ); 
  8.  
  9. if ( ! isset( $meta['videopress']['files']['hd']['mp4'] ) ) { 
  10. // Use the original file as the url if it isn't transcoded yet. 
  11. if ( isset( $meta['original'] ) ) { 
  12. return $meta['original']; 
  13.  
  14. // Otherwise, there isn't much we can do. 
  15. return null; 
  16.  
  17. return $meta['videopress']['file_url_base']['https'] . $meta['videopress']['files']['hd']['mp4'];