• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / edd_get_download_file_url() – Get Download File Url Constructs a secure file download url for a specific file.

You appear to be a bot. Output may be restricted

Description

Get Download File Url Constructs a secure file download url for a specific file.

Usage

$string = edd_get_download_file_url( $key, $email, $filekey, $download_id, $price_id );

Parameters

$key
( string ) required – Payment key. Use edd_get_payment_key() to get key.
$email
( string ) required – Customer email address. Use edd_get_payment_user_email() to get user email.
$filekey
( int ) required – Index of array of files returned by edd_get_download_files() that this download link is for.
$download_id
( int ) optional – Optional. ID of download this download link is for. Default is 0.
$price_id
( bool|int ) optional – Optional. Price ID when using variable prices. Default is false.

Returns

string A secure download URL

Source

File name: easy-digital-downloads/includes/download-functions.php
Lines:

1 to 50 of 50
function edd_get_download_file_url( $key, $email, $filekey, $download_id = 0, $price_id = false ) {

  $hours = absint( edd_get_option( 'download_link_expiration', 24 ) );

  if ( ! ( $date = strtotime( '+' . $hours . 'hours', current_time( 'timestamp') ) ) ) {
    $date = 2147472000; // Highest possible date, January 19, 2038
  }

  // Leaving in this array and the filter for backwards compatibility now
  $old_args = array(
    'download_key'   => rawurlencode( $key ),
    'email'         => rawurlencode( $email ),
    'file'          => rawurlencode( $filekey ),
    'price_id'      => (int) $price_id,
    'download_id'   => $download_id,
    'expire'        => rawurlencode( $date )
  );

  $params  = apply_filters( 'edd_download_file_url_args', $old_args );
  $payment = edd_get_payment_by( 'key', $params['download_key'] );

  if ( ! $payment ) {
    return false;
  }

  $args = array();

  if ( ! empty( $payment->ID ) ) {

    // Get the array of parameters in the same order in which they will be validated.
    $args = array_fill_keys( edd_get_url_token_parameters(), '' );

    // Simply the URL by concatenating required data using a colon as a delimiter.
    $args['eddfile'] = rawurlencode( sprintf( '%d:%d:%d:%d', $payment->ID, $params['download_id'], $params['file'], $price_id ) );

    if ( isset( $params['expire'] ) ) {
      $args['ttl'] = $params['expire'];
    }

    // Ensure all custom args registered with extensions through edd_download_file_url_args get added to the URL, but without adding all the old args
    $args = array_merge( $args, array_diff_key( $params, $old_args ) );

    $args = apply_filters( 'edd_get_download_file_url_args', $args, $payment->ID, $params );

    $args['file']  = $params['file'];
    $args['token'] = edd_get_download_token( add_query_arg( array_filter( $args ), untrailingslashit( site_url() ) ) );
  }

  return add_query_arg( array_filter( $args ), site_url( 'index.php' ) );
}
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th January 2022

Primary Sidebar

Information

Function name: edd_get_download_file_url
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/download-functions.php
File ref: includes/download-functions.php
Deprecated?: No
API Letters: D,E,F,G,U

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites