コード例 #1
0
 /**
  * Fires on a scheduled event. Responsible for determining if and which
  * reminders we should send.
  *
  * @since 1.0
  */
 public function on_schedule()
 {
     // stripe calls get_current_screen during this filter
     // this isn't provided during cron
     remove_filter('it_exchange_get_currencies', 'it_exchange_stripe_addon_get_currency_options');
     $notifications = $this->get_notifications();
     if (empty($notifications)) {
         return;
     }
     $queue = \ITELIC\get_queue_processor('itelic-renewal-reminder');
     $strategy = \ITELIC\get_notification_strategy();
     $queue->process($notifications, $strategy);
 }
コード例 #2
0
 /**
  * Handles the ajax callback for sending the notifications to outdated
  * customers.
  *
  * @since 1.0
  */
 public function send_notification()
 {
     if (!isset($_POST['release']) || !isset($_POST['subject']) || !isset($_POST['message']) || !isset($_POST['nonce'])) {
         return;
     }
     $release = intval($_POST['release']);
     $subject = sanitize_text_field($_POST['subject']);
     $message = wp_unslash($_POST['message']);
     $nonce = wp_unslash($_POST['nonce']);
     if (empty($subject)) {
         wp_send_json_error(array('message' => __("A subject is required. You want people to open this email, right?", Plugin::SLUG)));
     }
     if (empty($message)) {
         wp_send_json_error(array('message' => __("A message is required. What's an email without a body?", Plugin::SLUG)));
     }
     if (!wp_verify_nonce($nonce, "itelic-update-release-{$release}")) {
         wp_send_json_error(array('message' => __("Request expired. Please refresh and try again.", Plugin::SLUG)));
     }
     if (!current_user_can('manage_options')) {
         wp_send_json_error(array('message' => __("You don't have permission to do this.", Plugin::SLUG)));
     }
     $release = itelic_get_release($release);
     $notifications = $this->get_notifications($release, $message, $subject);
     if (empty($notifications)) {
         wp_send_json_error(array('message' => sprintf(__("All customers have already updated to version %s or later.", Plugin::SLUG), $release->get_version())));
     }
     try {
         $queue = \ITELIC\get_queue_processor('itelic-outdated-customers');
         $queue->process($notifications, \ITELIC\get_notification_strategy());
     } catch (\Exception $e) {
         wp_send_json_error(array('message' => $e->getMessage()));
     }
     wp_send_json_success(array('message' => sprintf(__("Notifications to %d customers have been queued for sending", Plugin::SLUG), count($notifications))));
 }