Exemplo n.º 1
0
 /**
  * Send email to $mail_to.
  *
  * @param AB_Notification $notification
  * @param AB_NotificationCodes $codes
  * @param string $mail_to
  * @param string $phone
  * @return bool
  */
 private static function _send(AB_Notification $notification, AB_NotificationCodes $codes, $mail_to, $phone = '')
 {
     $result = false;
     if ($notification->get('gateway') == 'email') {
         $message = $codes->replace($notification->get('message'));
         // Send email to recipient.
         $subject = $codes->replace($notification->get('subject'));
         $result = wp_mail($mail_to, $subject, wpautop($message), AB_Utils::getEmailHeaders());
         // Send copy to administrators.
         if ($notification->get('copy')) {
             $admin_emails = AB_Utils::getAdminEmails();
             if (!empty($admin_emails)) {
                 wp_mail($admin_emails, $subject, wpautop($message), AB_Utils::getEmailHeaders());
             }
         }
     } elseif ($notification->get('gateway') == 'sms') {
         $message = $codes->replace($notification->get('message'), 'sms');
         if (self::$sms_authorized === null) {
             self::$sms = new AB_SMS();
             self::$sms_authorized = self::$sms->loadProfile();
         }
         if (self::$sms_authorized) {
             if ($phone != '') {
                 $result = self::$sms->sendSms($phone, $message);
             }
             if ($notification->get('copy')) {
                 if ($administrator_phone = get_option('ab_sms_administrator_phone', '') != '') {
                     self::$sms->sendSms($administrator_phone, $message);
                 }
             }
         }
     }
     return $result;
 }