Exemplo n.º 1
0
/**
 * Removes a product update email completely. Does NOT move to trash.
 * 
 * @access public
 * @param mixed $data
 * @return void
 */
function edd_pup_delete_email($data)
{
    if (!wp_verify_nonce($data['_wpnonce'], 'edd-pup-delete-nonce')) {
        return;
    }
    // Clear instances of this email in the queue
    if (false !== edd_pup_check_queue($data['id'])) {
        global $wpdb;
        $wpdb->delete("{$wpdb->edd_pup_queue}", array('email_id' => $data['id']), array('%d'));
    }
    $goodbye = wp_delete_post($data['id'], true);
    if (false === $goodbye || empty($goodbye)) {
        wp_redirect(esc_url_raw(add_query_arg('edd_pup_notice', 4, admin_url('edit.php?post_type=download&page=edd-prod-updates'))));
    } else {
        wp_redirect(esc_url_raw(add_query_arg('edd_pup_notice', 5, admin_url('edit.php?post_type=download&page=edd-prod-updates'))));
    }
    exit;
}
Exemplo n.º 2
0
/**
 * Generates HTML for the "View Details" popup on emails in queue alert
 * 
 * @access public
 * @return void
 */
function edd_pup_queue_details()
{
    global $edd_options;
    $email_list = edd_pup_emails_processing();
    $n = count($email_list['queued']);
    $dateformat = get_option('date_format') . ' ' . get_option('time_format');
    ?>
		<div id="edd-pup-queue-details-wrap" style="display:none;">
		<div id="edd-pup-queue-details">
		<h2><?php 
    _e('Product Updates Email Queue', 'edd-pup');
    ?>
</h2>
		<p><?php 
    _e('The emails listed below have not finished sending. Please choose whether to finish sending them now or to clear the queue. ', 'edd-pup');
    if (empty($edd_options['edd_pup_auto_del'])) {
        printf(__('Emails are automatically cleared from the queue after 48 hours (<a href="%s">Disable this on the settings page</a>.)', 'edd-pup'), admin_url('edit.php?post_type=download&page=edd-settings&tab=emails#edd_pup_settings'));
    }
    ?>
</p>
		<?php 
    foreach ($email_list['queued'] as $email) {
        $queue = edd_pup_check_queue($email);
        $i = 1;
        $email_data = get_post_custom($email);
        $subject = isset($email_data['_edd_pup_subject'][0]) ? $email_data['_edd_pup_subject'][0] : '<em>Unable to find subject</em>';
        ?>
				<div id="edd-pup-queue-email-<?php 
        echo $i;
        ?>
" class="edd-pup-queue-email">
						<ul>
							<li><strong><?php 
        _e('Email ID:', 'edd-pup');
        ?>
</strong> <?php 
        echo $email;
        ?>
</li>
							<li><strong><?php 
        _e('Subject:', 'edd-pup');
        ?>
</strong> <?php 
        echo $subject;
        ?>
</li>
							<li><strong><?php 
        _e('Total Recipients:', 'edd-pup');
        ?>
</strong> <?php 
        echo number_format($queue['total']);
        ?>
</li>
							<li><strong><?php 
        _e('Processed:', 'edd-pup');
        ?>
</strong> <?php 
        echo number_format($queue['sent']);
        ?>
</li>
							<li><strong><?php 
        _e('Queued:', 'edd-pup');
        ?>
</strong> <?php 
        echo number_format($queue['queue']);
        ?>
</li>
							<li><strong><?php 
        _e('Last Send Attempt:', 'edd-pup');
        ?>
</strong> <?php 
        echo mysql2date($dateformat, strtotime($queue['date']));
        ?>
</li>
							<li><a href="<?php 
        echo admin_url('edit.php?post_type=download&page=edd-prod-updates&view=view_pup_email&id=' . $email);
        ?>
"><?php 
        _e('View Email Details', 'edd-pup');
        ?>
</a></li>				
						</ul>
						<?php 
        if ($n >= 1) {
            ?>
						<div class="button primary-button edd-pup-queue-button" data-url="<?php 
            echo add_query_arg(array('view' => 'send_pup_ajax', 'id' => $email, 'restart' => 1), admin_url('edit.php?post_type=download&page=edd-prod-updates'));
            ?>
" data-action="edd_pup_send_queue" data-email="<?php 
            echo $email;
            ?>
"><?php 
            _e('Send Remaining Emails', 'edd-pup');
            ?>
</div>
						<div class="button primary-button edd-pup-queue-button" data-action="edd_pup_clear_queue" data-email="<?php 
            echo $email;
            ?>
" data-nonce="<?php 
            echo wp_create_nonce('clear-queue-' . $email);
            ?>
"><?php 
            _e('Clear From Queue', 'edd-pup');
            ?>
</div>
						<?php 
        }
        ?>
					</div><!-- end #edd-pup-queue-email-<?php 
        echo $i;
        ?>
 -->
		<?php 
    }
    ?>
			<div id="edd-pup-queue-buttons">
				<?php 
    if ($n > 1) {
        ?>
				<!--<input type="submit" name="edd-pup-send-queue-all" id="edd-pup-send-queue-all" class="button button-primary edd-pup-queue-button" value="<?php 
        _e('Send All Emails', 'edd-pup');
        ?>
" data-email="all" data-action="edd_pup_send_queue">-->
				<input type="submit" name="edd-pup-empty-queue-all" id="edd-pup-empty-queue-all" class="button button-primary edd-pup-queue-button" value="<?php 
        _e('Clear All From Queue', 'edd-pup');
        ?>
" data-email="all" data-action="edd_pup_clear_queue" data-nonce="<?php 
        echo wp_create_nonce('clear-queue-all');
        ?>
">
				<?php 
    }
    ?>
				<button class="closebutton button button-secondary"><?php 
    _e('Close Window', 'edd-pup');
    ?>
</button>
			</div><!-- end #edd-pup-queue-buttons -->
		</div><!-- end #edd-pup-queue-details -->
	</div><!-- end #edd-pup-queue-details-wrap -->
<?php 
}
/**
 * Determines whether a specified email is currently being sent or not
 * 
 * @access public
 * @param mixed $emailid (default: null)
 * @return bool true if email is processing, false if not
 */
