/**
 * Helper Functions
 */
function wc_edd_email_purchase_receipt($payment_id, $download_id)
{
    $payment_data = edd_get_payment_meta($payment_id);
    $download = get_post($download_id);
    $license = edd_software_licensing()->get_license_by_purchase($payment_id, $download_id);
    $from_name = edd_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
    $from_name = apply_filters('edd_purchase_from_name', $from_name, $payment_id, $payment_data);
    $from_email = edd_get_option('from_email', get_bloginfo('admin_email'));
    $from_email = apply_filters('edd_purchase_from_address', $from_email, $payment_id, $payment_data);
    $to_email = edd_get_payment_user_email($payment_id);
    $subject = edd_get_option('purchase_subject', __('New License Key', 'edd'));
    $subject = apply_filters('edd_purchase_subject', wp_strip_all_tags($subject), $payment_id);
    $subject = edd_do_email_tags($subject, $payment_id);
    $message = "Dear " . edd_email_tag_first_name($payment_id) . ",\n\n";
    $message .= "As you have updated " . $download->post_title . ", please use following new license key to continue getting future updates: \n\n";
    $message .= "License Key : " . edd_software_licensing()->get_license_key($license->ID) . "\n\n";
    $message .= "Sorry for inconvenience.";
    $emails = EDD()->emails;
    $emails->__set('from_name', $from_name);
    $emails->__set('from_email', $from_email);
    $emails->__set('heading', __('Purchase Receipt', 'edd'));
    $headers = apply_filters('edd_receipt_headers', $emails->get_headers(), $payment_id, $payment_data);
    $emails->__set('headers', $headers);
    $emails->send($to_email, $subject, $message, array());
    if ($admin_notice && !edd_admin_notices_disabled($payment_id)) {
        do_action('edd_admin_sale_notice', $payment_id, $payment_data);
    }
}
/**
 * Check if the current user has a valid license for the $download_id passed-in.
 *
 * @param  array ( 'download' => Download/Item ID (post_id), 'price_id' => Price ID )
 * @return bool true/false
 */
function edd_sl_current_user_has_valid_license_for($download_ids)
{
    // Get the current user ID
    $current_user_id = get_current_user_id();
    // Set default for license validity to false
    $license_valid_for_download = false;
    // Get the current user's purchases
    $user_purchases = edd_get_users_purchases($current_user_id);
    if ($user_purchases) {
        foreach ($user_purchases as $user_purchase) {
            setup_postdata($user_purchase);
            // Get all the licenses for all the user's purchases
            $sl = edd_software_licensing();
            $licenses = $sl->get_licenses_of_purchase($user_purchase->ID);
            if (is_array($licenses)) {
                foreach ($licenses as $license_post) {
                    $license_key = get_post_meta($license_post->ID, '_edd_sl_key', true);
                    foreach ($download_ids as $download_id) {
                        if ($sl->is_download_id_valid_for_license($download_id['download'], $license_key)) {
                            $license_status = $sl->get_license_status($license_post->ID);
                            if ($license_status != 'expired' && $license_post->post_status == 'publish') {
                                $license_valid_for_download = true;
                                break;
                            }
                        }
                    }
                }
            }
            wp_reset_postdata();
        }
    }
    return $license_valid_for_download;
}
/**
 * Deactivates the given site
 */
function deactivate_site_license()
{
    authorize_request();
    $license_id = sanitize_text_field($_GET['license_id']);
    $site_url = sanitize_text_field($_GET['site_url']);
    edd_software_licensing()->delete_site($license_id, $site_url);
    die('<script>window.close();</script>');
}
Beispiel #4
0
/**
 * Hide download links for expired licenses on purchase receipt page
 *
 * @access      private
 * @since       2.3
 * @return      void
 */
function edd_sl_hide_downloads_on_expired($show, $item, $receipt_args)
{
    $payment_id = $receipt_args['id'];
    $licenses = edd_software_licensing()->get_licenses_of_purchase($payment_id);
    if (!empty($licenses)) {
        foreach ($licenses as $license) {
            if ('expired' == edd_software_licensing()->get_license_status($license->ID)) {
                $show = false;
                break;
            }
        }
    }
    return $show;
}
 public function check_for_request()
 {
     if (empty($_POST['rcp_action']) || 'get_version' != $_POST['rcp_action']) {
         return;
     }
     if (empty($_POST['license'])) {
         return;
     }
     if (empty($_POST['id']) || !is_numeric($_POST['id'])) {
         return;
     }
     if (empty($_POST['slug'])) {
         return;
     }
     if (empty($_POST['url'])) {
         return;
     }
     if (!function_exists('edd_software_licensing')) {
         return;
     }
     $add_on = get_post(absint($_POST['id']));
     if (!$add_on) {
         status_header(404);
         return;
     }
     $licensing = edd_software_licensing();
     $license = $licensing->get_license_by_key(sanitize_text_field($_POST['license']));
     if (!$license) {
         status_header(402);
         return;
     }
     $price_id = (int) get_post_meta($license, '_edd_sl_download_price_id', true);
     if (3 !== $price_id && 4 !== $price_id) {
         status_header(401);
         return;
         // Not a developer license
     }
     // All good, retrieve the Add On details
     if ('expired' === $licensing->get_license_status($license)) {
         $description = '<p><strong>' . __('Your license is expired. Please renew it or purchase a new one in order to update this item.', 'edd_sl') . '</strong></p>' . $description;
         $changelog = '<p><strong>' . __('Your license is expired. Please renew it or purchase a new one in order to update this item.', 'edd_sl') . '</strong></p>' . $changelog;
     } else {
         $changelog = get_post_meta($add_on->ID, '_edd_sl_changelog', true);
         $description = !empty($add_on->post_excerpt) ? $add_on->post_excerpt : $add_on->post_content;
     }
     $response = array('new_version' => get_post_meta($add_on->ID, '_edd_sl_version', true), 'name' => $add_on->post_title, 'slug' => $_POST['slug'], 'url' => get_permalink($add_on->ID), 'homepage' => get_permalink($add_on->ID), 'package' => $this->get_encoded_download_package_url($add_on->ID, $_POST['license'], $_POST['url']), 'download_link' => $this->get_encoded_download_package_url($add_on->ID, $_POST['license'], $_POST['url']), 'sections' => serialize(array('description' => wpautop(strip_tags($description, '<p><li><ul><ol><strong><a><em><span><br>')), 'changelog' => wpautop(strip_tags(stripslashes($changelog), '<p><li><ul><ol><strong><a><em><span><br>')))));
     echo json_encode($response);
     exit;
 }
