PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.10.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.10.0
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
97 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 bool
12 */
13 const DISABLE_FOOTER_MESSAGE = false;
14
15 /**
16 * @var bool
17 */
18 const ENABLE_FOOTER_MESSAGE = true;
19
20 /**
21 * @var object
22 */
23 private $transporter;
24
25 /**
26 * @var NotificationsProvider
27 */
28 private $notificationProvider;
29
30 /**
31 * @param NotificationsProvider $notificationProvider
32 */
33 public function __construct(NotificationsProvider $notificationProvider)
34 {
35 $this->notificationProvider = $notificationProvider;
36 $this->getTransporter();
37 }
38
39 /**
40 * @return void
41 */
42 private function getTransporter()
43 {
44 $providers = $this->notificationProvider->getProviders();
45
46 $this->transporter = new \stdClass();
47 foreach ($providers as $provider) {
48 $providerName = lcfirst(basename(str_replace('\\', '/', $provider)));
49 $this->transporter->{$providerName} = WPStaging::make($provider);
50 }
51 }
52
53 /**
54 * @param string $to Recipient
55 * @param string $subject Subject
56 * @param string $message Content
57 * @param string $from (Optional) Sender
58 * @param array $attachments (Optional) Attachments
59 * @param bool $isAddFooterMessage (Optional) Enable footer message
60 * @return bool
61 */
62 public function sendEmail(string $to, string $subject, string $message, string $from = '', array $attachments = [], bool $isAddFooterMessage = self::ENABLE_FOOTER_MESSAGE): bool
63 {
64 if (empty($this->transporter->emailNotification) || !is_object($this->transporter->emailNotification)) {
65 return false;
66 }
67
68 $this->transporter->emailNotification->setSender($from)
69 ->setRecipient($to)
70 ->setSubject($subject)
71 ->setAttachment($attachments)
72 ->setIsAddFooterMessage($isAddFooterMessage);
73
74 return $this->transporter->emailNotification->send($message);
75 }
76
77 /**
78 * @param string $webhook Slack Webhook
79 * @param string $title title
80 * @param string $message Content
81 * @param bool $isAddFooterMessage (Optional) Enable footer message
82 * @return bool
83 */
84 public function sendSlack(string $webhook, string $title, string $message, bool $isAddFooterMessage = self::ENABLE_FOOTER_MESSAGE): bool
85 {
86 if (empty($this->transporter->slackNotification) || !is_object($this->transporter->slackNotification)) {
87 return false;
88 }
89
90 $this->transporter->slackNotification->setWebhook($webhook)
91 ->setTitle($title)
92 ->setIsAddFooterMessage($isAddFooterMessage);
93
94 return $this->transporter->slackNotification->send($message);
95 }
96 }
97