/** * Returns a signed Amazon S3 download URL. * * @param $bucket string Bucket name * @param $file_name string File name (URI) * @return string The signed download URL */ public static function get_s3_url($bucket, $file_name) { $s3_url = ''; $options = get_option('wp-license-manager-settings'); if (Wp_License_Manager_S3::use_official_api()) { write_log('Using official API '); $s3_url = Wp_License_Manager_S3_Official::get_s3_url($options['aws_key'], $options['aws_secret'], $bucket, $file_name); } else { write_log('Using fallback API '); $s3_url = Wp_License_Manager_S3_Fallback::get_s3_url($options['aws_key'], $options['aws_secret'], $bucket, $file_name); } return $s3_url; }
/** * The handler for the "get" request. Redirects to the file download. * * @param $product WP_Post The product object */ private function get_product($product, $product_id, $email, $license_key) { // Get the AWS data from post meta fields $meta = get_post_meta($product->ID, 'wp_license_manager_product_meta', true); $bucket = isset($meta['file_bucket']) ? $meta['file_bucket'] : ''; $file_name = isset($meta['file_name']) ? $meta['file_name'] : ''; if ($bucket == '' || $file_name == '') { // No file set, return error return $this->error_response('No download defined for product.'); } // Use the AWS API to set up the download // This API method is called directly by WordPress so we need to adhere to its // requirements and skip the JSON. WordPress expects to receive a ZIP file... $s3_url = Wp_License_Manager_S3::get_s3_url($bucket, $file_name); wp_redirect($s3_url, 302); exit; }