PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.7.1
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.7.1
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 / WPMailInitiator.php
wp-mail-smtp / src Last commit date
Admin 6 months ago Compatibility 6 months ago Helpers 6 months ago Providers 6 months ago Queue 6 months ago Reports 6 months ago Tasks 6 months ago UsageTracking 6 months ago AbstractConnection.php 6 months ago Conflicts.php 6 months ago Connect.php 6 months ago Connection.php 6 months ago ConnectionInterface.php 6 months ago ConnectionsManager.php 6 months ago Core.php 6 months ago DBRepair.php 6 months ago Debug.php 6 months ago Geo.php 6 months ago MailCatcher.php 6 months ago MailCatcherInterface.php 6 months ago MailCatcherTrait.php 6 months ago MailCatcherV6.php 6 months ago Migration.php 6 months ago MigrationAbstract.php 6 months ago Migrations.php 6 months ago OptimizedEmailSending.php 6 months ago Options.php 6 months ago Processor.php 6 months ago SiteHealth.php 6 months ago Upgrade.php 6 months ago Uploads.php 6 months ago WP.php 6 months ago WPMailArgs.php 6 months ago WPMailInitiator.php 6 months ago
WPMailInitiator.php
272 lines
1 <?php
2
3 namespace WPMailSMTP;
4
5 /**
6 * The `wp_mail` function initiator. It has centralized initiator data that can be used across all processes.
7 *
8 * @since 3.7.0
9 */
10 class WPMailInitiator {
11
12 /**
13 * The path where the `wp_mail` function was called.
14 *
15 * @since 3.7.0
16 *
17 * @var string
18 */
19 private $file;
20
21 /**
22 * Line in the file where the `wp_mail` function was called.
23 *
24 * @since 3.7.0
25 *
26 * @var int
27 */
28 private $line;
29
30 /**
31 * The `wp_mail` function call backtrace.
32 *
33 * @since 3.7.0
34 *
35 * @var array
36 */
37 private $backtrace;
38
39 /**
40 * Initiator name (plugin or theme name).
41 *
42 * @since 3.7.0
43 *
44 * @var string
45 */
46 private $name;
47
48 /**
49 * Initiator type. Available options: plugin, mu-plugin, theme, wp-core, unknown.
50 *
51 * @since 3.7.0
52 *
53 * @var string
54 */
55 private $type;
56
57 /**
58 * Initiator slug (plugin or theme slug).
59 *
60 * @since 3.7.0
61 *
62 * @var string
63 */
64 private $slug;
65
66 /**
67 * Whether performance-costly properties were initialized.
68 *
69 * @since 3.7.0
70 *
71 * @var array
72 */
73 private $initialized = false;
74
75 /**
76 * Register hooks.
77 *
78 * @since 3.7.0
79 */
80 public function hooks() {
81
82 // Capture `wp_mail` function call.
83 add_action( 'wp_mail_smtp_processor_capture_wp_mail_call', [ $this, 'capture_wp_mail_call' ], 0 );
84 }
85
86 /**
87 * Capture `wp_mail` function call.
88 *
89 * @since 4.0.0
90 */
91 public function capture_wp_mail_call() {
92
93 $this->set_initiator();
94 }
95
96 /**
97 * Get the path where the `wp_mail` function was called.
98 *
99 * @since 3.7.0
100 *
101 * @return string
102 */
103 public function get_file() {
104
105 return $this->file;
106 }
107
108 /**
109 * Get the line in the file where the `wp_mail` function was called.
110 *
111 * @since 3.7.0
112 *
113 * @return int
114 */
115 public function get_line() {
116
117 return $this->line;
118 }
119
120 /**
121 * Get the `wp_mail` function call backtrace.
122 *
123 * @since 3.7.0
124 *
125 * @return array
126 */
127 public function get_backtrace() {
128
129 return $this->backtrace;
130 }
131
132 /**
133 * Get the initiator name (plugin or theme name).
134 *
135 * @since 3.7.0
136 *
137 * @return string
138 */
139 public function get_name() {
140
141 $this->lazy_init();
142
143 return $this->name;
144 }
145
146 /**
147 * Get the initiator type. Available options: plugin, mu-plugin, theme, wp-core, unknown.
148 *
149 * @since 3.7.0
150 *
151 * @return string
152 */
153 public function get_type() {
154
155 $this->lazy_init();
156
157 return $this->type;
158 }
159
160 /**
161 * Get the initiator slug (plugin or theme slug).
162 *
163 * @since 3.7.0
164 *
165 * @return string
166 */
167 public function get_slug() {
168
169 $this->lazy_init();
170
171 return $this->slug;
172 }
173
174 /**
175 * Initialize initiator data.
176 *
177 * @since 3.7.0
178 */
179 public function set_initiator() {
180
181 // Reset previous values.
182 $this->reset();
183
184 $backtrace = $this->get_wpmail_backtrace();
185
186 /**
187 * Filter the `wp_mail` function initiator data.
188 *
189 * @since 4.0.0
190 *
191 * @param array $backtrace Backtrace data.
192 */
193 $backtrace = apply_filters( 'wp_mail_smtp_wp_mail_initiator_set_initiator', $backtrace );
194
195 if ( empty( $backtrace['file'] ) ) {
196 return;
197 }
198
199 $this->file = $backtrace['file'];
200 $this->backtrace = $backtrace['backtrace'];
201
202 if ( ! empty( $backtrace['line'] ) ) {
203 $this->line = $backtrace['line'];
204 }
205 }
206
207 /**
208 * Initialize performance-costly properties.
209 *
210 * @since 3.7.0
211 */
212 private function lazy_init() {
213
214 if ( empty( $this->file ) || $this->initialized ) {
215 return;
216 }
217
218 $data = WP::get_initiator( $this->file );
219
220 $this->name = $data['name'];
221 $this->type = $data['type'];
222
223 if ( isset( $data['slug'] ) ) {
224 $this->slug = $data['slug'];
225 }
226
227 $this->initialized = true;
228 }
229
230 /**
231 * Reset previous initiator data before the new email sending.
232 *
233 * @since 3.7.0
234 */
235 private function reset() {
236
237 $this->initialized = false;
238 $this->file = null;
239 $this->line = null;
240 $this->backtrace = null;
241 $this->name = null;
242 $this->type = null;
243 $this->slug = null;
244 }
245
246 /**
247 * Get the `wp_mail` function backtrace data, if it exists.
248 *
249 * @since 3.7.0
250 *
251 * @return array
252 */
253 private function get_wpmail_backtrace() {
254
255 $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
256
257 foreach ( $backtrace as $i => $item ) {
258 if ( $item['function'] === 'wp_mail' ) {
259 if ( isset( $item['function'] ) ) {
260 unset( $item['function'] );
261 }
262
263 $item['backtrace'] = array_slice( $backtrace, $i );
264
265 return $item;
266 }
267 }
268
269 return [];
270 }
271 }
272