PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.5.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.5.2
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 4.5.2, at includes/class-updraft-email-logger.php

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