edd_ajax_generate_file_download_link

Retrieves a new download link for a purchased file.

Description

(string) edd_ajax_generate_file_download_link(); 

Returns (string)


Usage

  1. if ( !function_exists( 'edd_ajax_generate_file_download_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-digital-downloads/includes/admin/payments/actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = edd_ajax_generate_file_download_link(); 
  7.  

Defined (1)

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

/includes/admin/payments/actions.php  
  1. function edd_ajax_generate_file_download_link() { 
  2.  
  3. $customer_view_role = apply_filters( 'edd_view_customers_role', 'view_shop_reports' ); 
  4. if ( ! current_user_can( $customer_view_role ) ) { 
  5. die( '-1' ); 
  6.  
  7. $payment_id = absint( $_POST['payment_id'] ); 
  8. $download_id = absint( $_POST['download_id'] ); 
  9. $price_id = absint( $_POST['price_id'] ); 
  10.  
  11. if( empty( $payment_id ) ) 
  12. die( '-2' ); 
  13.  
  14. if( empty( $download_id ) ) 
  15. die( '-3' ); 
  16.  
  17. $payment_key = edd_get_payment_key( $payment_id ); 
  18. $email = edd_get_payment_user_email( $payment_id ); 
  19.  
  20. $limit = edd_get_file_download_limit( $download_id ); 
  21. if ( ! empty( $limit ) ) { 
  22. // Increase the file download limit when generating new links 
  23. edd_set_file_download_limit_override( $download_id, $payment_id ); 
  24.  
  25. $files = edd_get_download_files( $download_id, $price_id ); 
  26. if( ! $files ) { 
  27. die( '-4' ); 
  28.  
  29. $file_urls = ''; 
  30.  
  31. foreach( $files as $file_key => $file ) { 
  32.  
  33. $file_urls .= edd_get_download_file_url( $payment_key, $email, $file_key, $download_id, $price_id ); 
  34. $file_urls .= "\n\n"; 
  35.  
  36.  
  37. die( $file_urls ); 
  38.