Beispiel #6
0
/**
 * Displays a Manage Licenses link in purchase history
 *
 * @since 2.7
 */
function edd_sl_site_management_links($payment_id, $purchase_data)
{
    $licensing = edd_software_licensing();
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if ($downloads) {
        $manage_licenses_url = esc_url(add_query_arg(array('action' => 'manage_licenses', 'payment_id' => $payment_id)));
        echo '<td class="edd_license_key">';
        if (edd_is_payment_complete($payment_id)) {
            echo '<a href="' . esc_url($manage_licenses_url) . '">' . __('View Licenses', 'edd_sl') . '</a>';
        } else {
            echo '-';
        }
        echo '</td>';
    }
}
Beispiel #7
0
 public function populate_choices($choices)
 {
     $licenses = edd_software_licensing()->get_license_keys_of_user(get_current_user_id());
     if (empty($licenses)) {
         return $choices;
     }
     $to_add = array();
     foreach ($licenses as $license) {
         $key = edd_software_licensing()->get_license_key($license->ID);
         $download = get_post(edd_software_licensing()->get_download_by_license($key));
         $status = edd_software_licensing()->get_license_status($license->ID);
         if (0 === $download->ID || 'expired' == $status) {
             continue;
         }
         $choices[] = array('value' => 'valid-' . sanitize_title(get_the_title($download->ID)), 'text' => get_the_title($download->ID) . ' &mdash; Expires: ' . date_i18n(get_option('date_format'), strtotime(edd_software_licensing()->get_license_expiration($license->ID))));
     }
     return $choices;
 }
 public function process_renew_all()
 {
     if (empty($_POST['edd_renew_all'])) {
         return;
     }
     if (!is_user_logged_in()) {
         return;
     }
     if (!wp_verify_nonce($_POST['edd_sl_renew_all'], 'edd_sl_renew_all_nonce')) {
         wp_die(__('Error', 'edd-sl-renew-all'), __('Nonce verification failed', 'edd-sl-renew-all'), array('response' => 403));
     }
     $renew_type = edd_sanitize_text_field($_POST['edd_sl_renew_type']);
     $license_keys = edd_software_licensing()->get_license_keys_of_user(get_current_user_id());
     switch ($renew_type) {
         case 'expired':
             $stop_date = current_time('timestamp');
             break;
         case 'expiring_1_month':
             $stop_date = strtotime('+1 month', current_time('timestamp'));
             break;
         case 'all':
         default:
             $stop_date = false;
             break;
     }
     if ($license_keys) {
         foreach ($license_keys as $license) {
             if (!edd_software_licensing()->get_license_key($license->ID)) {
                 continue;
             }
             $expiration = edd_software_licensing()->get_license_expiration($license->ID);
             if ('lifetime' === $expiration) {
                 continue;
             }
             if ($stop_date && $expiration > $stop_date) {
                 continue;
             }
             edd_sl_add_renewal_to_cart($license->ID);
         }
         wp_redirect(edd_get_checkout_uri());
         exit;
     }
 }
 /**
  * Record a subscription payment
  *
  * @since  1.0.1
  * @return void
  */
 public function record_subscription_payment($parent_id = 0, $amount = '', $txn_id = '', $unique_key = 0)
 {
     global $edd_options;
     if ($this->payment_exists($unique_key)) {
         return;
     }
     // increase the earnings for each product in the subscription
     $downloads = edd_get_payment_meta_downloads($parent_id);
     if ($downloads) {
         foreach ($downloads as $download) {
             edd_increase_earnings($download['id'], $amount);
         }
     }
     // setup the payment daya
     $payment_data = array('parent' => $parent_id, 'price' => $amount, 'user_email' => edd_get_payment_user_email($parent_id), 'purchase_key' => get_post_meta($parent_id, '_edd_payment_purchase_key', true), 'currency' => edd_get_option('currency', 'usd'), 'downloads' => $downloads, 'user_info' => edd_get_payment_meta_user_info($parent_id), 'cart_details' => edd_get_payment_meta_cart_details($parent_id), 'status' => 'edd_subscription', 'gateway' => edd_get_payment_gateway($parent_id));
     // record the subscription payment
     $payment = edd_insert_payment($payment_data);
     if (!empty($unique_key)) {
         update_post_meta($payment, '_edd_recurring_' . $unique_key, '1');
     }
     // Record transaction ID
     if (!empty($txn_id)) {
         if (function_exists('edd_set_payment_transaction_id')) {
             edd_set_payment_transaction_id($payment, $txn_id);
         }
     }
     // Update the expiration date of license keys, if EDD Software Licensing is active
     if (function_exists('edd_software_licensing')) {
         $licenses = edd_software_licensing()->get_licenses_of_purchase($parent_id);
         if (!empty($licenses)) {
             foreach ($licenses as $license) {
                 // Update the expiration dates of the license key
                 edd_software_licensing()->renew_license($license->ID, $parent_id);
             }
         }
     }
     do_action('edd_recurring_record_payment', $payment, $parent_id, $amount, $txn_id, $unique_key);
 }
 /**
  * Query database for license data and prepare it for the table
  *
  * @access      private
  * @since       1.0
  * @return      array
  */
 function licenses_data()
 {
     $licenses_data = array();
     $license_args = array('post_type' => 'edd_license', 'post_status' => array('publish', 'future', 'draft'), 'posts_per_page' => $this->per_page, 'paged' => $this->get_paged(), 'meta_query' => array('relation' => 'AND'), 'post_parent' => 0);
     $view = isset($_GET['view']) ? $_GET['view'] : false;
     if ($view && 'disabled' == $view) {
         $license_args['post_status'] = 'draft';
     } elseif ($view) {
         $license_args['meta_query'][] = array('key' => '_edd_sl_status', 'value' => $view);
     }
     $key_search = false;
     // check to see if we are searching
     if (!empty($_GET['s'])) {
         $search = trim($_GET['s']);
         if (!is_email($search)) {
             $has_period = strstr($search, '.');
             if (false === $has_period && !preg_match('/\\s/', $search)) {
                 // Search in the license key.
                 $license_args['meta_query'][] = array('key' => '_edd_sl_key', 'value' => $search);
                 $key_search = true;
                 unset($license_args['post_parent']);
             } elseif ($has_period) {
                 // Search in the sites that are registered.
                 $license_args['meta_query'][] = array('key' => '_edd_sl_sites', 'value' => edd_software_licensing()->clean_site_url($search), 'compare' => 'LIKE');
             } else {
                 $license_args['s'] = $search;
             }
         } else {
             $license_args['s'] = $search;
         }
     }
     $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'ID';
     $order = isset($_GET['order']) ? $_GET['order'] : 'DESC';
     $order_inverse = $order == 'DESC' ? 'ASC' : 'DESC';
     $license_args['order'] = $order;
     switch ($orderby) {
         case 'purchased':
             $license_args['orderby'] = 'date';
             break;
         case 'expires':
             $license_args['orderby'] = 'meta_value_num';
             $license_args['meta_key'] = '_edd_sl_expiration';
             break;
     }
     $licenses = get_posts($license_args);
     // If searching by Key
     if ($key_search) {
         $found_license = $licenses[0];
         // And we found a child license
         if (!empty($found_license->post_parent)) {
             // Swap out the meta query for the parent license to show the entire bundle
             $parent_license_key = get_post_meta($found_license->post_parent, '_edd_sl_key', true);
             foreach ($license_args['meta_query'] as $key => $args) {
                 if (!empty($args['key']) && '_edd_sl_key' === $args['key']) {
                     $license_args['meta_query'][$key]['value'] = $parent_license_key;
                 }
             }
             $licenses = get_posts($license_args);
         }
     }
     if ($licenses) {
         foreach ($licenses as $license) {
             $status = get_post_meta($license->ID, '_edd_sl_status', true);
             $key = get_post_meta($license->ID, '_edd_sl_key', true);
             $user = get_post_meta($license->ID, '_edd_sl_user_id', true);
             $expires = date_i18n(get_option('date_format'), (int) get_post_meta($license->ID, '_edd_sl_expiration', true));
             $purchased = get_the_time(get_option('date_format'), $license->ID);
             $download_id = get_post_meta($license->ID, '_edd_sl_download_id', true);
             $licenses_data[] = array('ID' => $license->ID, 'title' => get_the_title($license->ID), 'status' => $status, 'key' => $key, 'user' => $user, 'expires' => $expires, 'purchased' => $purchased, 'download_id' => $download_id, 'is_child_license' => false);
             if (edd_is_bundled_product($download_id)) {
                 $child_args = array('post_type' => 'edd_license', 'post_status' => array('publish', 'future'), 'posts_per_page' => -1, 'post_parent' => $license->ID);
                 $child_licenses = get_children($child_args);
             } else {
                 $child_licenses = false;
             }
             if (!empty($child_licenses)) {
                 foreach ($child_licenses as $child_license) {
                     $child_license_status = get_post_meta($child_license->ID, '_edd_sl_status', true);
                     if (!empty($_GET['view']) && $child_license_status !== $_GET['view']) {
                         continue;
                     }
                     $licenses_data[] = array('ID' => $child_license->ID, 'title' => get_the_title($child_license->ID), 'status' => $status, 'key' => $key, 'user' => $user, 'expires' => $expires, 'purchased' => $purchased, 'download_id' => get_post_meta($child_license->ID, '_edd_sl_download_id', true), 'is_child_license' => true);
                 }
             }
         }
     }
     return $licenses_data;
 }
