| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Easy Digital Downloads |
| 4 |
* Plugin URI: https://wordpress.org/plugins/easy-digital-downloads/ |
| 5 |
* |
| 6 |
* Compatibility Description: |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace wpCloud\StatelessMedia { |
| 11 |
|
| 12 |
if(!class_exists('wpCloud\StatelessMedia\EDDDownloadMethod')) { |
| 13 |
|
| 14 |
class EDDDownloadMethod extends ICompatibility { |
| 15 |
protected $id = 'edd-download-method'; |
| 16 |
protected $title = 'Easy Digital Downloads'; |
| 17 |
protected $constant = 'WP_STATELESS_COMPATIBILITY_EDD'; |
| 18 |
protected $description = 'Ensures compatibility with the forced download method and WP-Stateless.'; |
| 19 |
|
| 20 |
public function __construct(){ |
| 21 |
$this->init(); |
| 22 |
} |
| 23 |
|
| 24 |
public function module_init($sm){ |
| 25 |
add_action('edd_process_download_headers', array( $this, 'edd_download_method_support' ), 10, 4); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* If EDD download method is Forced (direct) and file goes from GCS then make it to be downloaded right away. |
| 30 |
* |
| 31 |
* @param $requested_file |
| 32 |
* @param $download |
| 33 |
* @param $email |
| 34 |
* @param $payment |
| 35 |
*/ |
| 36 |
public function edd_download_method_support( $requested_file, $download, $email, $payment ) { |
| 37 |
if (!function_exists('edd_is_local_file') || !function_exists('edd_get_file_download_method') ) |
| 38 |
return; |
| 39 |
if (edd_get_file_download_method() != 'direct') |
| 40 |
return; |
| 41 |
if (!edd_is_local_file($requested_file) && strstr($requested_file, 'storage.googleapis.com')) { |
| 42 |
header('Content-Type: application/octet-stream'); |
| 43 |
header("Content-Transfer-Encoding: Binary"); |
| 44 |
header("Content-disposition: attachment; filename=\"" . apply_filters('edd_requested_file_name', basename($requested_file)) . "\""); |
| 45 |
readfile($requested_file); |
| 46 |
exit; |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|