PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.21
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.21
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / includes / class-updraft-email-logger.php

class-updraft-email-logger.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.21, at includes/class-updraft-email-logger.php

199 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access allowed');
4
5 if (class_exists('Updraft_Email_Logger')) return;
6
7 /**
8 * Class Updraft_Email_Logger
9 */
10 class Updraft_Email_Logger extends Updraft_Abstract_Logger {
11
12 protected $allow_multiple = true;
13
14 /**
15 * Updraft_Email_Logger constructor
16 */
17 public function __construct() {
18 }
19
20 /**
21 * Returns logger description
22 *
23 * @return string
24 */
25 public function get_description() {
26 return __('Log events to email', 'wp-optimize');
27 }
28
29 /**
30 * Returns list of logger options.
31 *
32 * @return array
33 */
34 public function get_options_list() {
35 return array(
36 'emails' => array(
37 __('Enter email for logs here', 'wp-optimize'),
38 'email', // validator
39 )
40 );
41 }
42
43 /**
44 * Emergency message
45 *
46 * @param string $message
47 * @param array $context
48 * @return null|void
49 */
50 public function emergency($message, array $context = array()) {
51 $this->log($message, Updraft_Log_Levels::EMERGENCY, $context);
52 }
53
54 /**
55 * Alert message
56 *
57 * @param string $message
58 * @param array $context
59 * @return null|void
60 */
61 public function alert($message, array $context = array()) {
62 $this->log($message, Updraft_Log_Levels::ALERT, $context);
63 }
64
65 /**
66 * Critical message
67 *
68 * @param string $message
69 * @param array $context
70 * @return null|void
71 */
72 public function critical($message, array $context = array()) {
73 $this->log($message, Updraft_Log_Levels::CRITICAL, $context);
74 }
75
76 /**
77 * Error message
78 *
79 * @param string $message
80 * @param array $context
81 * @return null|void
82 */
83 public function error($message, array $context = array()) {
84 $this->log($message, Updraft_Log_Levels::ERROR, $context);
85 }
86
87 /**
88 * Warning message
89 *
90 * @param string $message
91 * @param array $context
92 * @return null|void
93 */
94 public function warning($message, array $context = array()) {
95 $this->log($message, Updraft_Log_Levels::WARNING, $context);
96 }
97
98 /**
99 * Notice message
100 *
101 * @param string $message
102 * @param array $context
103 * @return null|void
104 */
105 public function notice($message, array $context = array()) {
106 $this->log($message, Updraft_Log_Levels::NOTICE, $context);
107 }
108
109 /**
110 * Info message
111 *
112 * @param string $message
113 * @param array $context
114 * @return null|void
115 */
116 public function info($message, array $context = array()) {
117 $this->log($message, Updraft_Log_Levels::INFO, $context);
118 }
119
120 /**
121 * Debug message
122 *
123 * @param string $message
124 * @param array $context
125 * @return null|void
126 */
127 public function debug($message, array $context = array()) {
128 $this->log($message, Updraft_Log_Levels::DEBUG, $context);
129 }
130
131 /**
132 * Log message with any level
133 *
134 * @param string $message
135 * @param mixed $level
136 * @param array $context
137 * @return null|void
138 */
139 public function log($message, $level, array $context = array()) {
140
141 if (!$this->is_enabled()) return false;
142
143 $log = WP_Optimize()->get_options()->get_option('updraft_mail_logger_log', array());
144
145 $message = '['.Updraft_Log_Levels::to_text($level).'] : '.$this->interpolate($message, $context);
146
147 $log[] = $message;
148 WP_Optimize()->get_options()->update_option('updraft_mail_logger_log', $log);
149 }
150
151 /**
152 * Add recipient email
153 *
154 * @param string $email
155 */
156 public function add_email($email) {
157 $emails = $this->get_option('emails', array());
158 $emails[] = $email;
159 $this->set_option('emails', $emails);
160 }
161
162 /**
163 * Return list of recipients email
164 *
165 * @return null
166 */
167 public function get_emails() {
168 return $this->get_option('emails', get_option('admin_email'));
169 }
170
171 /**
172 * Email and clear log
173 */
174 public function flush_log() {
175 $log = $this->get_log();
176 if (empty($log)) return;
177
178 WP_Optimize()->get_options()->update_option('updraft_mail_logger_log', array());
179
180 if (!$this->is_enabled()) return;
181
182 $email_addresses = $this->get_emails();
183 $subject = $this->get_option('updraft_mail_logger_subject', 'Updraft Email Log');
184
185 $log = join("\n", $log);
186
187 wp_mail($email_addresses, $subject, $log);
188 }
189
190 /**
191 * Return log messages
192 *
193 * @return mixed|void
194 */
195 public function get_log() {
196 return WP_Optimize()->get_options()->get_option('updraft_mail_logger_log', array());
197 }
198 }
199