/** * Resend the Email Purchase Receipt. (This can be done from the Payment History page) * * @since 1.0 * @param array $data Payment Data * @return void */ function edd_resend_purchase_receipt($data) { $purchase_id = absint($data['purchase_id']); if (empty($purchase_id)) { return; } if (!current_user_can('edit_shop_payments')) { wp_die(__('You do not have permission to edit this payment record', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403)); } $email = !empty($_GET['email']) ? sanitize_text_field($_GET['email']) : ''; if (empty($email)) { $customer = new EDD_Customer(edd_get_payment_customer_id($purchase_id)); $email = $customer->email; } edd_email_purchase_receipt($purchase_id, false, $email); // Grab all downloads of the purchase and update their file download limits, if needed // This allows admins to resend purchase receipts to grant additional file downloads $downloads = edd_get_payment_meta_cart_details($purchase_id, true); if (is_array($downloads)) { foreach ($downloads as $download) { $limit = edd_get_file_download_limit($download['id']); if (!empty($limit)) { edd_set_file_download_limit_override($download['id'], $purchase_id); } } } wp_redirect(add_query_arg(array('edd-message' => 'email_sent', 'edd-action' => false, 'purchase_id' => false))); exit; }
/** * Resend the Email Purchase Receipt. (This can be done from the Payment History page) * * @since 1.0 * @param array $data Payment Data * @return void */ function edd_resend_purchase_receipt($data) { $purchase_id = $data['purchase_id']; edd_email_purchase_receipt($purchase_id, false); // Grab all downloads of the purchase and update their file download limits, if needed // This allows admins to resend purchase receipts to grant additional file downloads $downloads = edd_get_payment_meta_downloads($purchase_id); if (is_array($downloads)) { foreach ($downloads as $download) { $limit = edd_get_file_download_limit($download['id']); if (!empty($limit)) { edd_set_file_download_limit_override($download['id'], $purchase_id); } } } wp_redirect(add_query_arg(array('edd-message' => 'email_sent', 'edd-action' => false, 'purchase_id' => false))); exit; }
/** * Resends a purchase receipt */ function resend_purchase_receipt() { authorize_request(); $payment_id = absint($_GET['payment_id']); edd_email_purchase_receipt($payment_id, false); // Grab all downloads of the purchase and update their file download limits, if needed // This allows admins to resend purchase receipts to grant additional file downloads $downloads = edd_get_payment_meta_downloads($payment_id); if (is_array($downloads)) { foreach ($downloads as $download) { $limit = edd_get_file_download_limit($download['id']); if (!empty($limit)) { edd_set_file_download_limit_override($download['id'], $payment_id); } } } die('<script>window.close();</script>'); }
/** * Checks if a file is at its download limit * * This limit refers to the maximum number of times files connected to a product * can be downloaded. * * @since 1.3.1 * @uses EDD_Logging::get_log_count() * @param int $download_id Download ID * @param int $payment_id Payment ID * @param int $file_id File ID * @param int $price_id Price ID * @return bool True if at limit, false otherwise */ function edd_is_file_at_download_limit($download_id = 0, $payment_id = 0, $file_id = 0, $price_id = false) { // Checks to see if at limit $logs = new EDD_Logging(); $meta_query = array('relation' => 'AND', array('key' => '_edd_log_file_id', 'value' => (int) $file_id), array('key' => '_edd_log_payment_id', 'value' => (int) $payment_id), array('key' => '_edd_log_price_id', 'value' => (int) $price_id)); $ret = false; $download_count = $logs->get_log_count($download_id, 'file_download', $meta_query); $download_limit = edd_get_file_download_limit($download_id); $unlimited_purchase = edd_payment_has_unlimited_downloads($payment_id); if (!empty($download_limit) && empty($unlimited_purchase)) { if ($download_count >= $download_limit) { $ret = true; // Check to make sure the limit isn't overwritten // A limit is overwritten when purchase receipt is resent $limit_override = edd_get_file_download_limit_override($download_id, $payment_id); if (!empty($limit_override) && $download_count < $limit_override) { $ret = false; } } } return (bool) apply_filters('edd_is_file_at_download_limit', $ret, $download_id, $payment_id, $file_id); }
/** * File Download Limit Row * * The file download limit is the maximum number of times each file * can be downloaded by the buyer * * @since 1.3.1 * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_limit_row($post_id) { if (!current_user_can('manage_shop_settings')) { return; } $edd_download_limit = edd_get_file_download_limit($post_id); $display = 'bundle' == edd_get_download_type($post_id) ? ' style="display: none;"' : ''; ?> <div id="edd_download_limit_wrap"<?php echo $display; ?> > <p><strong><?php _e('File Download Limit:', 'edd'); ?> </strong></p> <label for="edd_download_limit"> <?php echo EDD()->html->text(array('name' => '_edd_download_limit', 'value' => $edd_download_limit, 'class' => 'small-text')); ?> <?php _e('Leave blank for global setting or 0 for unlimited', 'edd'); ?> </label> </div> <?php }
/** * Retrieves a new download link for a purchased file * * @since 2.0 * @return string */ function edd_ajax_generate_file_download_link() { if (!current_user_can('view_shop_reports')) { die('-1'); } $payment_id = absint($_POST['payment_id']); $download_id = absint($_POST['download_id']); $price_id = absint($_POST['price_id']); if (empty($payment_id)) { die('-2'); } if (empty($download_id)) { die('-3'); } $payment_key = edd_get_payment_key($payment_id); $email = edd_get_payment_user_email($payment_id); $limit = edd_get_file_download_limit($download_id); if (!empty($limit)) { // Increase the file download limit when generating new links edd_set_file_download_limit_override($download_id, $payment_id); } $files = edd_get_download_files($download_id, $price_id); if (!$files) { die('-4'); } $file_urls = ''; foreach ($files as $file_key => $file) { $file_urls .= edd_get_download_file_url($payment_key, $email, $file_key, $download_id, $price_id); $file_urls .= "\n\n"; } die($file_urls); }
/** * File Download Limit Row * * The file download limit is the maximum number of times each file * can be downloaded by the buyer * * @since 1.3.1 * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_limit_row($post_id) { if (!current_user_can('manage_shop_settings')) { return; } $edd_download_limit = edd_get_file_download_limit($post_id); $display = 'bundle' == edd_get_download_type($post_id) ? ' style="display: none;"' : ''; ?> <div id="edd_download_limit_wrap"<?php echo $display; ?> > <p><strong><?php _e('File Download Limit:', 'easy-digital-downloads'); ?> </strong></p> <label for="edd_download_limit"> <?php echo EDD()->html->text(array('name' => '_edd_download_limit', 'value' => $edd_download_limit, 'class' => 'small-text')); ?> <?php _e('Leave blank for global setting or 0 for unlimited', 'easy-digital-downloads'); ?> </label> <span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php _e('<strong>File Download Limit</strong>: Limit the number of times a customer who purchased this product can access their download links.', 'easy-digital-downloads'); ?> "></span> </div> <?php }
/** * Fetches emails from queue and sends them in batches of 10 * * @access public * @since 0.9.2 * @return $sent (number of emails successfully processed) */ function edd_pup_ajax_trigger() { global $wpdb; global $edd_options; global $wpdb; if (!empty($_POST['email_id']) && absint($_POST['email_id']) != 0) { $email_id = $_POST['email_id']; } else { $email_id = get_transient('edd_pup_sending_email_' . get_current_user_id()); } // Refresh email ID transient set_transient('edd_pup_sending_email_' . get_current_user_id(), $email_id, 60); $batch = $_POST['iteration']; $sent = $_POST['sent']; $limit = 10; $rows = array(); /* Throttle emails if enabled in settings if ( isset( $edd_options['edd_pup_throttle'] ) ) { $last = $wpdb->query( "SELECT UNIX_TIMESTAMP(sent_date) FROM $wpdb->edd_pup_queue WHERE email_id = $email_id AND sent = 1 ORDER BY sent_date DESC LIMIT 1" ) $now = time(); if ( ( $now - $last ) < $edd_options['edd_pup_throttle_int'] ) { echo json_encode(array('status'=>'new','sent'=>0,'total'=>absint($total),'processed'=>absint($processed+$count))); exit; } }*/ $query = "SELECT * FROM {$wpdb->edd_pup_queue} WHERE email_id = {$email_id} AND sent = 0 LIMIT {$limit}"; $customers = $wpdb->get_results($query, ARRAY_A); foreach ($customers as $customer) { $trigger = edd_pup_ajax_send_email($customer['customer_id'], $email_id, $edd_options['edd_pup_test']); // Reset file download limits for customers' eligible updates $customer_updates = edd_pup_get_customer_updates($customer['customer_id'], $email_id); foreach ($customer_updates as $download) { $limit = edd_get_file_download_limit($download['id']); if (!empty($limit)) { edd_set_file_download_limit_override($download['id'], $customer['customer_id']); } } if (true == $trigger) { $rows[] = $customer['eddpup_id']; $sent++; } } // Designate emails in database as having been sent if (!empty($rows)) { $updateids = implode(',', $rows); $wpdb->query("UPDATE {$wpdb->edd_pup_queue} SET sent=1 WHERE eddpup_id IN ({$updateids})"); } echo $sent; exit; }
/** * File Download Limit Row * * The file download limit is the maximum number of times each file * can be downloaded by the buyer * * @since 1.3.1 * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_limit_row($post_id) { global $edd_options; $edd_download_limit = edd_get_file_download_limit($post_id); ?> <p><strong><?php _e('File Download Limit:', 'edd'); ?> </strong></p> <label for="edd_download_limit"> <input type="text" name="_edd_download_limit" id="edd_download_limit" value="<?php echo esc_attr($edd_download_limit); ?> " size="30" style="width: 80px;" placeholder="0"/> <?php _e('The maximum number of times a buyer can download each file. Leave blank or set to 0 for unlimited', 'edd'); ?> </label> <?php }