/**
 * 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);
}
/**
 * Return array of license keys matched with download ID for payment/customer
 * 
 * @access public
 * @param mixed $payment_id
 *
 * @return array $key
 */
function edd_pup_get_license_keys($payment_id)
{
    $keys = '';
    $licenses = edd_software_licensing()->get_licenses_of_purchase($payment_id);
    if ($licenses) {
        foreach ($licenses as $license) {
            $meta = get_post_custom($license->ID);
            $keys[$meta['_edd_sl_download_id'][0]] = array('license_id' => $license->ID, 'key' => $meta['_edd_sl_key'][0]);
        }
    }
    return $keys;
}
			<td colspan="2"><?php 
    _e('No sites have been activated for this license', 'edd_sl');
    ?>
</td>
			<?php 
    do_action('edd_sl_license_sites_row_end', $license_id);
    ?>
		</tr>
	<?php 
}
?>
</table>

<?php 
$status = edd_software_licensing()->get_license_status($license_id);
$at_limit = edd_software_licensing()->is_at_limit($license_id, $download_id);
?>

<?php 
if (!$at_limit && ($status == 'active' || $status == 'inactive')) {
    ?>
<form method="post" id="edd_sl_license_add_site_form" class="edd_sl_form">
	<div>
		<span><?php 
    _e('Use this form to authorize a new site URL for this license. Enter the full site URL.', 'edd_sl');
    ?>
</span>
		<input type="text" name="site_url" class="edd-input" value="http://"/>
		<input type="submit" class="button-primary button" value="<?php 
    _e('Add Site', 'edd_sl');
    ?>
    /**
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    public function widget($args, $instance)
    {
        //No EDD? Bail
        if (!class_exists('Easy_Digital_Downloads')) {
            return false;
        }
        //Not EDD admin? Bail
        if (!current_user_can('view_shop_sensitive_data')) {
            return false;
        }
        //Handle before_widget args
        echo $args['before_widget'];
        if (!empty($instance['title'])) {
            echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
        }
        $user_id = get_the_author_meta('ID');
        $user_data = get_userdata($user_id);
        ?>
		<div class="box">

			<?php 
        do_action('wi_bbp_sidebar');
        ?>

			<h3><?php 
        echo get_the_author_meta('first_name') . '  ' . get_the_author_meta('last_name');
        ?>
</h3>

			<p class="bbp-user-forum-role"><?php 
        printf('Forum Role: %s', bbp_get_user_display_role($user_id));
        ?>
</p>

			<p class="bbp-user-topic-count"><?php 
        printf('Topics Started: %s', bbp_get_user_topic_count_raw($user_id));
        ?>
</p>

			<p class="bbp-user-reply-count"><?php 
        printf('Replies Created: %s', bbp_get_user_reply_count_raw($user_id));
        ?>
</p>


			<div class="wi_users_purchases">
				<h3><?php 
        _e('User\'s Purchases:', 'wi_bbp');
        ?>
</h3>
				<?php 
        $purchases = edd_get_users_purchases($user_data->user_email, 100, false, 'any');
        if ($purchases) {
            echo '<ul>';
            foreach ($purchases as $purchase) {
                echo '<li>';
                echo '<strong><a href="' . admin_url('edit.php?post_type=download&page=give-payment-history&view=view-order-details&id=' . $purchase->ID) . '">#' . $purchase->ID . ' - ' . edd_get_payment_status($purchase, true) . '</a></strong><br/>';
                $downloads = edd_get_payment_meta_downloads($purchase->ID);
                foreach ($downloads as $download) {
                    echo get_the_title($download['id']) . ' - ' . date('F j, Y', strtotime($purchase->post_date)) . '<br/>';
                }
                //Check license key
                if (function_exists('edd_software_licensing')) {
                    $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
                    if ($licenses) {
                        echo '<strong>' . __('Licenses:', 'edd') . '</strong><br/>';
                        foreach ($licenses as $license) {
                            $key = edd_software_licensing()->get_license_key($license->ID);
                            $download_id = edd_software_licensing()->get_download_by_license($key);
                            $title = get_the_title($download_id);
                            //output license URL
                            echo $title . ' - <a href="' . admin_url('edit.php?post_type=download&page=give-licenses&s=' . $key) . '">' . $key . '</a>';
                            echo ' - ' . edd_software_licensing()->get_license_status($license->ID);
                            echo '<br/>';
                        }
                    }
                    echo '<hr/>';
                }
                echo '</li>';
            }
            echo '</ul>';
        } else {
            echo '<p>' . __('This user has never purchased anything.', 'wi_bbp') . '</p>';
        }
        ?>
			</div>
		</div>
		<?php 
        //After widget args
        echo $args['after_widget'];
        return false;
    }
        echo edd_software_licensing()->get_site_count($license->ID);
        ?>
</span><span class="edd_sl_limit_sep">&nbsp;/&nbsp;</span><span class="edd_sl_limit_max"><?php 
        echo edd_software_licensing()->license_limit($license->ID);
        ?>
</span></td>
				<td><?php 
        if (3 === (int) $price_id) {
            echo 'never';
        } else {
            echo date_i18n('F j, Y', edd_software_licensing()->get_license_expiration($license->ID));
        }
        ?>
</td>
				<?php 
        if (!edd_software_licensing()->force_increase()) {
            ?>
				<td><a href="<?php 
            echo esc_url(add_query_arg('license_id', $license->ID));
            ?>
"><?php 
            _e('Manage Sites', 'edd_sl');
            ?>
</a></td>
				<?php 
        }
        ?>
				<?php 
        do_action('edd_sl_license_row_end', $license->ID);
        ?>
			</tr>
$color = $color == 'inherit' ? '' : $color;
?>
<script type="text/javascript">jQuery(document).ready(function($){ $(".edd_sl_show_key").on("click",function(e){e.preventDefault(),$(this).parent().find(".edd_sl_license_key").on("click",function(){$(this).select()}).fadeToggle("fast")}); });</script>
<p><a href="<?php 
echo esc_url(remove_query_arg(array('payment_id', 'edd_sl_error')));
?>
" class="edd-manage-license-back edd-submit button <?php 
echo esc_attr($color);
?>
"><?php 
_e('Go back', 'edd_sl');
?>
</a></p>
<?php 
// Retrieve all license keys for the specified payment
$edd_sl = edd_software_licensing();
$keys = $edd_sl->get_licenses_of_purchase($payment_id);
if ($keys) {
    ?>
	<table id="edd_sl_license_keys" class="edd_sl_table">
		<thead>
			<tr class="edd_sl_license_row">
				<?php 
    do_action('edd_sl_license_header_before');
    ?>
				<th class="edd_sl_item"><?php 
    _e('Item', 'edd_sl');
    ?>
</th>
				<th class="edd_sl_key"><?php 
    _e('Key', 'edd_sl');
/**
 * EDD Forum Sidebar
 *
 * @since		1.0.0
 * @return		void
 */
function edd_bbp_sidebar()
{
    global $post;
    $user_id = get_the_author_meta('ID');
    $user_data = get_userdata($user_id);
    ?>
	<div class="box">

		<?php 
    do_action('edd_bbp_sidebar');
    ?>

		<h3><?php 
    echo get_the_author_meta('first_name') . '  ' . get_the_author_meta('last_name');
    ?>
</h3>
		<p class="bbp-user-forum-role"><?php 
    printf('Forum Role: %s', bbp_get_user_display_role($user_id));
    ?>
</p>
		<p class="bbp-user-topic-count"><?php 
    printf('Topics Started: %s', bbp_get_user_topic_count_raw($user_id));
    ?>
</p>
		<p class="bbp-user-reply-count"><?php 
    printf('Replies Created: %s', bbp_get_user_reply_count_raw($user_id));
    ?>
</p>

		<div class="rcp_support_status">
			<h4>Priority Support Access</h4>
			<?php 
    if (function_exists('rcp_is_active')) {
        if (rcp_is_active($user_id)) {
            ?>
				<p>Has <strong>Priority Support</strong> access.</p>
			<?php 
        } elseif (rcp_is_expired($user_id)) {
            ?>
				<p><strong>Priority Support</strong> access has <span style="color:red;">expired</span>.</p>
			<?php 
        } else {
            ?>
				<p>Has no priority support accesss</p>
			<?php 
        }
    }
    ?>
		</div><!-- /.rcp_support_status -->

		<div class="edd_users_purchases">
			<h4>User's Purchases:</h4>
			<?php 
    $purchases = edd_get_users_purchases($user_data->user_email, 100, false, 'any');
    if ($purchases) {
        echo '<ul>';
        foreach ($purchases as $purchase) {
            echo '<li>';
            echo '<strong><a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $purchase->ID) . '">#' . $purchase->ID . ' - ' . edd_get_payment_status($purchase, true) . '</a></strong><br/>';
            $downloads = edd_get_payment_meta_downloads($purchase->ID);
            foreach ($downloads as $download) {
                echo get_the_title($download['id']) . ' - ' . date('F j, Y', strtotime($purchase->post_date)) . '<br/>';
            }
            if (function_exists('edd_software_licensing')) {
                $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
                if ($licenses) {
                    echo '<strong>Licenses:</strong><br/>';
                    foreach ($licenses as $license) {
                        $key = edd_software_licensing()->get_license_key($license->ID);
                        echo '<a href="' . admin_url('edit.php?post_type=download&page=edd-licenses&s=' . $key) . '">' . $key . '</a>';
                        echo ' - ' . edd_software_licensing()->get_license_status($license->ID);
                        echo '<br/>';
                    }
                }
                echo '<hr/>';
            }
            echo '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>This user has never purchased anything.</p>';
    }
    ?>
		</div>
	</div>
	<?php 
}
function edd_downloads_updated_sites($meta_id, $object_id, $meta_key, $_meta_value)
{
    if ($meta_key == '_edd_sl_sites' && is_admin()) {
        $license_id = absint($_GET['license_id']);
        $site_url = urldecode($_GET['site_url']);
        $sites = edd_software_licensing()->get_sites($license_id);
        $download_id = get_post_meta($license_id, '_edd_sl_download_id', true);
        $download_files = edd_get_download_files($download_id);
        if (empty($download_files)) {
            return true;
        } else {
            $product_id = $download_files[0]['attachment_id'];
        }
        /*		unset($sites[$product_id.'_changes']);
        		$current_values = count($sites);
        
        		if ($current_values > 0) {
        			$sites[$product_id] = $sites[0];
        			$sites[$product_id.'_changes'] = $current_values;
        			unset ($sites[0]);
        		}*/
        $updated_sites = array();
        $updated_sites[$product_id] = end($sites);
        $updated_sites[$product_id . '_changes'] = count($sites) - 1;
        if (!empty($sites)) {
            $new_sites = serialize($updated_sites);
        } else {
            $new_sites = "";
        }
        global $wpdb;
        $wpdb->query("UPDATE " . $wpdb->prefix . "postmeta SET `meta_value` = '" . $new_sites . "' WHERE `post_id` = " . $license_id . " AND `meta_key` = '_edd_sl_sites' ");
    }
}
 /**
  * Process the request
  *  - Find purchase data
  *  - Generate response*
  * @link http://developer.helpscout.net/custom-apps/style-guide/ HelpScout Custom Apps Style Guide
  * @return string
  */
 private function build_response_html()
 {
     if (count($this->customer_payments) === 0) {
         // No purchase data was found
         return sprintf('<p>No payments founds for %s.</p>', '<strong>' . join('</strong> or <strong>', $this->customer_emails) . '</strong>');
     }
     // build array of purchases
     $orders = array();
     foreach ($this->customer_payments as $payment) {
         $order = array();
         $order['payment_id'] = $payment->ID;
         $order['date'] = $payment->post_date;
         $order['amount'] = edd_get_payment_amount($payment->ID);
         $order['status'] = $payment->post_status;
         $order['payment_method'] = $this->get_payment_method($payment->ID);
         $order['downloads'] = array();
         $order['resend_receipt_link'] = '';
         $order['is_renewal'] = false;
         $order['is_completed'] = $payment->post_status === 'publish';
         // do stuff for completed orders
         if ($payment->post_status === 'publish') {
             $args = array('payment_id' => (string) $order['payment_id']);
             $request = new Request($args);
             $order['resend_receipt_link'] = $request->get_signed_url('resend_purchase_receipt');
         }
         // find purchased Downloads.
         $order['downloads'] = (array) edd_get_payment_meta_downloads($payment->ID);
         // for each download, find license + sites
         if (function_exists('edd_software_licensing')) {
             /**
              * @var EDD_Software_Licensing
              */
             $licensing = edd_software_licensing();
             // was this order a renewal?
             $order['is_renewal'] = (string) get_post_meta($payment->ID, '_edd_sl_is_renewal', true) !== '';
             if ($order['is_completed']) {
                 foreach ($order['downloads'] as $key => $download) {
                     // only proceed if this download has EDD Software Licensing enabled
                     if ('' === (string) get_post_meta($download['id'], '_edd_sl_enabled', true)) {
                         continue;
                     }
                     // find license that was given out for this download purchase
                     $license = $licensing->get_license_by_purchase($payment->ID, $download['id']);
                     if (is_object($license)) {
                         $key = (string) get_post_meta($license->ID, '_edd_sl_key', true);
                         // add support for "lifetime" licenses
                         if (method_exists($licensing, 'is_lifetime_license') && $licensing->is_lifetime_license($license->ID)) {
                             $is_expired = false;
                         } else {
                             $expires = (string) get_post_meta($license->ID, '_edd_sl_expiration', true);
                             $is_expired = $expires < time();
                         }
                         $order['downloads'][$key]['license'] = array('limit' => 0, 'key' => $key, 'is_expired' => $is_expired, 'sites' => array());
                         // look-up active sites if license is not expired
                         if (!$is_expired) {
                             // get license limit
                             $order['downloads'][$key]['license']['limit'] = $licensing->get_license_limit($download['id'], $license->ID);
                             $sites = (array) $licensing->get_sites($license->ID);
                             foreach ($sites as $site) {
                                 $args = array('license_id' => (string) $license->ID, 'site_url' => $site);
                                 // make sure site url is prefixed with "http://"
                                 $site_url = strpos($site, '://') !== false ? $site : 'http://' . $site;
                                 $request = new Request($args);
                                 $order['downloads'][$key]['license']['sites'][] = array('url' => $site_url, 'deactivate_link' => $request->get_signed_url('deactivate_site_license'));
                             }
                         }
                         //endif not expired
                     }
                     // endif license found
                 }
                 // end foreach downloads
             }
             // endif order completed
         }
         $orders[] = $order;
     }
     // build HTML output
     $html = '';
     foreach ($orders as $order) {
         $html .= str_replace('\\t', '', $this->order_row($order));
     }
     return $html;
 }
Beispiel #20
0
/**
 * Get a user's download price IDs that they have access to
 *
 * @since  1.9
 */
function affwp_get_users_licenses($user_id = 0)
{
    if (!function_exists('edd_software_licensing')) {
        return;
    }
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    // if user is still a guest return an empty array as their ID will be 0
    if (!$user_id) {
        return array();
    }
    $args = array('posts_per_page' => -1, 'post_type' => 'edd_license', 'meta_key' => '_edd_sl_user_id', 'meta_value' => $user_id, 'fields' => 'ids');
    $keys = array();
    $licenses = get_posts($args);
    if ($licenses) {
        foreach ($licenses as $key) {
            $keys[$key] = array('license' => get_post_meta($key, '_edd_sl_key', true), 'price_id' => get_post_meta($key, '_edd_sl_download_price_id', true), 'limit' => edd_software_licensing()->get_license_limit(affwp_get_affiliatewp_id(), $key), 'expires' => edd_software_licensing()->get_license_expiration($key));
        }
    }
    return $keys;
}
Beispiel #21
0
/**
 * Tap into the filter to use data from a readme.txt file
 *
 * @since  2.4
 * @see  EDD_Software_Licensing::get_latest_version_remote()
 * @param  array  $original_response License response array
 * @param  WP_Post $download          Post object of the Download item
 * @return array                    Modified array, if readme exists. Otherwise, original array is returned.
 */
function edd_sl_readme_modify_license_response($response = array(), $download = NULL)
{
    if (is_admin() || defined('DOING_AJAX')) {
        // Prevent errors and send headers
        ini_set('display_errors', 0);
        ini_set('log_errors', 1);
        error_reporting(0);
        define('DOING_AJAX', true);
        @header('Content-type: text/plain');
        @send_nosniff_header();
    }
    // Get the URL to use in the WP.org validator
    $readme_url = get_post_meta($download->ID, '_edd_readme_location', true);
    // If the URL doesn't exist, get outta here.
    if (empty($readme_url)) {
        return $response;
    }
    // Fetch the cached/fresh readme data
    $readme = _edd_sl_get_readme_data($readme_url, $download->ID);
    // The readme didn't exist or process. Return existing response.
    if (empty($readme)) {
        return $response;
    }
    // Modify the homepage linked to in the Update Notice
    $response['homepage'] = edd_sl_readme_get_download_homepage($download->ID);
    // Set the slug
    $response['new_version'] = edd_software_licensing()->get_latest_version($download->ID);
    // The original response sections
    $response['sections'] = maybe_unserialize(@$response['sections']);
    // Get the override readme sections settings
    if ($readme_sections = get_post_meta($download->ID, '_edd_readme_sections', true)) {
        // We loop through the settings sections and make overwrite the
        // existing sections with the custom readme.txt sections.
        foreach ((array) $readme_sections as $section) {
            $response['sections'][$section] = $readme['sections']["{$section}"];
        }
    }
    if (!empty($readme['tested_up_to'])) {
        $response['tested'] = $readme['tested_up_to'];
    }
    // Reserialize it
    $response['sections'] = serialize($response['sections']);
    // Get the override readme meta settings
    if ($readme_meta = get_post_meta($download->ID, '_edd_readme_meta', true)) {
        // We loop through the settings sections and make overwrite the
        // existing sections with the custom readme.txt sections.
        foreach ((array) $readme_meta as $meta) {
            $response[$meta] = $readme["{$meta}"];
        }
    }
    if (get_post_meta($download->ID, '_edd_readme_plugin_added', true)) {
        $response['added'] = date('Y-m-d', strtotime($download->post_date_gmt));
    }
    if (get_post_meta($download->ID, '_edd_readme_plugin_last_updated', true)) {
        $response['last_updated'] = apply_filters('edd_sl_readme_last_updated', human_time_diff(strtotime($download->post_modified_gmt), current_time('timestamp', 1)) . ' ago', $download);
    }
    // Remove empty items
    $response = array_filter($response);
    // Filter this if you want to.
    return apply_filters('edd_sl_license_readme_response', $response, $download, $readme);
}
                    $download_id = edd_software_licensing()->get_download_id($license->ID);
                    $post = get_post($download_id);
                    $download_files = get_post_meta($post->ID, 'edd_download_files', true);
                    foreach ($download_files as $filekey => $file) {
                        $post_meta = get_post_meta($licenses[$cart_row]->ID, '_edd_sl_download_id', true);
                        $product = get_post($file['attachment_id']);
                        if (!empty($product)) {
                            ?>
							<div style="float:left;">
								<span class="edd_downloads_license_number">
									<?php 
                            echo $post->post_title;
                            ?>
<br/>
									<?php 
                            _e('License No: ' . edd_software_licensing()->get_license_key($license->ID), 'dwqa_site_info');
                            ?>
								</span>
							</div>
							<div style="float:left;">
		
								<form action="<?php 
                            echo site_url($Path);
                            ?>
" method="post" class="edd_downloads_domains" id="edd_downloads_domains_domain_form_<?php 
                            echo absint($license->ID);
                            ?>
">
									<input id="edd_downloads_domains_domain_<?php 
                            echo absint($license->ID);
                            ?>
/**
 * Forum Sidebar
 *
 * @since        1.0.0
 * @return        void
 */
function wi_bbp_sidebar()
{
    global $post;
    $user_id = get_the_author_meta('ID');
    $user_data = get_userdata($user_id);
    ?>
	<div class="box">

		<?php 
    do_action('wi_bbp_sidebar');
    ?>

		<h3><?php 
    echo get_the_author_meta('first_name') . '  ' . get_the_author_meta('last_name');
    ?>
</h3>

		<p class="bbp-user-forum-role"><?php 
    printf('Forum Role: %s', bbp_get_user_display_role($user_id));
    ?>
</p>

		<p class="bbp-user-topic-count"><?php 
    printf('Topics Started: %s', bbp_get_user_topic_count_raw($user_id));
    ?>
</p>

		<p class="bbp-user-reply-count"><?php 
    printf('Replies Created: %s', bbp_get_user_reply_count_raw($user_id));
    ?>
</p>


		<div class="wi_users_purchases">
			<h3><?php 
    _e('User\'s Purchases:', 'wi_bbp');
    ?>
</h3>
			<?php 
    $purchases = edd_get_users_purchases($user_data->user_email, 100, false, 'any');
    if ($purchases) {
        echo '<ul>';
        foreach ($purchases as $purchase) {
            echo '<li>';
            echo '<strong><a href="' . admin_url('edit.php?post_type=download&page=give-payment-history&view=view-order-details&id=' . $purchase->ID) . '">#' . $purchase->ID . ' - ' . edd_get_payment_status($purchase, true) . '</a></strong><br/>';
            $downloads = edd_get_payment_meta_downloads($purchase->ID);
            foreach ($downloads as $download) {
                echo get_the_title($download['id']) . ' - ' . date('F j, Y', strtotime($purchase->post_date)) . '<br/>';
            }
            //Check license key
            if (function_exists('edd_software_licensing')) {
                $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
                if ($licenses) {
                    echo '<strong>Licenses:</strong><br/>';
                    foreach ($licenses as $license) {
                        $key = edd_software_licensing()->get_license_key($license->ID);
                        echo '<a href="' . admin_url('edit.php?post_type=download&page=give-licenses&s=' . $key) . '">' . $key . '</a>';
                        echo ' - ' . edd_software_licensing()->get_license_status($license->ID);
                        echo '<br/>';
                    }
                }
                echo '<hr/>';
            }
            echo '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>This user has never purchased anything.</p>';
    }
    ?>
		</div>
	</div>
	<?php 
}
Beispiel #24
0
/**
 * 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;
}
Beispiel #25
0
 public function filter_reminder_template_tags($text = '', $license_id = 0)
 {
     $payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true);
     $user_info = edd_get_payment_meta_user_info($payment_id);
     $user_id = edd_get_payment_user_id($payment_id);
     // Retrieve the customer name
     if ($user_id) {
         $user_data = get_userdata($user_id);
         $customer_name = $user_data->display_name;
     } elseif (isset($user_info['first_name'])) {
         $customer_name = $user_info['first_name'];
     } else {
         $customer_name = $user_info['email'];
     }
     $license_key = edd_software_licensing()->get_license_key($license_id);
     $download_id = get_post_meta($license_id, '_edd_sl_download_id', true);
     $product_name = get_the_title($download_id);
     $expiration = edd_software_licensing()->get_license_expiration($license_id);
     $expiration = date(get_option('date_format'), $expiration);
     $discount = edd_sl_get_renewal_discount_percentage($license_id);
     $renewal_link = apply_filters('edd_sl_renewal_link', edd_get_checkout_uri(array('edd_license_key' => $license_key, 'download_id' => $download_id)));
     $text = str_replace('{name}', $customer_name, $text);
     $text = str_replace('{license_key}', $license_key, $text);
     $text = str_replace('{product_name}', $product_name, $text);
     $text = str_replace('{expiration}', $expiration, $text);
     if (!empty($discount)) {
         $text = str_replace('{renewal_discount}', $discount . '%', $text);
     }
     $text = str_replace('{renewal_link}', $renewal_link, $text);
     return $text;
 }
                                            ?>
</span></button><?php 
                                        }
                                    }
                                } else {
                                    echo '<li>' . __('No downloadable files found for this bundled item.', 'edd_downloads') . '</li>';
                                }
                                ?>
		
									</td>
		
									<td>
		
										<?php 
                                //show renew option for expired product
                                if ('expired' == edd_software_licensing()->get_license_status($bundle_license->ID)) {
                                    ?>
		
											<div class="edd_purchase_submit_wrapper">
		
												<?php 
                                    if (!isset($edd_options['expired'])) {
                                        $edd_options['expired'] = array();
                                        $edd_options['expired'][$payment_id] = $bundle_item;
                                        $edd_options['payment_id'] = $payment_id;
                                    } else {
                                        $edd_options['expired'][$payment_id] = $bundle_item;
                                        $edd_options['payment_id'] = $payment_id;
                                    }
                                    $edd_options[$bundle_item] = array('download_id' => $post_meta, 'payment_id' => $payment_id);
                                    echo edd_get_purchase_link(array('download_id' => $bundle_item, 'payment_id' => $payment_id));
/**	
 * 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 dwqa_siteinfo_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 !== NULL) {
        $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);
            $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 ($downloads === NULL || 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;
}
Beispiel #28
0
 public function fire_drip_expired_event($license_id = 0, $period = null)
 {
     // global $edd_options;
     if (empty($license_id) || empty($period) || !class_exists('edd_software_licensing')) {
         return;
     }
     //fetch the license
     $license = get_post($license_id);
     if (!$license || 'edd_license' != $license->post_type || !empty($license->post_parent)) {
         return;
     }
     //error_log(var_export($license,true));
     $customer = false;
     if (class_exists('EDD_Customer')) {
         $payment_id = get_post_meta($license->ID, '_edd_sl_payment_id', true);
         $customer_id = edd_get_payment_customer_id($payment_id);
         $customer = new EDD_Customer($customer_id);
     }
     //error_log(var_export($customer,true));
     //IF the customer ID is empty then use the payment to get the email info
     if (empty($customer->id)) {
         // Remove the post title to get just the email
         $title = $license->post_title;
         $title_pos = strpos($title, '-') + 1;
         $length = strlen($title);
         $email_to = substr($title, $title_pos, $length);
     }
     //Get the email.
     $customer_email = !empty($customer->id) ? $customer->email : $email_to;
     $customer_name = !empty($customer->id) ? $customer->name : null;
     //default to null
     //                $payment_id = get_post_meta( $license_id, '_edd_sl_payment_id', true );
     //                $user_info  = edd_get_payment_meta_user_info( $payment_id );
     //                $user_id    = edd_get_payment_user_id( $payment_id );
     //
     //                // Retrieve the customer name
     //                if ( $user_id ) {
     //                    $user_data     = get_userdata( $user_id );
     //                    $customer_name = $user_data->display_name;
     //                } elseif ( isset( $user_info['first_name'] ) ) {
     //                    $customer_name = $user_info['first_name'];
     //                } else {
     //                    $customer_name = $user_info['email'];
     //                }
     //These are custom fields on customer
     $license_key = edd_software_licensing()->get_license_key($license_id);
     $download_id = get_post_meta($license_id, '_edd_sl_download_id', true);
     $product_name = get_the_title($download_id);
     $expiration = edd_software_licensing()->get_license_expiration($license_id);
     $expiration = date(get_option('date_format'), $expiration);
     $discount_percent = edd_sl_get_renewal_discount_percentage($license_id);
     $renewal_link = apply_filters('edd_sl_renewal_link', edd_get_checkout_uri(array('edd_license_key' => $license_key, 'download_id' => $download_id)));
     //Fire the event
     error_log('FIRE DRIP EVENT:' . $period . '-' . $license_id);
     error_log($customer_name);
     error_log($license_key);
     error_log($product_name);
     error_log($expiration);
     error_log($discount_percent);
     error_log($renewal_link);
     return true;
     $text = str_replace('{name}', $customer_name, $text);
     $text = str_replace('{license_key}', $license_key, $text);
     $text = str_replace('{product_name}', $product_name, $text);
     $text = str_replace('{expiration}', $expiration, $text);
     if (!empty($discount)) {
         $text = str_replace('{renewal_discount}', $discount . '%', $text);
     }
     $text = str_replace('{renewal_link}', $renewal_link, $text);
     return $text;
     return false;
     //            $message    = $this->filter_reminder_template_tags( $message, $license_id );
     //
     //            $subject    = ! empty( $notice['subject'] ) ? $notice['subject'] : __( 'Your License Key is About to Expire', 'edd_sl' );
     //            $subject    = $this->filter_reminder_template_tags( $subject, $license_id );
     if ($sent) {
         $log_id = wp_insert_post(array('post_title' => __('LOG - Renewal Drip Event Fired', 'edd_sl'), 'post_name' => 'log-notice-sent-' . $license_id . '-' . md5(time()), 'post_type' => 'edd_license_log', 'post_status' => 'publish'));
         //'_edd_drip_sl_renewal_sent_
         add_post_meta($log_id, '_edd_sl_log_license_id', $license_id);
         add_post_meta($log_id, '_edd_sl_renewal_notice_id', (int) $notice_id);
         wp_set_object_terms($log_id, 'renewal_notice', 'edd_log_type', false);
         add_post_meta($license_id, sanitize_key('_edd_drip_sl_renewal_sent_' . $notice['send_period']), time());
         // Prevent renewal notices from being sent more than once
     }
 }
 /**
  * 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;
 }
<?php

$payment_id = absint($_GET['payment_id']);
$license_id = absint($_GET['license_id']);
$download_id = absint(edd_software_licensing()->get_download_id($license_id));
$upgrades = edd_sl_get_license_upgrades($license_id);
$user_id = get_post_meta($license_id, '_edd_sl_user_id', true);
if (!current_user_can('edit_shop_payments') && $user_id != get_current_user_id()) {
    return;
}
$color = edd_get_option('checkout_color', 'gray');
$color = $color == 'inherit' ? '' : $color;
?>
<p><a href="<?php 
echo esc_url(remove_query_arg(array('view', 'license_id', 'edd_sl_error', '_wpnonce')));
?>
" class="edd-manage-license-back edd-submit button <?php 
echo esc_attr($color);
?>
"><?php 
_e('Go back', 'edd_sl');
?>
</a></p>
<?php 
edd_sl_show_errors();
?>
<table id="edd_sl_license_upgrades" class="edd_sl_table">
	<thead>
		<tr class="edd_sl_license_row">
			<?php 
do_action('edd_sl_license_upgrades_header_before');