PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.3.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.3.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / src / Debug.php
wp-mail-smtp / src Last commit date
Admin 1 year ago Compatibility 1 year ago Helpers 1 year ago Providers 1 year ago Queue 1 year ago Reports 1 year ago Tasks 1 year ago UsageTracking 1 year ago AbstractConnection.php 1 year ago Conflicts.php 1 year ago Connect.php 1 year ago Connection.php 1 year ago ConnectionInterface.php 1 year ago ConnectionsManager.php 1 year ago Core.php 1 year ago DBRepair.php 1 year ago Debug.php 1 year ago Geo.php 1 year ago MailCatcher.php 1 year ago MailCatcherInterface.php 1 year ago MailCatcherTrait.php 1 year ago MailCatcherV6.php 1 year ago Migration.php 1 year ago MigrationAbstract.php 1 year ago Migrations.php 1 year ago OptimizedEmailSending.php 1 year ago Options.php 1 year ago Processor.php 1 year ago SiteHealth.php 1 year ago Upgrade.php 1 year ago Uploads.php 1 year ago WP.php 1 year ago WPMailArgs.php 1 year ago WPMailInitiator.php 1 year ago
Debug.php
200 lines
1 <?php
2
3 namespace WPMailSMTP;
4
5 use WPMailSMTP\Admin\DebugEvents\DebugEvents;
6
7 /**
8 * Class Debug that will save all errors or warnings generated by APIs or SMTP
9 * and display in area for administrators.
10 *
11 * Usage example:
12 * Debug::set( 'Some warning: %s', array( '%s' => $e->getMessage() );
13 * $debug = Debug::get(); // array
14 * $debug = Debug::get_last(); // string
15 *
16 * @since 1.2.0
17 */
18 class Debug {
19
20 /**
21 * Key for options table where all messages will be saved to.
22 *
23 * @since 1.2.0
24 */
25 const OPTION_KEY = 'wp_mail_smtp_debug';
26
27 /**
28 * Hold the cached error messages.
29 *
30 * @since 3.0.0
31 *
32 * @var array
33 */
34 private static $cached_messages;
35
36 /**
37 * Save unique debug message to a debug log.
38 * Adds one more to a list, at the end.
39 *
40 * @since 1.2.0
41 * @since 3.0.0 Start saving the Debug Event IDs, instead of error messages.
42 * @since 3.5.0 Returns Event ID.
43 *
44 * @param mixed $message An array or string error message.
45 *
46 * @return bool|int
47 */
48 public static function set( $message ) {
49
50 if ( empty( $message ) ) {
51 return false;
52 }
53
54 self::clear_cache();
55
56 // Log the error message to the Debug Events.
57 $event_id = DebugEvents::add( $message );
58
59 $all = self::get_raw();
60
61 if ( ! empty( $event_id ) ) {
62 array_push( $all, $event_id );
63 } else {
64 if ( ! is_string( $message ) ) {
65 $message = wp_json_encode( $message );
66 } else {
67 $message = wp_strip_all_tags( $message, false );
68 }
69
70 array_push( $all, $message );
71 }
72
73 update_option( self::OPTION_KEY, array_unique( $all ), false );
74
75 return $event_id;
76 }
77
78 /**
79 * Remove all messages for a debug log.
80 *
81 * @since 1.2.0
82 */
83 public static function clear() {
84
85 self::clear_cache();
86
87 update_option( self::OPTION_KEY, [], false );
88 }
89
90 /**
91 * Clear cached error messages.
92 *
93 * @since 3.0.0
94 */
95 private static function clear_cache() {
96
97 self::$cached_messages = null;
98 }
99
100 /**
101 * Get the raw DB debug option values.
102 *
103 * @since 3.0.0
104 */
105 private static function get_raw() {
106
107 $all = get_option( self::OPTION_KEY, [] );
108
109 if ( ! is_array( $all ) ) {
110 $all = (array) $all;
111 }
112
113 return $all;
114 }
115
116 /**
117 * Retrieve all messages from a debug log.
118 *
119 * @since 1.2.0
120 *
121 * @return array
122 */
123 public static function get() {
124
125 if ( isset( self::$cached_messages ) ) {
126 return self::$cached_messages;
127 }
128
129 $all = self::get_raw();
130
131 if ( empty( $all ) ) {
132 self::$cached_messages = [];
133
134 return [];
135 }
136
137 $event_ids = [];
138 $old_messages = [];
139
140 foreach ( $all as $item ) {
141 if ( is_int( $item ) ) {
142 $event_ids[] = (int) $item;
143 } else {
144 $old_messages[] = $item;
145 }
146 }
147
148 $event_messages = DebugEvents::get_debug_messages( $event_ids );
149 self::$cached_messages = array_unique( array_merge( $old_messages, $event_messages ) );
150
151 return self::$cached_messages;
152 }
153
154 /**
155 * Get the last message that was saved to a debug log.
156 *
157 * @since 1.2.0
158 *
159 * @return string
160 */
161 public static function get_last() {
162
163 $all = self::get();
164
165 if ( ! empty( $all ) && is_array( $all ) ) {
166 return (string) end( $all );
167 }
168
169 return '';
170 }
171
172 /**
173 * Get the proper variable content output to debug.
174 *
175 * @since 1.2.0
176 *
177 * @param mixed $var Variable to output.
178 *
179 * @return string
180 */
181 public static function pvar( $var = '' ) {
182
183 ob_start();
184
185 echo '<code>';
186
187 if ( is_bool( $var ) || empty( $var ) ) {
188 var_dump( $var );
189 } else {
190 print_r( $var );
191 }
192
193 echo '</code>';
194
195 $output = ob_get_clean();
196
197 return str_replace( array( "\r\n", "\r", "\n" ), '', $output );
198 }
199 }
200