function edd_pup_is_processing($emailid = null)
{
    if (empty($emailid)) {
        return;
    }
    $email_list = edd_pup_emails_processing();
    if (is_array($email_list['processing']) && in_array($emailid, $email_list['processing'])) {
        $totals = edd_pup_check_queue($emailid);
        if ($totals['queue'] > 0) {
            return true;
        }
    } else {
        return false;
    }
}
 /**
  * Process the bulk actions
  * @access public
  * @since 0.9.3
  * @return void
  */
 public function process_bulk_action()
 {
     if (empty($_REQUEST['_wpnonce'])) {
         return;
     }
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-emails')) {
         return;
     }
     $ids = isset($_GET['email']) ? $_GET['email'] : false;
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     foreach ($ids as $id) {
         if ('delete' === $this->current_action()) {
             // Clear instances of this email in the queue
             if (false !== edd_pup_check_queue($id)) {
                 global $wpdb;
                 $wpdb->delete("{$wpdb->edd_pup_queue}", array('email_id' => $id), array('%d'));
             }
             // Delete the email
             $goodbye = wp_delete_post($id, true);
         }
     }
 }
 /**
  * Checks the email queue every day for emails older than 48 hours and clears them.
  * 
  * @access public
  * @return void
  * @since 0.9.3.1
  */
 function edd_pup_cron_clear()
 {
     global $edd_options;
     if (!isset($edd_options['edd_pup_auto_del'])) {
         global $wpdb;
         $emails = $wpdb->get_results("SELECT DISTINCT email_id FROM {$wpdb->edd_pup_queue} WHERE sent = 0 AND HOUR( TIMEDIFF( NOW(), sent_date)) >= 48", ARRAY_A);
         if (!empty($emails)) {
             foreach ($emails as $email) {
                 $recipients = edd_pup_check_queue($email['email_id']);
                 $query = $wpdb->delete("{$wpdb->edd_pup_queue}", array('email_id' => $email['email_id']), array('%d'));
                 if (is_numeric($query)) {
                     $post = wp_update_post(array('ID' => $email['email_id'], 'post_status' => 'abandoned'));
                     update_post_meta($post, '_edd_pup_recipients', $recipients);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
/**
 * Determines whether an AJAX send is from the queue (a restart)
 * or fresh (no previous attempts to send).
 * 
 * @access public
 * @param mixed $emailid (default: null)
 * @return mixed array of queue totals if it's a restart, false if not a restart
 */
function edd_pup_is_ajax_restart($emailid = null)
{
    if (empty($emailid)) {
        return;
    }
    $queue = edd_pup_check_queue($emailid);
    if ($queue['queue'] > 0) {
        return $queue;
    } else {
        return false;
    }
}
if (!defined('ABSPATH')) {
    exit;
}
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    wp_die(__('Something went wrong.', 'edd-pup'), __('Error', 'edd-pup'));
}
global $edd_options;
$bundle = 0;
$user = get_current_user_id();
$email_id = absint($_GET['id']);
$email = get_post($email_id);
$emailmeta = get_post_custom($email_id);
$updated_products = get_post_meta($email_id, '_edd_pup_updated_products', TRUE);
$recipients = get_post_meta($email_id, '_edd_pup_recipients', TRUE);
$filters = isset($emailmeta['_edd_pup_filters'][0]) ? maybe_unserialize($emailmeta['_edd_pup_filters'][0]) : null;
$queue = edd_pup_check_queue($email_id);
$processing = edd_pup_is_processing($email_id) ? true : false;
$dateformat = get_option('date_format') . ' ' . get_option('time_format');
$baseurl = admin_url('edit.php?post_type=download&page=edd-prod-updates');
$restarturl = add_query_arg(array('view' => 'send_pup_ajax', 'id' => $email_id, 'restart' => 1), admin_url('edit.php?post_type=download&page=edd-prod-updates'));
$duplicateurl = wp_nonce_url(add_query_arg(array('edd_action' => 'pup_duplicate_email', 'id' => $email_id, 'redirect' => 1), $baseurl), 'edd-pup-duplicate-nonce');
// Find if any products were bundles
foreach ($updated_products as $prod_id => $prod_name) {
    if (edd_is_bundled_product($prod_id)) {
        $bundle++;
    }
}
switch (strtolower($email->post_status)) {
    case 'publish':
        $status = __('Sent', 'edd-pup');
        break;