本文整理汇总了PHP中edd_get_bundled_products函数的典型用法代码示例。如果您正苦于以下问题:PHP edd_get_bundled_products函数的具体用法?PHP edd_get_bundled_products怎么用?PHP edd_get_bundled_products使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了edd_get_bundled_products函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ck_edd_user_download_button
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;
}
示例2: kjm_render_products_field
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
}
示例3: edd_get_payment_meta_cart_details
/**
* 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);
}
示例4: completed_download_purchase_signup
/**
* 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);
}
}
示例5: edd_email_tag_file_urls
/**
* 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;
}
示例6: edd_sl_process_license_upgrade
/**
* 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);
}
//.........这里部分代码省略.........
示例7: edd_get_bundled_products
<?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();
?>
示例8: function_exists
<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"/>
示例9: edd_sl_process_new_license_generation
/**
* 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;
}
示例10: edd_pup_email_confirm_html
//.........这里部分代码省略.........
)</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;
示例11: edd_pup_products_links_tag_plain
/**
* 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;
}
}
示例12: edd_sl_generate_download_keys_ajax_callback
/**
* 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;
}
示例13: edd_dwqa_categories_has_user_purchased
/**
* 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;
//.........这里部分代码省略.........
示例14: edd_media
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;
}
示例15: generate_license
/**
* 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);
//.........这里部分代码省略.........