| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ajax Functions |
| 4 |
* |
| 5 |
* @package GamiPress\Easy_Digital_Downloads\Ajax_Functions |
| 6 |
* @since 1.1.2 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
// Return download variations dropdown for requirements UI |
| 13 |
function gamipress_edd_ajax_get_download_variations() { |
| 14 |
|
| 15 |
$download_id = $_POST['post_id']; |
| 16 |
$site_id = $_POST['site_id']; |
| 17 |
|
| 18 |
if ( !isset ( $_POST['selected'] ) ) { |
| 19 |
$selected = 0; |
| 20 |
} else { |
| 21 |
$selected = $_POST['selected']; |
| 22 |
} |
| 23 |
|
| 24 |
if( gamipress_is_network_wide_active() && $site_id !== get_current_blog_id() ) { |
| 25 |
switch_to_blog( $site_id ); |
| 26 |
$download = edd_get_download( $download_id ); |
| 27 |
restore_current_blog(); |
| 28 |
} else { |
| 29 |
$download = edd_get_download( $download_id ); |
| 30 |
} |
| 31 |
|
| 32 |
// Bail if download doesn't exists |
| 33 |
if( ! $download ) { |
| 34 |
die(); |
| 35 |
} |
| 36 |
|
| 37 |
$output = gamipress_edd_get_download_variations_dropdown( $download_id, $selected, $site_id ); |
| 38 |
|
| 39 |
// Bail if download has no variations |
| 40 |
if( empty( $output ) ) { |
| 41 |
echo '<span style="color: #a00;">This download has no variations</span>'; |
| 42 |
die(); |
| 43 |
} |
| 44 |
|
| 45 |
echo $output; |
| 46 |
die(); |
| 47 |
|
| 48 |
} |
| 49 |
add_action( 'wp_ajax_gamipress_edd_get_download_variations', 'gamipress_edd_ajax_get_download_variations' ); |