예제 #1
0
 /**
  * Process bulk actions
  *
  * @access      private
  * @since       1.0
  * @return      void
  */
 function process_bulk_action()
 {
     if (empty($_REQUEST['_wpnonce'])) {
         return;
     }
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-licenses') && !wp_verify_nonce($_REQUEST['_wpnonce'], 'edd_sl_key_nonce')) {
         return;
     }
     $ids = isset($_GET['license']) ? $_GET['license'] : false;
     if (!$ids) {
         return;
     }
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     foreach ($ids as $id) {
         // Detect when a bulk action is being triggered...
         if ('deactivate' === $this->current_action()) {
             edd_software_licensing()->set_license_status($id, 'inactive');
         }
         if ('activate' === $this->current_action()) {
             edd_software_licensing()->set_license_status($id, 'active');
         }
         if ('enable' === $this->current_action()) {
             wp_update_post(array('ID' => $id, 'post_status' => 'publish'));
         }
         if ('disable' === $this->current_action()) {
             wp_update_post(array('ID' => $id, 'post_status' => 'draft'));
         }
         if ('renew' === $this->current_action()) {
             $license = get_post($id);
             // Don't bulk renew child licenses
             if (empty($license->post_parent)) {
                 edd_software_licensing()->renew_license($id);
             }
         }
         if ('renewal_notice' === $this->current_action()) {
             $license = get_post($id);
             if (empty($license->post_parent)) {
                 $emails = new EDD_SL_Emails();
                 if ('expired' == edd_software_licensing()->get_license_status($id)) {
                     $notices = edd_sl_get_renewal_notices();
                     $send_notice_id = 0;
                     foreach ($notices as $notice_id => $notice) {
                         if ('expired' === $notice['send_period']) {
                             $send_notice_id = $notice_id;
                             break;
                         }
                     }
                     $emails->send_renewal_reminder($id, $send_notice_id);
                 } else {
                     $emails->send_renewal_reminder($id);
                 }
             }
         }
         if ('delete' === $this->current_action()) {
             wp_delete_post($id);
         }
     }
     set_transient('_edd_sl_bulk_actions_redirect', 1, 1000);
 }
예제 #2
0
 function set_license_status($license_id, $status = 'active')
 {
     if (empty($license_id)) {
         return;
     }
     $current_status = get_post_meta($license_id, '_edd_sl_status', true);
     if (strtolower($current_status) === strtolower($status)) {
         return;
         // Statuses are the same
     }
     do_action('edd_sl_pre_set_status', $license_id, $status);
     update_post_meta($license_id, '_edd_sl_status', $status);
     if ('expired' == $status) {
         // Determine if we should send an email when a license key is marked as expired
         $notice_on_expired = false;
         $notices = edd_sl_get_renewal_notices();
         foreach ($notices as $key => $notice) {
             if ('expired' == $notice['send_period']) {
                 $edd_sl_emails = new EDD_SL_Emails();
                 $edd_sl_emails->send_renewal_reminder($license_id, $key);
             }
         }
     }
     // Update status for child licenses.
     $args = array('post_type' => 'edd_license', 'post_parent' => $license_id, 'posts_per_page' => 1000, 'post_status' => 'any', 'fields' => 'ids');
     $child_licenses = get_posts($args);
     foreach ($child_licenses as $child_id) {
         self::set_license_status($child_id, $status);
     }
     do_action('edd_sl_post_set_status', $license_id, $status);
 }
예제 #3
0
function edd_sl_scheduled_reminders()
{
    global $edd_options;
    if (!isset($edd_options['edd_sl_send_renewal_reminders'])) {
        return;
    }
    $edd_sl_emails = new EDD_SL_Emails();
    $notices = edd_sl_get_renewal_notices();
    foreach ($notices as $notice_id => $notice) {
        if ('expired' == $notice['send_period']) {
            continue;
            // Expired notices are triggered from the set_license_status() method of EDD_Software_Licensing
        }
        $keys = edd_sl_get_expiring_licenses($notice['send_period']);
        if (!$keys) {
            continue;
        }
        foreach ($keys as $license_id) {
            if (!apply_filters('edd_sl_send_scheduled_reminder_for_license', true, $license_id, $notice_id)) {
                continue;
            }
            $sent_time = get_post_meta($license_id, sanitize_key('_edd_sl_renewal_sent_' . $notice['send_period']), true);
            if ($sent_time) {
                $expire_date = strtotime($notice['send_period'], $sent_time);
                if (time() < $expire_date) {
                    // The renewal period isn't expired yet so don't send again
                    continue;
                }
                delete_post_meta($license_id, sanitize_key('_edd_sl_renewal_sent_' . $notice['send_period']));
            }
            $edd_sl_emails->send_renewal_reminder($license_id, $notice_id);
        }
    }
}