PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.1.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.1.1
4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Notifications / Notifications.php
wp-staging / Notifications Last commit date
Interfaces 1 year ago Transporter 1 year ago Notifications.php 1 year ago NotificationsProvider.php 1 year ago
Notifications.php
102 lines
1 <?php
2
3 namespace WPStaging\Notifications;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Notifications\NotificationsProvider;
7
8 class Notifications
9 {
10 /**
11 * @var string
12 */
13 const OPTION_BACKUP_SCHEDULE_REPORT_EMAIL = 'wpstg_backup_schedules_report_email';
14
15 /**
16 * @var bool
17 */
18 const DISABLE_FOOTER_MESSAGE = false;
19
20 /**
21 * @var bool
22 */
23 const ENABLE_FOOTER_MESSAGE = true;
24
25 /**
26 * @var object
27 */
28 private $transporter;
29
30 /**
31 * @var NotificationsProvider
32 */
33 private $notificationProvider;
34
35 /**
36 * @param NotificationsProvider $notificationProvider
37 */
38 public function __construct(NotificationsProvider $notificationProvider)
39 {
40 $this->notificationProvider = $notificationProvider;
41 $this->getTransporter();
42 }
43
44 /**
45 * @return void
46 */
47 private function getTransporter()
48 {
49 $providers = $this->notificationProvider->getProviders();
50
51 $this->transporter = new \stdClass();
52 foreach ($providers as $provider) {
53 $providerName = lcfirst(basename(str_replace('\\', '/', $provider)));
54 $this->transporter->{$providerName} = WPStaging::make($provider);
55 }
56 }
57
58 /**
59 * @param string $to Recipient
60 * @param string $subject Subject
61 * @param string $message Content
62 * @param string $from (Optional) Sender
63 * @param array $attachments (Optional) Attachments
64 * @param bool $isAddFooterMessage (Optional) Enable footer message
65 * @return bool
66 */
67 public function sendEmail(string $to, string $subject, string $message, string $from = '', array $attachments = [], bool $isAddFooterMessage = self::ENABLE_FOOTER_MESSAGE): bool
68 {
69 if (empty($this->transporter->emailNotification) || !is_object($this->transporter->emailNotification)) {
70 return false;
71 }
72
73 $this->transporter->emailNotification->setSender($from)
74 ->setRecipient($to)
75 ->setSubject($subject)
76 ->setAttachment($attachments)
77 ->setIsAddFooterMessage($isAddFooterMessage);
78
79 return $this->transporter->emailNotification->send($message);
80 }
81
82 /**
83 * @param string $webhook Slack Webhook
84 * @param string $title title
85 * @param string $message Content
86 * @param bool $isAddFooterMessage (Optional) Enable footer message
87 * @return bool
88 */
89 public function sendSlack(string $webhook, string $title, string $message, bool $isAddFooterMessage = self::ENABLE_FOOTER_MESSAGE): bool
90 {
91 if (empty($this->transporter->slackNotification) || !is_object($this->transporter->slackNotification)) {
92 return false;
93 }
94
95 $this->transporter->slackNotification->setWebhook($webhook)
96 ->setTitle($title)
97 ->setIsAddFooterMessage($isAddFooterMessage);
98
99 return $this->transporter->slackNotification->send($message);
100 }
101 }
102