PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 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 day ago Transporter 1 day ago Notifications.php 1 day ago NotificationsProvider.php 1 day ago
Notifications.php
136 lines
1 <?php
2
3 namespace WPStaging\Notifications;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\TemplateEngine\TemplateEngine;
7 use WPStaging\Notifications\NotificationsProvider;
8 use WPStaging\Notifications\Transporter\EmailTemplateBuilder;
9
10 class Notifications
11 {
12
13
14
15 const OPTION_BACKUP_SCHEDULE_REPORT_EMAIL = 'wpstg_backup_schedules_report_email';
16
17
18
19
20 const DISABLE_FOOTER_MESSAGE = false;
21
22
23
24
25 const ENABLE_FOOTER_MESSAGE = true;
26
27
28
29
30 const OPTION_SEND_EMAIL_AS_HTML = 'wpstg_send_email_as_html';
31
32
33
34
35 private $transporter;
36
37
38
39
40 private $notificationProvider;
41
42
43
44
45 public function __construct(NotificationsProvider $notificationProvider)
46 {
47 $this->notificationProvider = $notificationProvider;
48 $this->getTransporter();
49 }
50
51
52
53
54 private function getTransporter()
55 {
56 $providers = $this->notificationProvider->getProviders();
57
58 $this->transporter = new \stdClass();
59 foreach ($providers as $provider) {
60 $providerName = lcfirst(basename(str_replace('\\', '/', $provider)));
61 $this->transporter->{$providerName} = WPStaging::make($provider);
62 }
63 }
64
65
66
67
68
69
70
71
72
73
74 public function sendEmail(string $to, string $subject, string $message, string $from = '', array $attachments = [], bool $isAddFooterMessage = self::ENABLE_FOOTER_MESSAGE): bool
75 {
76 if (empty($this->transporter->emailNotification) || !is_object($this->transporter->emailNotification)) {
77 return false;
78 }
79
80 $this->transporter->emailNotification->setSender($from)
81 ->setRecipient($to)
82 ->setSubject($subject)
83 ->setAttachment($attachments)
84 ->setIsAddFooterMessage($isAddFooterMessage);
85
86 return $this->transporter->emailNotification->send($message);
87 }
88
89
90
91
92
93
94
95
96 public function sendSlack(string $webhook, string $title, string $message, bool $isAddFooterMessage = self::ENABLE_FOOTER_MESSAGE): bool
97 {
98 if (empty($this->transporter->slackNotification) || !is_object($this->transporter->slackNotification)) {
99 return false;
100 }
101
102 $this->transporter->slackNotification->setWebhook($webhook)
103 ->setTitle($title)
104 ->setIsAddFooterMessage($isAddFooterMessage);
105
106 return $this->transporter->slackNotification->send($message);
107 }
108
109
110
111
112
113
114
115
116
117
118 public function sendEmailAsHTML(string $to, string $subject, string $message = '', string $from = '', array $details = [], array $attachments = []): bool
119 {
120 if (empty($this->transporter->emailNotification) || !is_object($this->transporter->emailNotification)) {
121 return false;
122 }
123
124 $this->transporter->emailNotification->setUseHtml(true);
125 $templateEngine = WPStaging::make(TemplateEngine::class);
126 $emailTemplate = EmailTemplateBuilder::create($templateEngine)
127 ->setTitle($subject)
128 ->setRecipient($to)
129 ->setMessage($message)
130 ->setDetails($details)
131 ->generate();
132
133 return $this->sendEmail($to, $subject, $emailTemplate, $from, $attachments, false);
134 }
135 }
136