Пример #1
0
 /**
  * On post publish
  *
  * @param $post
  * @return mixed
  */
 public function onPublish($post)
 {
     if ($post) {
         $subcribers = $this->subscribers->getAllActiveEmails();
         $postDigest = $this->getPostDigestBody($post);
         try {
             $this->sendEmail($subcribers, $postDigest->subject, $postDigest->data);
             // log success message
             $this->log->add(1, 'Digest successfully sent to ' . count($subcribers) . ' subscribers. Post ID: ' . $post->ID);
         } catch (EmailException $e) {
             // log error
             $this->log->add(0, $e->getMessage());
         }
     } else {
         // log error
         $this->log->add(0, 'Digest not sent - no post included. Removed maybe?');
     }
 }
Пример #2
0
 /**
  * What shall we do, what shall we do? :D
  *
  * @param $post
  */
 public function onPublish($post)
 {
     // settings
     $timing = $this->settings->getTiming();
     $inCategory = $this->settings->inCategory($post);
     if ($post->post_type == 'post' && $inCategory) {
         switch ($timing) {
             case 1:
                 \SimpleSubscribe\Cron::scheduleCron(Utils::NINE_AM, $post->ID);
                 $this->log->add(1, 'Cron scheduled, 9AM for Post ID: ' . $post->ID);
                 break;
             case 2:
                 \SimpleSubscribe\Cron::scheduleCron(Utils::NINE_PM, $post->ID);
                 $this->log->add(1, 'Cron scheduled, 9PM for Post ID: ' . $post->ID);
                 break;
             case 0:
             default:
                 $this->email->onPublish($post);
                 break;
         }
     }
 }