/** * Change a queue item's status and redirect the browser back to the scheduled emails page after */ public static function update_queue_item_status() { check_admin_referer('update_queue_status'); $scheduler = Follow_Up_Emails::instance()->scheduler; $item = new FUE_Sending_Queue_Item(absint($_GET['id'])); $item->status = absint($_GET['status']); $item->save(); if ($item->status == 1) { $scheduler->schedule_email($item->id, $item->send_on); } elseif ($item->status == 0) { $scheduler->unschedule_email($item->id); } $messages = array(__('Scheduled email updated successfully', 'follow_up_emails')); $message_nonce = wp_create_nonce(__FILE__); set_transient('_fue_messages_' . $message_nonce, array('messages' => $messages), 60 * 60); // redirect back to scheduled emails wp_redirect(add_query_arg('message', $message_nonce, 'admin.php?page=followup-emails-queue')); exit; }
/** * Validate the request by checking: * * 1) the ID is a valid integer * 2) the ID returns a valid queue item * 3) the current user has the proper permissions to read/edit/delete the object * * @since 4.1 * @param string|int $id the post ID * @param string $type Unused * @param string $context Unused * @return int|WP_Error valid post ID or WP_Error if any of the checks fails */ protected function validate_request($id, $type = null, $context = null) { $id = absint($id); // validate ID if (empty($id)) { return new WP_Error("fue_api_invalid_queue_id", __('Invalid Queue ID', 'follow_up_emails'), array('status' => 404)); } $item = new FUE_Sending_Queue_Item($id); // check that the resource exists if (!$item->exists()) { return new WP_Error('fue_api_invalid_queue_id', __('Invalid Queue ID', 'follow_up_emails'), array('status' => 404)); } if (!current_user_can('manage_follow_up_emails')) { return new WP_Error("fue_api_user_cannot_access_queue", __('You do not have permission to access this resource', 'follow_up_emails'), array('status' => 401)); } return $id; }
/** * Schedule an email for sending via action-scheduler * * @param int $queue_id * @param int $timestamp * @param bool $convert_to_gmt ActionScheduler uses GMT to schedule the events * @return void */ public function schedule_email($queue_id, $timestamp, $convert_to_gmt = true) { $param = $this->get_scheduler_parameters($queue_id); $local_timestamp = $timestamp; if ($convert_to_gmt) { // because ActionScheduler uses GMT for scheduling events, convert the send date to GMT $timestamp = strtotime(get_gmt_from_date(date('Y-m-d H:i:s', $timestamp))); } wc_schedule_single_action($timestamp, 'sfn_followup_emails', $param, 'fue'); $item = new FUE_Sending_Queue_Item($queue_id); $message = sprintf(__('Email is scheduled to be sent on %s', 'follow_up_emails'), date('Y-m-d H:i:s', $local_timestamp)); $item->add_note($message); }
<?php if (!defined('ABSPATH')) { exit; // Exit if accessed directly } $order_id = 0; $order_url = ''; $email_address = ''; $queue_id = ''; if (!empty($_GET['qid'])) { $queue_id = absint($_GET['qid']); $queue = new FUE_Sending_Queue_Item($queue_id); if ($queue->exists()) { $order_id = $queue->order_id; $order = WC_FUE_Compatibility::wc_get_order($order_id); $email_address = $queue->user_email; if (function_exists('wc_get_endpoint_url')) { $order_url = wc_get_endpoint_url('view-order', $order_id, wc_get_page_permalink('myaccount')); } else { $order_url = add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('view_order'))); } } } get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <article class="page type-page status-publish hentry"> <header class="entry-header">
<?php /** * Update Data to 7.5 * Look for queue items for subscription emails without subscription keys in the meta */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } global $wpdb; if (class_exists('WC_Subscriptions_Manager')) { $email_ids = fue_get_emails('subscription', '', array('fields' => 'ids')); if (count($email_ids)) { $item_ids = $wpdb->get_results("SELECT id FROM {$wpdb->prefix}followup_email_orders WHERE email_id IN (" . implode(',', $email_ids) . ")"); foreach ($item_ids as $item_id) { $item = new FUE_Sending_Queue_Item($item_id->id); if (empty($item->meta['subs_key']) && WC_Subscriptions_Order::order_contains_subscription($item->order_id)) { $subs_key = WC_Subscriptions_Manager::get_subscription_key($item->order_id); $item->meta['subs_key'] = $subs_key; $item->save(); } } } }