function ck_edd_user_download_button($purchase_form, $args) { global $edd_options; if (!is_user_logged_in()) { return $purchase_form; } $download_id = (string) $args['download_id']; $current_user_id = get_current_user_id(); // If the user has purchased this item, itterate through their purchases to get the specific // purchase data and pull out the key and email associated with it. This is necessary for the // generation of the download link if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) { $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete'); foreach ($user_purchases as $purchase) { $cart_items = edd_get_payment_meta_cart_details($purchase->ID); $item_ids = wp_list_pluck($cart_items, 'id'); if (in_array($download_id, $item_ids)) { $email = edd_get_payment_user_email($purchase->ID); $payment_key = edd_get_payment_key($purchase->ID); } } $download_ids = array(); if (edd_is_bundled_product($download_id)) { $download_ids = edd_get_bundled_products($download_id); } else { $download_ids[] = $download_id; } // Setup the style and colors associated with the settings $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button'; $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue'; $new_purchase_form = ''; foreach ($download_ids as $item) { // Attempt to get the file data associated with this download $download_data = edd_get_download_files($item, null); if ($download_data) { foreach ($download_data as $filekey => $file) { // Generate the file URL and then make a link to it $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $item, null); $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a> '; } } // As long as we ended up with links to show, use them. if (!empty($new_purchase_form)) { $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form; } } } return $purchase_form; }
function kjm_render_products_field($post_id) { $type = edd_get_download_type($post_id); $display = $type == 'bundle' ? '' : ' style="display:none;"'; $products = edd_get_bundled_products($post_id); ?> <div id="edd_products"<?php echo $display; ?> > <div id="edd_file_fields" class="edd_meta_table_wrap"> <table class="widefat" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th><?php printf(__('Bundled %s:', 'easy-digital-downloads'), edd_get_label_plural()); ?> </th> <?php do_action('edd_download_products_table_head', $post_id); ?> </tr> </thead> <tbody> <tr class="edd_repeatable_product_wrapper"> <td> <?php echo EDD()->html->product_dropdown(array('name' => '_edd_bundled_products[]', 'id' => 'edd_bundled_products', 'selected' => $products, 'multiple' => true, 'chosen' => true, 'bundles' => false, 'number' => 2)); ?> </td> <?php do_action('edd_download_products_table_row', $post_id); ?> </tr> </tbody> </table> </div> </div> <?php }
/** * Get the cart_details Key from Payment Meta * * @since 1.2 * @param int $payment_id Payment ID * @param bool $include_bundle_files Whether to retrieve product IDs associated with a bundled product and return them in the array * @return array $cart_details Cart Details Meta Values */ function edd_get_payment_meta_cart_details($payment_id, $include_bundle_files = false) { $payment_meta = edd_get_payment_meta($payment_id); $cart_details = !empty($payment_meta['cart_details']) ? maybe_unserialize($payment_meta['cart_details']) : array(); if (!empty($cart_details) && is_array($cart_details)) { foreach ($cart_details as $key => $cart_item) { // Ensure subtotal is set, for pre-1.9 orders if (!isset($cart_item['subtotal'])) { $cart_details[$key]['subtotal'] = $cart_item['price']; } if ($include_bundle_files) { if ('bundle' != edd_get_download_type($cart_item['id'])) { continue; } $products = edd_get_bundled_products($cart_item['id']); if (empty($products)) { continue; } foreach ($products as $product_id) { $cart_details[] = array('id' => $product_id, 'name' => get_the_title($product_id), 'item_number' => array('id' => $product_id, 'options' => array()), 'price' => 0, 'subtotal' => 0, 'quantity' => 1, 'tax' => 0, 'in_bundle' => 1, 'parent' => array('id' => $cart_item['id'], 'options' => isset($cart_item['item_number']['options']) ? $cart_item['item_number']['options'] : array())); } } } } return apply_filters('edd_payment_meta_cart_details', $cart_details, $payment_id); }
/** * Check if a customer needs to be subscribed on completed purchase of specific products */ public function completed_download_purchase_signup($download_id = 0, $payment_id = 0, $download_type = 'default') { $user_info = edd_get_payment_meta_user_info($payment_id); $lists = get_post_meta($download_id, '_edd_' . $this->id, true); if ('bundle' == $download_type) { // Get the lists of all items included in the bundle $downloads = edd_get_bundled_products($download_id); if ($downloads) { foreach ($downloads as $d_id) { $d_lists = get_post_meta($d_id, '_edd_' . $this->id, true); if (is_array($d_lists)) { $lists = array_merge($d_lists, (array) $lists); } } } } if (empty($lists)) { return; } $lists = array_unique($lists); foreach ($lists as $list) { $this->subscribe_email($user_info, $list); } }
/** * Email template tag: file_urls * A plain-text list of download URLs for each download purchased * * @param int $payment_id * * @return string $file_urls */ function edd_email_tag_file_urls($payment_id) { $payment_data = edd_get_payment_meta($payment_id); $file_urls = ''; $cart_items = edd_get_payment_meta_cart_details($payment_id); $email = edd_get_payment_user_email($payment_id); foreach ($cart_items as $item) { $price_id = edd_get_cart_item_price_id($item); $files = edd_get_download_files($item['id'], $price_id); if ($files) { foreach ($files as $filekey => $file) { $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $item['id'], $price_id); $file_urls .= esc_html($file_url) . '<br/>'; } } elseif (edd_is_bundled_product($item['id'])) { $bundled_products = apply_filters('edd_email_tag_bundled_products', edd_get_bundled_products($item['id']), $item, $payment_id, 'file_urls'); foreach ($bundled_products as $bundle_item) { $files = edd_get_download_files($bundle_item); foreach ($files as $filekey => $file) { $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $bundle_item, $price_id); $file_urls .= esc_html($file_url) . '<br/>'; } } } } return $file_urls; }
/** * Process the license upgrade during purchase * * @since 3.3 * @return void */ function edd_sl_process_license_upgrade($download_id = 0, $payment_id = 0, $type = 'default', $cart_item = array(), $cart_index = 0) { // Bail if this is not a renewal item if (empty($cart_item['item_number']['options']['is_upgrade'])) { return; } $license_id = $cart_item['item_number']['options']['license_id']; $upgrade_id = $cart_item['item_number']['options']['upgrade_id']; $upgrade = edd_sl_get_upgrade_path($download_id, $upgrade_id); $old_payment_ids = get_post_meta($license_id, '_edd_sl_payment_id'); $old_payment_id = end($old_payment_ids); // We only want the most recent one $old_download_id = edd_software_licensing()->get_download_id($license_id); $old_price_id = edd_software_licensing()->get_price_id($license_id); $purchase_date = get_post_field('post_date', $old_payment_id); if (edd_is_bundled_product($download_id)) { // Upgrade to a bundle from a standard license $downloads = array(); $bundle_licensing = (bool) get_post_meta($download_id, '_edd_sl_enabled', true); $parent_license_id = 0; $activation_limit = false; $user_info = edd_get_payment_meta_user_info($payment_id); if ($bundle_licensing) { $downloads[] = $download_id; } $downloads = array_merge($downloads, edd_get_bundled_products($download_id)); if (edd_has_variable_prices($download_id)) { $activation_limit = edd_software_licensing()->get_price_activation_limit($download_id, $cart_item['item_number']['options']['price_id']); $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $cart_item['item_number']['options']['price_id']); } foreach ($downloads as $d_id) { if ((int) $d_id === (int) $old_download_id) { continue; } if (!get_post_meta($d_id, '_edd_sl_enabled', true)) { continue; } $license_title = get_the_title($d_id) . ' - ' . $user_info['email']; $license_args = array('post_type' => 'edd_license', 'post_title' => $license_title, 'post_status' => 'publish', 'post_date' => get_post_field('post_date', $payment_id, 'raw')); if ($parent_license_id) { $license_args['post_parent'] = $parent_license_id; } $l_id = wp_insert_post(apply_filters('edd_sl_insert_license_args', $license_args)); if ($bundle_licensing && $download_id == $d_id && !$parent_license_id) { $parent_license_id = $l_id; } $license_key = edd_software_licensing()->get_new_download_license_key($d_id); if (!$license_key) { // No predefined license key available, generate a random one $license_key = edd_software_licensing()->generate_license_key($l_id, $d_id, $payment_id, $cart_index); } $price_id = isset($cart_item['item_number']['options']['price_id']) ? (int) $cart_item['item_number']['options']['price_id'] : false; add_post_meta($l_id, '_edd_sl_download_id', $d_id); if (false !== $price_id) { add_post_meta($l_id, '_edd_sl_download_price_id', $price_id); } add_post_meta($l_id, '_edd_sl_cart_index', $cart_index); add_post_meta($l_id, '_edd_sl_payment_id', $payment_id); add_post_meta($l_id, '_edd_sl_key', $license_key); add_post_meta($l_id, '_edd_sl_user_id', $user_info['id']); add_post_meta($l_id, '_edd_sl_status', 'inactive'); add_post_meta($l_id, '_edd_sl_site_count', 0); if ($parent_license_id && !empty($activation_limit)) { add_post_meta($l_id, '_edd_sl_limit', $activation_limit); } // Get license length $license_length = edd_software_licensing()->get_license_length($l_id, $payment_id, $d_id); if (empty($is_lifetime) && 'lifetime' !== $license_length) { // Set license expiration date delete_post_meta($l_id, '_edd_sl_is_lifetime'); edd_software_licensing()->set_license_expiration($l_id, strtotime($license_length, strtotime($purchase_date))); } else { edd_software_licensing()->set_license_as_lifetime($l_id); } do_action('edd_sl_store_license', $l_id, $d_id, $payment_id, $type); } // Now update the original license wp_update_post(array('ID' => $license_id, 'post_parent' => $parent_license_id)); update_post_meta($license_id, '_edd_sl_cart_index', $cart_index); add_post_meta($license_id, '_edd_sl_payment_id', $payment_id); } else { // Standard license upgrade $new_title = get_the_title($download_id) . ' - ' . edd_get_payment_user_email($payment_id); wp_update_post(array('ID' => $license_id, 'post_title' => $new_title)); update_post_meta($license_id, '_edd_sl_cart_index', $cart_index); add_post_meta($license_id, '_edd_sl_payment_id', $payment_id); update_post_meta($license_id, '_edd_sl_download_id', $download_id); if (edd_has_variable_prices($download_id)) { $limit = edd_software_licensing()->get_price_activation_limit($download_id, $upgrade['price_id']); $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $upgrade['price_id']); update_post_meta($license_id, '_edd_sl_download_price_id', $upgrade['price_id']); } else { $limit = edd_software_licensing()->get_license_limit($download_id, $license_id); } update_post_meta($license_id, '_edd_sl_limit', $limit); $license_length = edd_software_licensing()->get_license_length($license_id, $payment_id, $download_id); if (empty($is_lifetime) && 'lifetime' !== $license_length) { // Set license expiration date delete_post_meta($license_id, '_edd_sl_is_lifetime'); edd_software_licensing()->set_license_expiration($license_id, strtotime($license_length, strtotime($purchase_date))); } else { edd_software_licensing()->set_license_as_lifetime($license_id); } } // Now store upgrade details / notes on payments $old_product = get_the_title($old_download_id); if (false !== $old_price_id) { $old_product .= ' - ' . edd_get_price_option_name($old_download_id, $old_price_id); } $new_product = get_the_title($download_id); if (edd_has_variable_prices($download_id)) { $new_product .= ' - ' . edd_get_price_option_name($download_id, $upgrade['price_id']); } $note = sprintf(__('License upgraded from %s to %s', 'edd_sl'), $old_product, $new_product); edd_insert_payment_note($payment_id, $note); update_post_meta($payment_id, '_edd_sl_upgraded_payment_id', $old_payment_id); update_post_meta($old_payment_id, '_edd_sl_upgraded_to_payment_id', $payment_id); }
<?php namespace Yoast\YoastCom\Theme; $product_ids = edd_get_bundled_products(get_the_ID()); $products = array_map(function ($product_id) { return get_post($product_id); }, $product_ids); ?> <div class="media media--nofloat product"> <a href="<?php the_permalink(); ?> " class="img img--large promoblock--imageholder"> <?php the_post_thumbnail(array(240, 320)); ?> </a> <div class="bd"> <?php $url = post_meta('url'); if (!$url) { $url = get_permalink(); } ?> <h2 class="h3 tight color-academy--tertiary"><a href="<?php echo $url; ?> "><?php the_title(); ?>
<section class="<?php if (get_theme_mod('hide-player') == 0) { echo "w-f-md"; } ?> " id="ajax-container"> <section class="vbox"> <section class="scrollable wrapper-lg"> <div class="row"> <div class="col-sm-9"> <div class="panel wrapper-md"> <div itemscope="" itemtype="http://schema.org/Product"> <div class="row"> <div class="col-sm-4"> <?php $list = function_exists('edd_get_bundled_products') ? edd_get_bundled_products($post->ID) : array(); if (has_post_thumbnail()) { ?> <?php the_post_thumbnail('medium', array('class' => 'm-b img-full')); ?> <?php } else { ?> <img src="<?php echo get_stylesheet_directory_uri(); ?> /assets/images/default_300_300.jpg" alt="<?php the_title_attribute(); ?> " class="img-full m-b"/>
/** * Process the Generate License Keys button from the View Order Details metabox * * @since 1.9 */ function edd_sl_process_new_license_generation($data) { if (empty($data['edd_sl_generate_keys_nonce']) || !wp_verify_nonce($data['edd_sl_generate_keys_nonce'], 'generate_new_license_keys')) { wp_die(__('Verification failed', 'edd_sl'), __('Error', 'edd_sl'), array('response' => 401)); } $payment_id = absint($data['id']); if (empty($payment_id)) { return; } if (!current_user_can('edit_shop_payments')) { wp_die(__('You do not have permission to perform this action', 'edd_sl'), __('Error', 'edd_sl'), array('response' => 401)); } $downloads = edd_get_payment_meta_cart_details($payment_id, false); if (empty($downloads)) { return; } $payment_date = get_post_field('post_date', $payment_id); // Generate keys for each iem that needs it foreach ($downloads as $cart_index => $download) { if ('bundle' === edd_get_download_type($download['id'])) { // Get products for the bundle and check if any need a license key $bundle_license = edd_software_licensing()->get_license_by_purchase($payment_id, $download['id'], $cart_index); if (!$bundle_license) { // Create a new bundle key $bundle_keys = edd_software_licensing()->generate_license($download['id'], $payment_id, 'default', array(), $cart_index); $bundle_key_id = isset($bundle_keys[0]) ? $bundle_keys[0] : 0; if (empty($bundle_key_id)) { continue; } $license_length = edd_software_licensing()->get_license_length($bundle_key_id, $payment_id, $download['id']); if (!edd_software_licensing()->is_lifetime_license($bundle_key_id)) { $expiration = strtotime($license_length, strtotime($payment_date)); edd_software_licensing()->set_license_expiration($bundle_key_id, strtotime($license_length)); } } else { $bundle_key_id = $bundle_license->ID; } $bundle_items = edd_get_bundled_products($download['id']); foreach ($bundle_items as $item_id) { if (edd_software_licensing()->get_license_by_purchase($payment_id, $item_id, $cart_index)) { continue; // This product already has keys } $keys = edd_software_licensing()->generate_license($item_id, $payment_id, 'default', array(), $cart_index); foreach ($keys as $license_id) { $license_length = edd_software_licensing()->get_license_length($license_id, $payment_id, $download['id']); if (!edd_software_licensing()->is_lifetime_license($license_id)) { $expiration = strtotime($license_length, strtotime($payment_date)); edd_software_licensing()->set_license_expiration($license_id, strtotime($license_length)); } // Set the post parent to the Bundle Key $update_args = array('ID' => $license_id, 'post_parent' => $bundle_key_id); wp_update_post($update_args); } } } else { if (edd_software_licensing()->get_license_by_purchase($payment_id, $download['id'], $cart_index)) { continue; // This product already has keys } $keys = edd_software_licensing()->generate_license($download['id'], $payment_id, 'default', $download, $cart_index); foreach ($keys as $license_id) { $license_length = edd_software_licensing()->get_license_length($license_id, $payment_id, $download['id']); if (!edd_software_licensing()->is_lifetime_license($license_id)) { $expiration = strtotime($license_length, strtotime($payment_date)); edd_software_licensing()->set_license_expiration($license_id, strtotime($license_length)); } } } } wp_redirect(admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $payment_id)); exit; }
/** * Generates HTML for email confirmation via AJAX on send button press * * @access public * @return void * @since 0.9 */ function edd_pup_email_confirm_html() { $form = array(); parse_str($_POST['form'], $form); parse_str($_POST['url'], $url); // Nonce security check if (empty($form['edd-pup-send-nonce']) || !wp_verify_nonce($form['edd-pup-send-nonce'], 'edd-pup-confirm-send')) { echo 'noncefail'; die; } // Make sure there are products to be updated if (empty($form['products'])) { echo 'nocheck'; die; } // Save the email before generating preview $email_id = edd_pup_sanitize_save($_POST); // If "Send Update Email" was clicked from Add New Email page, trigger browser to refresh to edit page for continued editing if ($url['view'] == 'add_pup_email') { echo absint($email_id); die; } // Necessary for preview HTML set_transient('edd_pup_preview_email_' . get_current_user_id(), $email_id, 60); $bundlenum = 0; $email = get_post($email_id); $emailmeta = get_post_custom($email_id); $filters = unserialize($emailmeta['_edd_pup_filters'][0]); $products = get_post_meta($email_id, '_edd_pup_updated_products', true); $popup_url = add_query_arg(array('view' => 'send_pup_ajax', 'id' => $email_id), admin_url('edit.php?post_type=download&page=edd-prod-updates')); $customercount = edd_pup_customer_count($email_id, $products); $email_body = isset($email->post_content) ? stripslashes($email->post_content) : 'Cannot retrieve message content'; $subject = empty($emailmeta['_edd_pup_subject'][0]) ? '(no subject)' : strip_tags(edd_email_preview_template_tags($emailmeta['_edd_pup_subject'][0])); $productlist = ''; // Construct templated email HTML add_filter('edd_email_template', 'edd_pup_template'); if (version_compare(get_option('edd_version'), '2.1') >= 0) { $edd_emails = new EDD_Emails(); $message = $edd_emails->build_email(edd_email_preview_template_tags($email_body)); } else { $message = edd_apply_email_template($email_body, null, null); } // Add max-width for plaintext emails so they don't run off the page if ('none' == edd_pup_template()) { $message = '<div style="width: 640px;">' . $message . '</div>'; } // Save message to metadata for later retrieval update_post_meta($email_id, '_edd_pup_message', $message); ob_start(); ?> <!-- Begin send email confirmation message --> <h2 id="edd-pup-confirm-title"><strong><?php _e('Almost Ready to Send!', 'edd-pup'); ?> </strong></h2> <p style="text-align: center;"><?php _e('Please carefully check the information below before sending your emails.', 'edd-pup'); ?> </p> <div id="edd-pup-confirm-message"> <div id="edd-pup-confirm-header"> <h3><?php _e('Email Message Preview', 'edd-pup'); ?> </h3> <ul> <li><strong><?php _e('From:', 'edd-pup'); ?> </strong> <?php echo $emailmeta['_edd_pup_from_name'][0]; ?> (<?php echo $emailmeta['_edd_pup_from_email'][0]; ?> )</li> <li><strong><?php _e('Subject:', 'edd-pup'); ?> </strong> <?php echo $subject; ?> </li> </ul> </div> <?php echo $message; ?> <div id="edd-pup-confirm-footer"> <h3><?php _e('Additional Information', 'edd-pup'); ?> </h3> <ul> <li><strong><?php _e('Updated Products:', 'edd-pup'); ?> </strong></li> <ul id="edd-pup-confirm-products"> <?php foreach ($products as $product_id => $product) { $bundle = edd_is_bundled_product($product_id); // Filter bundle customers only if ($filters['bundle_2'] && !$bundle) { continue; } $productlist .= '<li data-id="' . $product_id . '">' . $product . '</li>'; if ($bundle) { $bundledproducts = edd_get_bundled_products($product_id); $productlist .= '<ul id="edd-pup-confirm-bundle-products">'; foreach ($bundledproducts as $bundleitem) { if (isset($products[$bundleitem])) { $productlist .= '<li data-id="' . $bundleitem . '">' . $products[$bundleitem] . '</li>'; } } $productlist .= '</ul>'; $bundlenum++; } } echo $productlist; ?> </ul> <?php if ($bundlenum > 0) { ?> <li><strong><?php _e('Bundle Filters:', 'edd-pup'); ?> </strong></li> <ul id="edd-pup-confirm-products"> <?php foreach ($filters as $filtername => $filtervalue) { ?> <?php switch ($filtername) { case 'bundle_1': $output = $filtervalue == 'all' ? '<li>' . __('Show links for all products within bundles', 'edd-pup') . '</li>' : '<li>' . __('Show links for only updated products within bundles', 'edd-pup') . '</li>'; break; case 'bundle_2': $output = $filtervalue == 1 ? '<li>' . __('Send this email to bundle customers only', 'edd-pup') . '</li>' : ''; break; } echo $output; ?> <?php } ?> </ul> <?php } ?> <li><strong><?php _e('Recipients:', 'edd-pup'); ?> </strong> <?php printf(_n('1 customer will receive this email and have their downloads reset', '%s customers will receive this email and have their downloads reset', $customercount, 'edd-pup'), number_format($customercount)); ?> </li> </ul> <a href="<?php echo $popup_url; ?> " id="prod-updates-email-ajax" class="button-primary button" title="<?php _e('Confirm and Send Emails', 'edd-pup'); ?> " onclick="window.open(this.href,'targetWindow', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=480');return false;"><?php _e('Confirm and Send Emails', 'edd-pup'); ?> </a> <button class="closebutton button-secondary"><?php _e('Close without sending', 'edd-pup'); ?> </button> </div> </div> <!-- End send email confirmation message --> <script type="text/javascript"> jQuery('.postbox .recipient-count').text("<?php echo number_format($customercount); ?> "); jQuery('.postbox .recipient-input').val(<?php echo $customercount; ?> ); </script> <?php echo ob_get_clean(); die; }
/** * Email template tag: updated_products_links * A list of updated products with download links included * * @access public * @param mixed $payment_id * @return void */ function edd_pup_products_links_tag_plain($payment_id, $email = null) { // Used to generate accurate tag outputs for preview and test emails if (isset($email) && absint($email) != 0) { $updated_products = get_post_meta($email, '_edd_pup_updated_products', true); $updated_products = is_array($updated_products) ? $updated_products : array($updated_products); foreach ($updated_products as $id => $name) { $customer_updates[$id] = array('id' => $id, 'name' => $name); } } else { $email = get_transient('edd_pup_sending_email_' . get_current_user_id()); $updated_products = get_post_meta($email, '_edd_pup_updated_products', true); $updated_products = is_array($updated_products) ? $updated_products : array($updated_products); $customer_updates = edd_pup_get_customer_updates($payment_id, $email); $customer_updates = is_array($customer_updates) ? $customer_updates : array($customer_updates); } $filters = get_post_meta($email, '_edd_pup_filters', true); if ($customer_updates) { $show_names = apply_filters('edd_pup_email_show_names', true); $payment_data = edd_get_payment_meta($payment_id); // Set email to most recent email if it's been changed from initial email if (isset($payment_data['user_info']['email']) && $payment_data['user_info']['email'] != $payment_data['email']) { $payment_data['email'] = $payment_data['user_info']['email']; } // Used for detecting when to place commas $c = 1; $download_list = ''; foreach ($customer_updates as $item) { if (edd_use_skus()) { $sku = edd_get_download_sku($item['id']); } $price_id = edd_get_cart_item_price_id($item); if ($show_names) { $title = $c == 1 ? $item['name'] : ', ' . $item['name']; if (!empty($sku)) { $title .= " – " . __('SKU', 'edd') . ': ' . $sku; } $download_list .= apply_filters('edd_pup_email_products_link_title_plain', $title, $item, $price_id, $payment_id); } $files = edd_get_download_files($item['id'], $price_id); if ($files) { // $f used for detecting when to place commas $f = 1; $download_list .= ' ('; foreach ($files as $filekey => &$file) { $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $item['id'], $price_id); $download_list .= $f == 1 ? edd_get_file_name($file) . ': ' . esc_url($file_url) : ', ' . edd_get_file_name($file) . ': ' . esc_url($file_url); $f++; } $download_list .= ')'; } if (edd_is_bundled_product($item['id'])) { $b = 1; $bundled_products = edd_get_bundled_products($item['id']); $download_list .= " – "; foreach ($bundled_products as $bundle_item) { if ($filters['bundle_1'] == 'all' || isset($updated_products[$bundle_item])) { $download_list .= $b == 1 ? get_the_title($bundle_item) : '; ' . get_the_title($bundle_item); $fb = 1; $bundlefiles = edd_get_download_files($bundle_item); $download_list .= ' ('; foreach ($bundlefiles as $bundlefilekey => $bundlefile) { $bundlefile_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $bundlefilekey, $bundle_item, $price_id); $download_list .= $fb == 1 ? $bundlefile['name'] . ': ' . esc_url($bundlefile_url) : ', ' . $bundlefile['name'] . ': ' . esc_url($bundlefile_url); $fb++; } $download_list .= ')'; } $b++; } } if ('' != edd_get_product_notes($item['id'])) { $download_list .= ' – ' . edd_get_product_notes($item['id']); } $c++; } return $download_list; } }
/** * Handle the ajax call, no need for nopriv handling since this is admin only * * @access private * @since 2.6 * @return void */ function edd_sl_generate_download_keys_ajax_callback() { if (!current_user_can('edit_shop_payments')) { status_header(404); die; } // If there is no download ID posted, breakout immediately because we cannot find the download if (!isset($_POST['download'])) { status_header(404); die; } // Grab the download ID and make sure its an int $download = intval($_POST['download']); // Make sure the post we are looking at is a download, otherwise the post (media type) is unsupported! if (get_post_type($download) !== 'download') { status_header(415); die; } // Gather all the payments, and individual download IDs so we can verify licenses exist $args = array('download' => $download, 'number' => -1); $query = new EDD_Payments_Query($args); $payments = $query->get_payments(); $is_bundle = edd_is_bundled_product($download); $downloads = $is_bundle ? edd_get_bundled_products($download) : array($download); // Loop through the payments, and then the downloads, and maybe generate licenses $generated = 0; $updated = 0; foreach ($payments as $payment) { if ($is_bundle) { $parent_license = edd_software_licensing()->get_license_by_purchase($payment->ID, $download); } foreach ($downloads as $d) { // If download ID is empty, continue if (empty($d)) { continue; } // Maybe generate a key, and if we do increase the count $license = edd_software_licensing()->get_license_by_purchase($payment->ID, $d); // If no license exists... generate one! if (!$license) { add_action('edd_sl_store_license', 'edd_sl_log_generated_license', 10, 4); $key = edd_software_licensing()->generate_license($d, $payment->ID); $license = edd_software_licensing()->get_license_by_purchase($payment->ID, $d); if ($is_bundle && $key) { // Set the post parent to the Bundle Key $update_args = array('ID' => $license->ID, 'post_parent' => $parent_license->ID); wp_update_post($update_args); } remove_action('edd_sl_store_license', 'edd_sl_log_generated_license', 10); // Return true if a key was generated if ($key) { $generated++; } } elseif ($is_bundle && $license) { if (empty($license->post_parent)) { // Set the post parent to the Bundle Key $update_args = array('ID' => $license->ID, 'post_parent' => $parent_license->ID); wp_update_post($update_args); $updated++; } } } } // We must die, or we live too long... but we must speak our last workd. printf(_n('One key was generated', '%d keys were generated.', $generated), $generated); echo '<br />'; printf(_n('One key was updated', '%d keys were updated.', $updated), $updated); die; }
/** * Has User Purchased * * Checks to see if a user has purchased a download. * * @access public * @since 1.0 * @param int $user_id - the ID of the user to check * @param array $downloads - Array of IDs to check if purchased. If an int is passed, it will be converted to an array * @param int $variable_price_id - the variable price ID to check for * @return boolean - true if has purchased and license is active, false otherwise */ function edd_dwqa_categories_has_user_purchased($user_id, $downloads, $variable_price_id = null, $verify_purchase = false) { $users_purchases = edd_get_users_purchases($user_id); $return = false; if (!is_array($downloads)) { $downloads = array($downloads); } $now = strtotime(date('Y-m-d H:i:s')); if ($users_purchases) { foreach ($users_purchases as $purchase) { $purchased_files = edd_get_payment_meta_downloads($purchase->ID); if (empty($purchased_files)) { return false; } $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID); $licenses_products = array(); if (is_array($licenses)) { foreach ($licenses as $license) { $download_id = get_post_meta($license->ID, '_edd_sl_download_id', true); $status = get_post_meta($license->ID, '_edd_sl_status', true); $expire = get_post_meta($license->ID, '_edd_sl_expiration', true); $licenses_products[$download_id] = array(); $licenses_products[$download_id]['status'] = $status; $licenses_products[$download_id]['expire'] = $expire; } } else { return false; } if (is_array($purchased_files)) { foreach ($purchased_files as $download) { if (edd_is_bundled_product($download['id'])) { $bundled_products = edd_get_bundled_products($download['id']); if (empty($bundled_products)) { return false; } foreach ($bundled_products as $bundle_product) { if (in_array($bundle_product, $downloads)) { //check to see if the license is active //echo $licenses_products[$download['id']]['expire'] . ">" . $now . "=========="; if (isset($licenses_products[$bundle_product]['expire']) && $now > $licenses_products[$bundle_product]['expire']) { // || $licenses_products[$download['id']]['status'] == 'inactive' if ($verify_purchase) { return "purchased_expired"; } else { return false; } } $variable_prices = edd_has_variable_prices($bundle_product); if ($variable_prices && !is_null($variable_price_id) && $variable_price_id !== false) { if (isset($download['options']['price_id']) && $variable_price_id == $download['options']['price_id']) { return true; } else { return false; } } else { return true; } } } return false; } if (in_array($download['id'], $downloads)) { //check to see if the license is active //echo $licenses_products[$download['id']]['expire'] . ">" . $now . "=========="; if (isset($licenses_products[$download['id']]['expire']) && $now > $licenses_products[$download['id']]['expire']) { // || $licenses_products[$download['id']]['status'] == 'inactive' if ($verify_purchase) { return "purchased_expired"; } else { return false; } } $variable_prices = edd_has_variable_prices($download['id']); if ($variable_prices && !is_null($variable_price_id) && $variable_price_id !== false) { if (isset($download['options']['price_id']) && $variable_price_id == $download['options']['price_id']) { return true; } else { return false; } } else { return true; } } } } } } return false; }
function edd_media() { if (!isset($_REQUEST['id'])) { die(0); } $post_id = intval($_REQUEST['id']); $plays = get_post_meta($post_id, 'plays', true); update_post_meta($post_id, 'plays', $plays + 1); $list = edd_get_bundled_products($post_id); if (empty($list)) { $list = array($post_id); $post = get_post($post_id); if ($post->post_type == 'playlist') { $tracks = get_post_meta($post->ID, 'tracks', true); $list = explode(',', trim($tracks)); } } $args = array('posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'download', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true, 'post__in' => $list); $objs = array(); $posts = get_posts($args); foreach ($posts as $post) { $obj = array(); $obj['id'] = $post->ID; $obj['ids'] = $post_id; $obj['title'] = '</a><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a>'; $obj = array_merge($obj, get_preview($post->ID)); $terms = get_the_terms($post->ID, 'download_artist', '', ', ', ''); if ($terms && !is_wp_error($terms)) { $artist = array(); foreach ($terms as $term) { $artist[] = $term->name; } $obj['artist'] = join(", ", $artist); } $obj['poster'] = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); $objs[] = $obj; } echo json_encode($objs); die; }
/** * Generate license keys for a purchase * * Generates ( if needed ) a license key for the buyer at time of purchase * This key will be used to activate all products for this purchase * * @access private * @since 1.5 * @return void */ function generate_license($download_id = 0, $payment_id = 0, $type = 'default', $cart_item = array(), $cart_index = 0) { // Bail if this cart item is for a renewal if (!empty($cart_item['item_number']['options']['is_renewal'])) { return; } // Bail if this cart item is for an upgrade if (!empty($cart_item['item_number']['options']['is_upgrade'])) { return; } $keys = array(); $user_info = edd_get_payment_meta_user_info($payment_id); $bundle_licensing = 'bundle' == $type && (bool) get_post_meta($download_id, '_edd_sl_enabled', true); $parent_license_id = 0; $activation_limit = false; if ($type == 'bundle') { $downloads = array(); if ($bundle_licensing) { $downloads[] = $download_id; } $downloads = array_merge($downloads, edd_get_bundled_products($download_id)); if (edd_has_variable_prices($download_id)) { $activation_limit = edd_software_licensing()->get_price_activation_limit($download_id, $cart_item['item_number']['options']['price_id']); $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $cart_item['item_number']['options']['price_id']); } } else { if (edd_has_variable_prices($download_id)) { $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $cart_item['item_number']['options']['price_id']); } $downloads = array(); $downloads[] = $download_id; } if (!is_array($downloads)) { return; } foreach ($downloads as $d_id) { if (!get_post_meta($d_id, '_edd_sl_enabled', true)) { continue; } $license_title = get_the_title($d_id) . ' - ' . $user_info['email']; $license_args = array('post_type' => 'edd_license', 'post_title' => $license_title, 'post_status' => 'publish', 'post_date' => get_post_field('post_date', $payment_id, 'raw')); if ($parent_license_id) { $license_args['post_parent'] = $parent_license_id; } $license_id = wp_insert_post(apply_filters('edd_sl_insert_license_args', $license_args)); if ($bundle_licensing && $download_id == $d_id && !$parent_license_id) { $parent_license_id = $license_id; } $keys[] = $license_id; $license_key = self::get_new_download_license_key($d_id); if (!$license_key) { // No predefined license key available, generate a random one $license_key = self::generate_license_key($license_id, $d_id, $payment_id, $cart_index); } $price_id = isset($cart_item['item_number']['options']['price_id']) ? (int) $cart_item['item_number']['options']['price_id'] : false; add_post_meta($license_id, '_edd_sl_download_id', $d_id); if (false !== $price_id) { add_post_meta($license_id, '_edd_sl_download_price_id', $price_id); } add_post_meta($license_id, '_edd_sl_cart_index', $cart_index); add_post_meta($license_id, '_edd_sl_payment_id', $payment_id); add_post_meta($license_id, '_edd_sl_key', $license_key); add_post_meta($license_id, '_edd_sl_user_id', $user_info['id']); add_post_meta($license_id, '_edd_sl_status', 'inactive'); add_post_meta($license_id, '_edd_sl_site_count', 0); if ($parent_license_id && !empty($activation_limit)) { add_post_meta($license_id, '_edd_sl_limit', $activation_limit); } // Get the purchase date so we can set the correct license expiration date $payment_meta = edd_get_payment_meta($payment_id); $purchase_date = null; if (!empty($payment_meta['date'])) { $purchase_date = strtotime($payment_meta['date']); } // Get license length $license_length = self::get_license_length($license_id, $payment_id, $d_id); if (empty($is_lifetime) && 'lifetime' !== $license_length) { // Set license expiration date $expiration = strtotime($license_length, $purchase_date); if ($expiration > strtotime('+24 hours')) { // Force it to end of day if expiration is more than 24 hours in the future $expiration = date('Y-n-d 23:59:59', $expiration); // Convert back into timestamp $expiration = strtotime($expiration); } self::set_license_expiration($license_id, $expiration); } else { self::set_license_as_lifetime($license_id); } do_action('edd_sl_store_license', $license_id, $d_id, $payment_id, $type); } return $keys; }
/** * Renders product field * @since 1.6 * * @param $post_id */ function edd_render_products_field($post_id) { $type = edd_get_download_type($post_id); $display = $type == 'bundle' ? '' : ' style="display:none;"'; $products = edd_get_bundled_products($post_id); ?> <div id="edd_products"<?php echo $display; ?> > <div id="edd_file_fields" class="edd_meta_table_wrap"> <table class="widefat edd_repeatable_table" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th style="width: 20px"></th> <th><?php printf(__('Bundled %s:', 'easy-digital-downloads'), edd_get_label_plural()); ?> </th> <th></th> <?php do_action('edd_download_products_table_head', $post_id); ?> </tr> </thead> <tbody> <?php if ($products) { ?> <?php $index = 1; ?> <?php foreach ($products as $key => $product) { ?> <tr class="edd_repeatable_product_wrapper edd_repeatable_row" data-key="<?php echo esc_attr($key); ?> "> <td> <span class="edd_draghandle"></span> <input type="hidden" name="edd_bundled_products[<?php echo $key; ?> ][index]" class="edd_repeatable_index" value="<?php echo $index; ?> "/> </td> <td> <?php echo EDD()->html->product_dropdown(array('name' => '_edd_bundled_products[]', 'id' => 'edd_bundled_products_' . $key, 'selected' => $product, 'multiple' => false, 'chosen' => true, 'bundles' => false)); ?> </td> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> <?php do_action('edd_download_products_table_row', $post_id); ?> </tr> <?php $index++; ?> <?php } ?> <?php } else { ?> <tr class="edd_repeatable_product_wrapper edd_repeatable_row" data-key="1"> <td> <span class="edd_draghandle"></span> <input type="hidden" name="edd_bundled_products[1][index]" class="edd_repeatable_index" value="1"/> </td> <td> <?php echo EDD()->html->product_dropdown(array('name' => '_edd_bundled_products[]', 'id' => 'edd_bundled_products_1', 'multiple' => false, 'chosen' => true, 'bundles' => false)); ?> </td> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> <?php do_action('edd_download_products_table_row', $post_id); ?> </tr> <?php } ?> <tr> <td class="submit" colspan="3" style="float: none; clear:both; background: #fff;"> <a class="button-secondary edd_add_repeatable" style="margin: 6px 0 10px;"><?php _e('Add New File', 'easy-digital-downloads'); ?> </a> </td> </tr> </tbody> </table> </div> </div> <?php }
$download_url = edd_get_download_file_url($meta['key'], $email, $filekey, $item['id'], $price_id); ?> <li class="edd_download_file"> <a href="<?php echo esc_url($download_url); ?> " class="edd_download_file_link"><?php echo edd_get_file_name($file); ?> </a> </li> <?php do_action('edd_receipt_files', $filekey, $file, $item['id'], $payment->ID, $meta); } } elseif (edd_is_bundled_product($item['id'])) { $bundled_products = edd_get_bundled_products($item['id']); foreach ($bundled_products as $bundle_item) { ?> <li class="edd_bundled_product"> <span class="edd_bundled_product_name"><?php echo get_the_title($bundle_item); ?> </span> <ul class="edd_bundled_product_files"> <?php $download_files = edd_get_download_files($bundle_item); if ($download_files && is_array($download_files)) { foreach ($download_files as $filekey => $file) { $download_url = edd_get_download_file_url($meta['key'], $email, $filekey, $bundle_item, $price_id); ?> <li class="edd_download_file">
/** * Run the upgrade to generate licenses for past bundle purchases * * @since 3.2 * @return void */ function edd_sl_v32_add_bundle_licenses() { global $wpdb; if (!current_user_can('manage_shop_settings')) { wp_die(__('You do not have permission to do shop upgrades', 'edd'), __('Error', 'edd'), array('response' => 403)); } ignore_user_abort(true); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { @set_time_limit(0); } $step = isset($_GET['step']) ? absint($_GET['step']) : 1; $number = 25; $offset = $step == 1 ? 0 : ($step - 1) * $number; // Get the upgrade type...if none provided, dismiss is used and no further action is taken $custom = isset($_GET['custom']) ? absint($_GET['custom']) : 0; if ($step < 2) { // User chose to not run any upgrades if (0 === $custom) { update_option('edd_sl_version', preg_replace('/[^0-9.].*/', '', EDD_SL_VERSION)); edd_set_upgrade_complete('sl_add_bundle_licenses'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } // Check if we have any payments before moving on $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'edd_payment' LIMIT 1"; $has_payments = $wpdb->get_col($sql); if (empty($has_payments)) { // We had no payments, just complete update_option('edd_sl_version', preg_replace('/[^0-9.].*/', '', EDD_SL_VERSION)); edd_set_upgrade_complete('sl_add_bundle_licenses'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } // Check if we have any bundle products as well $sql = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_edd_bundled_products' LIMIT 1"; $has_bundles = $wpdb->get_col($sql); if (empty($has_bundles)) { // We had no bundles, just complete update_option('edd_sl_version', preg_replace('/[^0-9.].*/', '', EDD_SL_VERSION)); edd_set_upgrade_complete('sl_add_bundle_licenses'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } } $sql = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_edd_bundled_products'"; $bundle_download_ids = $wpdb->get_col($sql); foreach ($bundle_download_ids as $key => $bundle_id) { $licenses_enabled = get_post_meta($bundle_id, '_edd_sl_enabled', false); if (empty($licenses_enabled)) { unset($bundle_download_ids[$key]); } } // If we ended up with no bundles that have licensing enabled, just exit as well if (empty($bundle_download_ids)) { update_option('edd_sl_version', preg_replace('/[^0-9.].*/', '', EDD_SL_VERSION)); edd_set_upgrade_complete('sl_add_bundle_licenses'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } $total = isset($_GET['total']) ? absint($_GET['total']) : false; if (empty($total) || $total <= 1) { $args = array('number' => -1, 'download' => $bundle_download_ids); $all_payments = new EDD_Payments_Query($args); $all_payments = $all_payments->get_payments(); $total = count($all_payments); } $payment_args = array('order' => 'ASC', 'orderby' => 'ID', 'number' => $number, 'page' => $step, 'download' => $bundle_download_ids); $payments = new EDD_Payments_Query($payment_args); $payments = $payments->get_payments(); $bundle_contents = array(); if (!empty($payments)) { foreach ($payments as $payment) { $cart_details = edd_get_payment_meta_downloads($payment->ID); foreach ($cart_details as $cart_index => $cart_item) { if (!in_array($cart_item['id'], $bundle_download_ids)) { // Item is not a bundled product, move along continue; } // See if there is a bundle license already $bundle_license = edd_software_licensing()->get_license_by_purchase($payment->ID, $cart_item['id']); // It not create the bundle license if (empty($bundle_license)) { $bundle_license = edd_software_licensing()->generate_license($cart_item['id'], $payment->ID, 'default', $cart_item, $cart_index); $bundle_license = edd_software_licensing()->get_license_by_purchase($payment->ID, $cart_item['id'], $cart_index); } // If we haven't retrieved the bundle contents yet, get them if (!isset($bundle_contents[$cart_item['id']])) { $bundle_contents[$cart_item['id']] = edd_get_bundled_products($cart_item['id']); } // Get the products in the bundle $bundle_products = $bundle_contents[$cart_item['id']]; // For every bundle in the download, get the license for this payment, and update it's post_parent foreach ($bundle_products as $license_download_id) { $license = edd_software_licensing()->get_license_by_purchase($payment->ID, $license_download_id); if (empty($license)) { continue; } $update_args = array('ID' => $license->ID, 'post_parent' => $bundle_license->ID); wp_update_post($update_args); } } } // More Payments found so upgrade them $step++; $redirect = add_query_arg(array('page' => 'edd-upgrades', 'edd-upgrade' => 'sl_add_bundle_licenses', 'step' => $step, 'number' => $number, 'total' => $total, 'custom' => $custom), admin_url('index.php')); wp_safe_redirect($redirect); exit; } else { // No more data to update. Downloads have been altered or dismissed update_option('edd_sl_version', preg_replace('/[^0-9.].*/', '', EDD_SL_VERSION)); edd_set_upgrade_complete('sl_add_bundle_licenses'); delete_option('edd_doing_upgrade'); wp_redirect(admin_url()); exit; } }