WP Mail SMTP by WPForms - Version 1.2.4

Version Description

  • 2018-01-28 =
  • Fixed: Improved escaping with debug reporting.
Download this release

Release Info

Developer slaFFik
Plugin Icon 128x128 WP Mail SMTP by WPForms
Version 1.2.4
Comparing to
See all releases

Code changes from version 1.2.3 to 1.2.4

class-wpms-am-notification.php CHANGED
@@ -1,450 +1,450 @@
1
- <?php
2
-
3
- /**
4
- * Awesome Motive Notifications
5
- *
6
- * This creates a custom post type (if it doesn't exist) and calls the API to
7
- * retrieve notifications for this product.
8
- *
9
- * @package AwesomeMotive
10
- * @author Benjamin Rojas
11
- * @license GPL-2.0+
12
- * @copyright Copyright (c) 2017, Retyp LLC
13
- * @version 1.0.2
14
- */
15
- class WPMS_AM_Notification {
16
- /**
17
- * The api url we are calling.
18
- *
19
- * @since 1.0.0
20
- *
21
- * @var string
22
- */
23
- public $api_url = 'https://api.awesomemotive.com/v1/notification/';
24
-
25
- /**
26
- * A unique slug for this plugin.
27
- * (Not the WordPress plugin slug)
28
- *
29
- * @since 1.0.0
30
- *
31
- * @var string
32
- */
33
- public $plugin;
34
-
35
- /**
36
- * The current plugin version.
37
- *
38
- * @since 1.0.0
39
- *
40
- * @var string
41
- */
42
- public $plugin_version;
43
-
44
- /**
45
- * Flag if a notice has been registered.
46
- *
47
- * @since 1.0.0
48
- *
49
- * @var bool
50
- */
51
- public static $registered = false;
52
-
53
- /**
54
- * Construct.
55
- *
56
- * @since 1.0.0
57
- *
58
- * @param string $plugin The plugin slug.
59
- * @param mixed $version The version of the plugin.
60
- */
61
- public function __construct( $plugin = '', $version = 0 ) {
62
- $this->plugin = $plugin;
63
- $this->plugin_version = $version;
64
-
65
- add_action( 'init', array( $this, 'custom_post_type' ) );
66
- add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
67
- add_action( 'admin_notices', array( $this, 'display_notifications' ) );
68
- add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
69
- }
70
-
71
- /**
72
- * Registers a custom post type.
73
- *
74
- * @since 1.0.0
75
- */
76
- public function custom_post_type() {
77
- register_post_type( 'amn_' . $this->plugin, array(
78
- 'label' => $this->plugin . ' Announcements',
79
- 'can_export' => false,
80
- 'supports' => false,
81
- ) );
82
- }
83
-
84
- /**
85
- * Retrieve the remote notifications if the time has expired.
86
- *
87
- * @since 1.0.0
88
- */
89
- public function get_remote_notifications() {
90
- if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
91
- return;
92
- }
93
-
94
- $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
95
-
96
- if ( $last_checked < strtotime( 'today midnight' ) ) {
97
- $plugin_notifications = $this->get_plugin_notifications( 1 );
98
- $notification_id = null;
99
-
100
- if ( ! empty( $plugin_notifications ) ) {
101
- // Unset it from the array.
102
- $notification = $plugin_notifications[0];
103
- $notification_id = get_post_meta( $notification->ID, 'notification_id', true );
104
- }
105
-
106
- $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
107
- 'body' => array(
108
- 'slug' => $this->plugin,
109
- 'version' => $this->plugin_version,
110
- 'last_notification' => $notification_id,
111
- ),
112
- ) ) );
113
-
114
- $data = json_decode( $response );
115
-
116
- if ( ! empty( $data->id ) ) {
117
- $notifications = array();
118
-
119
- foreach ( (array) $data->slugs as $slug ) {
120
- $notifications = array_merge(
121
- $notifications,
122
- (array) get_posts(
123
- array(
124
- 'post_type' => 'amn_' . $slug,
125
- 'post_status' => 'all',
126
- 'meta_key' => 'notification_id',
127
- 'meta_value' => $data->id,
128
- )
129
- )
130
- );
131
- }
132
-
133
- if ( empty( $notifications ) ) {
134
- $new_notification_id = wp_insert_post( array(
135
- 'post_content' => wp_kses_post( $data->content ),
136
- 'post_type' => 'amn_' . $this->plugin,
137
- ) );
138
-
139
- update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
140
- update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
141
- update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
142
- update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
143
- update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
144
- update_post_meta( $new_notification_id, 'viewed', 0 );
145
- update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
146
- update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
147
- }
148
- }
149
-
150
- // Possibly revoke notifications.
151
- if ( ! empty( $data->revoked ) ) {
152
- $this->revoke_notifications( $data->revoked );
153
- }
154
-
155
- // Set the option now so we can't run this again until after 24 hours.
156
- update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
157
- }
158
- }
159
-
160
- /**
161
- * Get local plugin notifications that have already been set.
162
- *
163
- * @since 1.0.0
164
- *
165
- * @param integer $limit Set the limit for how many posts to retrieve.
166
- * @param array $args Any top-level arguments to add to the array.
167
- *
168
- * @return WP_Post[] WP_Post that match the query.
169
- */
170
- public function get_plugin_notifications( $limit = -1, $args = array() ) {
171
- return get_posts(
172
- array(
173
- 'posts_per_page' => $limit,
174
- 'post_type' => 'amn_' . $this->plugin,
175
- ) + $args
176
- );
177
- }
178
-
179
- /**
180
- * Display any notifications that should be displayed.
181
- *
182
- * @since 1.0.0
183
- */
184
- public function display_notifications() {
185
- if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
186
- return;
187
- }
188
-
189
- $plugin_notifications = $this->get_plugin_notifications( -1, array(
190
- 'post_status' => 'all',
191
- 'meta_key' => 'viewed',
192
- 'meta_value' => '0',
193
- ) );
194
-
195
- $plugin_notifications = $this->validate_notifications( $plugin_notifications );
196
-
197
- if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
198
- foreach ( $plugin_notifications as $notification ) {
199
- $dismissable = get_post_meta( $notification->ID, 'dismissable', true );
200
- $type = get_post_meta( $notification->ID, 'type', true );
201
- ?>
202
- <div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
203
- <?php echo $notification->post_content; ?>
204
- </div>
205
- <script type="text/javascript">
206
- jQuery(document).ready(function ($) {
207
- $(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
208
- $.post(ajaxurl, {
209
- action: 'am_notification_dismiss',
210
- notification_id: '<?php echo $notification->ID; ?>'
211
- });
212
- });
213
- });
214
- </script>
215
- <?php
216
- }
217
-
218
- self::$registered = true;
219
- }
220
- }
221
-
222
- /**
223
- * Validate the notifications before displaying them.
224
- *
225
- * @since 1.0.0
226
- *
227
- * @param array $plugin_notifications An array of plugin notifications.
228
- *
229
- * @return array A filtered array of plugin notifications.
230
- */
231
- public function validate_notifications( $plugin_notifications ) {
232
- global $pagenow;
233
-
234
- foreach ( $plugin_notifications as $key => $notification ) {
235
- // Location validation.
236
- $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
237
- $continue = false;
238
- if ( ! in_array( 'everywhere', $location, true ) ) {
239
- if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
240
- $continue = true;
241
- }
242
-
243
- if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
244
- $continue = true;
245
- }
246
-
247
- if ( ! $continue ) {
248
- unset( $plugin_notifications[ $key ] );
249
- }
250
- }
251
-
252
- // Plugin validation (OR conditional).
253
- $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
254
- $continue = false;
255
- if ( ! empty( $plugins ) ) {
256
- foreach ( $plugins as $plugin ) {
257
- if ( is_plugin_active( $plugin ) ) {
258
- $continue = true;
259
- }
260
- }
261
-
262
- if ( ! $continue ) {
263
- unset( $plugin_notifications[ $key ] );
264
- }
265
- }
266
-
267
- // Theme validation.
268
- $theme = get_post_meta( $notification->ID, 'theme', true );
269
- $continue = (string) wp_get_theme() === $theme;
270
-
271
- if ( ! empty( $theme ) && ! $continue ) {
272
- unset( $plugin_notifications[ $key ] );
273
- }
274
-
275
- // Version validation.
276
- $version = get_post_meta( $notification->ID, 'version', true );
277
- $continue = false;
278
- if ( ! empty( $version ) ) {
279
- if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
280
- $continue = true;
281
- }
282
-
283
- if ( ! $continue ) {
284
- unset( $plugin_notifications[ $key ] );
285
- }
286
- }
287
-
288
- // Expiration validation.
289
- $expiration = get_post_meta( $notification->ID, 'expiration', true );
290
- $continue = false;
291
- if ( ! empty( $expiration ) ) {
292
- if ( $expiration > time() ) {
293
- $continue = true;
294
- }
295
-
296
- if ( ! $continue ) {
297
- unset( $plugin_notifications[ $key ] );
298
- }
299
- }
300
-
301
- // Plan validation.
302
- $plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
303
- $continue = false;
304
- if ( ! empty( $plans ) ) {
305
- $level = $this->get_plan_level();
306
- if ( in_array( $level, $plans, true ) ) {
307
- $continue = true;
308
- }
309
-
310
- if ( ! $continue ) {
311
- unset( $plugin_notifications[ $key ] );
312
- }
313
- }
314
- }
315
-
316
- return $plugin_notifications;
317
- }
318
-
319
- /**
320
- * Grab the current plan level.
321
- *
322
- * @since 1.0.0
323
- *
324
- * @return string The current plan level.
325
- */
326
- public function get_plan_level() {
327
- // Prepare variables.
328
- $key = '';
329
- $level = '';
330
- $option = false;
331
- switch ( $this->plugin ) {
332
- case 'wpforms' :
333
- $option = get_option( 'wpforms_license' );
334
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
335
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
336
-
337
- // Possibly check for a constant.
338
- if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
339
- $key = WPFORMS_LICENSE_KEY;
340
- }
341
- break;
342
- case 'mi' :
343
- $option = get_option( 'monsterinsights_license' );
344
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
345
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
346
-
347
- // Possibly check for a constant.
348
- if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
349
- $key = MONSTERINSIGHTS_LICENSE_KEY;
350
- }
351
- break;
352
- case 'sol' :
353
- $option = get_option( 'soliloquy' );
354
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
355
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
356
-
357
- // Possibly check for a constant.
358
- if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
359
- $key = SOLILOQUY_LICENSE_KEY;
360
- }
361
- break;
362
- case 'envira' :
363
- $option = get_option( 'envira_gallery' );
364
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
365
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
366
-
367
- // Possibly check for a constant.
368
- if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
369
- $key = ENVIRA_LICENSE_KEY;
370
- }
371
- break;
372
- case 'om' :
373
- $option = get_option( 'optin_monster_api' );
374
- $key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
375
-
376
- // Possibly check for a constant.
377
- if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
378
- $key = OPTINMONSTER_REST_API_LICENSE_KEY;
379
- }
380
-
381
- // If the key is still empty, check for the old legacy key.
382
- if ( empty( $key ) ) {
383
- $key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
384
- }
385
- break;
386
- }
387
-
388
- // Possibly set the level to 'none' if the key is empty and no level has been set.
389
- if ( empty( $key ) && empty( $level ) ) {
390
- $level = 'none';
391
- }
392
-
393
- // Normalize the level.
394
- switch ( $level ) {
395
- case 'bronze' :
396
- case 'personal' :
397
- $level = 'basic';
398
- break;
399
- case 'silver' :
400
- case 'multi' :
401
- $level = 'plus';
402
- break;
403
- case 'gold' :
404
- case 'developer' :
405
- $level = 'pro';
406
- break;
407
- case 'platinum' :
408
- case 'master' :
409
- $level = 'ultimate';
410
- break;
411
- }
412
-
413
- // Return the plan level.
414
- return $level;
415
- }
416
-
417
- /**
418
- * Dismiss the notification via AJAX.
419
- *
420
- * @since 1.0.0
421
- */
422
- public function dismiss_notification() {
423
- if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
424
- die;
425
- }
426
-
427
- $notification_id = intval( $_POST['notification_id'] );
428
- update_post_meta( $notification_id, 'viewed', 1 );
429
- die;
430
- }
431
-
432
- /**
433
- * Revokes notifications.
434
- *
435
- * @since 1.0.0
436
- *
437
- * @param array $ids An array of notification IDs to revoke.
438
- */
439
- public function revoke_notifications( $ids ) {
440
- // Loop through each of the IDs and find the post that has it as meta.
441
- foreach ( (array) $ids as $id ) {
442
- $notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
443
- if ( $notifications ) {
444
- foreach ( $notifications as $notification ) {
445
- update_post_meta( $notification->ID, 'viewed', 1 );
446
- }
447
- }
448
- }
449
- }
450
- }
1
+ <?php
2
+
3
+ /**
4
+ * Awesome Motive Notifications
5
+ *
6
+ * This creates a custom post type (if it doesn't exist) and calls the API to
7
+ * retrieve notifications for this product.
8
+ *
9
+ * @package AwesomeMotive
10
+ * @author Benjamin Rojas
11
+ * @license GPL-2.0+
12
+ * @copyright Copyright (c) 2017, Retyp LLC
13
+ * @version 1.0.2
14
+ */
15
+ class WPMS_AM_Notification {
16
+ /**
17
+ * The api url we are calling.
18
+ *
19
+ * @since 1.0.0
20
+ *
21
+ * @var string
22
+ */
23
+ public $api_url = 'https://api.awesomemotive.com/v1/notification/';
24
+
25
+ /**
26
+ * A unique slug for this plugin.
27
+ * (Not the WordPress plugin slug)
28
+ *
29
+ * @since 1.0.0
30
+ *
31
+ * @var string
32
+ */
33
+ public $plugin;
34
+
35
+ /**
36
+ * The current plugin version.
37
+ *
38
+ * @since 1.0.0
39
+ *
40
+ * @var string
41
+ */
42
+ public $plugin_version;
43
+
44
+ /**
45
+ * Flag if a notice has been registered.
46
+ *
47
+ * @since 1.0.0
48
+ *
49
+ * @var bool
50
+ */
51
+ public static $registered = false;
52
+
53
+ /**
54
+ * Construct.
55
+ *
56
+ * @since 1.0.0
57
+ *
58
+ * @param string $plugin The plugin slug.
59
+ * @param mixed $version The version of the plugin.
60
+ */
61
+ public function __construct( $plugin = '', $version = 0 ) {
62
+ $this->plugin = $plugin;
63
+ $this->plugin_version = $version;
64
+
65
+ add_action( 'init', array( $this, 'custom_post_type' ) );
66
+ add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
67
+ add_action( 'admin_notices', array( $this, 'display_notifications' ) );
68
+ add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
69
+ }
70
+
71
+ /**
72
+ * Registers a custom post type.
73
+ *
74
+ * @since 1.0.0
75
+ */
76
+ public function custom_post_type() {
77
+ register_post_type( 'amn_' . $this->plugin, array(
78
+ 'label' => $this->plugin . ' Announcements',
79
+ 'can_export' => false,
80
+ 'supports' => false,
81
+ ) );
82
+ }
83
+
84
+ /**
85
+ * Retrieve the remote notifications if the time has expired.
86
+ *
87
+ * @since 1.0.0
88
+ */
89
+ public function get_remote_notifications() {
90
+ if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
91
+ return;
92
+ }
93
+
94
+ $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
95
+
96
+ if ( $last_checked < strtotime( 'today midnight' ) ) {
97
+ $plugin_notifications = $this->get_plugin_notifications( 1 );
98
+ $notification_id = null;
99
+
100
+ if ( ! empty( $plugin_notifications ) ) {
101
+ // Unset it from the array.
102
+ $notification = $plugin_notifications[0];
103
+ $notification_id = get_post_meta( $notification->ID, 'notification_id', true );
104
+ }
105
+
106
+ $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
107
+ 'body' => array(
108
+ 'slug' => $this->plugin,
109
+ 'version' => $this->plugin_version,
110
+ 'last_notification' => $notification_id,
111
+ ),
112
+ ) ) );
113
+
114
+ $data = json_decode( $response );
115
+
116
+ if ( ! empty( $data->id ) ) {
117
+ $notifications = array();
118
+
119
+ foreach ( (array) $data->slugs as $slug ) {
120
+ $notifications = array_merge(
121
+ $notifications,
122
+ (array) get_posts(
123
+ array(
124
+ 'post_type' => 'amn_' . $slug,
125
+ 'post_status' => 'all',
126
+ 'meta_key' => 'notification_id',
127
+ 'meta_value' => $data->id,
128
+ )
129
+ )
130
+ );
131
+ }
132
+
133
+ if ( empty( $notifications ) ) {
134
+ $new_notification_id = wp_insert_post( array(
135
+ 'post_content' => wp_kses_post( $data->content ),
136
+ 'post_type' => 'amn_' . $this->plugin,
137
+ ) );
138
+
139
+ update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
140
+ update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
141
+ update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
142
+ update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
143
+ update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
144
+ update_post_meta( $new_notification_id, 'viewed', 0 );
145
+ update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
146
+ update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
147
+ }
148
+ }
149
+
150
+ // Possibly revoke notifications.
151
+ if ( ! empty( $data->revoked ) ) {
152
+ $this->revoke_notifications( $data->revoked );
153
+ }
154
+
155
+ // Set the option now so we can't run this again until after 24 hours.
156
+ update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Get local plugin notifications that have already been set.
162
+ *
163
+ * @since 1.0.0
164
+ *
165
+ * @param integer $limit Set the limit for how many posts to retrieve.
166
+ * @param array $args Any top-level arguments to add to the array.
167
+ *
168
+ * @return WP_Post[] WP_Post that match the query.
169
+ */
170
+ public function get_plugin_notifications( $limit = -1, $args = array() ) {
171
+ return get_posts(
172
+ array(
173
+ 'posts_per_page' => $limit,
174
+ 'post_type' => 'amn_' . $this->plugin,
175
+ ) + $args
176
+ );
177
+ }
178
+
179
+ /**
180
+ * Display any notifications that should be displayed.
181
+ *
182
+ * @since 1.0.0
183
+ */
184
+ public function display_notifications() {
185
+ if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
186
+ return;
187
+ }
188
+
189
+ $plugin_notifications = $this->get_plugin_notifications( -1, array(
190
+ 'post_status' => 'all',
191
+ 'meta_key' => 'viewed',
192
+ 'meta_value' => '0',
193
+ ) );
194
+
195
+ $plugin_notifications = $this->validate_notifications( $plugin_notifications );
196
+
197
+ if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
198
+ foreach ( $plugin_notifications as $notification ) {
199
+ $dismissable = get_post_meta( $notification->ID, 'dismissable', true );
200
+ $type = get_post_meta( $notification->ID, 'type', true );
201
+ ?>
202
+ <div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
203
+ <?php echo $notification->post_content; ?>
204
+ </div>
205
+ <script type="text/javascript">
206
+ jQuery(document).ready(function ($) {
207
+ $(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
208
+ $.post(ajaxurl, {
209
+ action: 'am_notification_dismiss',
210
+ notification_id: '<?php echo $notification->ID; ?>'
211
+ });
212
+ });
213
+ });
214
+ </script>
215
+ <?php
216
+ }
217
+
218
+ self::$registered = true;
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Validate the notifications before displaying them.
224
+ *
225
+ * @since 1.0.0
226
+ *
227
+ * @param array $plugin_notifications An array of plugin notifications.
228
+ *
229
+ * @return array A filtered array of plugin notifications.
230
+ */
231
+ public function validate_notifications( $plugin_notifications ) {
232
+ global $pagenow;
233
+
234
+ foreach ( $plugin_notifications as $key => $notification ) {
235
+ // Location validation.
236
+ $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
237
+ $continue = false;
238
+ if ( ! in_array( 'everywhere', $location, true ) ) {
239
+ if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
240
+ $continue = true;
241
+ }
242
+
243
+ if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
244
+ $continue = true;
245
+ }
246
+
247
+ if ( ! $continue ) {
248
+ unset( $plugin_notifications[ $key ] );
249
+ }
250
+ }
251
+
252
+ // Plugin validation (OR conditional).
253
+ $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
254
+ $continue = false;
255
+ if ( ! empty( $plugins ) ) {
256
+ foreach ( $plugins as $plugin ) {
257
+ if ( is_plugin_active( $plugin ) ) {
258
+ $continue = true;
259
+ }
260
+ }
261
+
262
+ if ( ! $continue ) {
263
+ unset( $plugin_notifications[ $key ] );
264
+ }
265
+ }
266
+
267
+ // Theme validation.
268
+ $theme = get_post_meta( $notification->ID, 'theme', true );
269
+ $continue = (string) wp_get_theme() === $theme;
270
+
271
+ if ( ! empty( $theme ) && ! $continue ) {
272
+ unset( $plugin_notifications[ $key ] );
273
+ }
274
+
275
+ // Version validation.
276
+ $version = get_post_meta( $notification->ID, 'version', true );
277
+ $continue = false;
278
+ if ( ! empty( $version ) ) {
279
+ if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
280
+ $continue = true;
281
+ }
282
+
283
+ if ( ! $continue ) {
284
+ unset( $plugin_notifications[ $key ] );
285
+ }
286
+ }
287
+
288
+ // Expiration validation.
289
+ $expiration = get_post_meta( $notification->ID, 'expiration', true );
290
+ $continue = false;
291
+ if ( ! empty( $expiration ) ) {
292
+ if ( $expiration > time() ) {
293
+ $continue = true;
294
+ }
295
+
296
+ if ( ! $continue ) {
297
+ unset( $plugin_notifications[ $key ] );
298
+ }
299
+ }
300
+
301
+ // Plan validation.
302
+ $plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
303
+ $continue = false;
304
+ if ( ! empty( $plans ) ) {
305
+ $level = $this->get_plan_level();
306
+ if ( in_array( $level, $plans, true ) ) {
307
+ $continue = true;
308
+ }
309
+
310
+ if ( ! $continue ) {
311
+ unset( $plugin_notifications[ $key ] );
312
+ }
313
+ }
314
+ }
315
+
316
+ return $plugin_notifications;
317
+ }
318
+
319
+ /**
320
+ * Grab the current plan level.
321
+ *
322
+ * @since 1.0.0
323
+ *
324
+ * @return string The current plan level.
325
+ */
326
+ public function get_plan_level() {
327
+ // Prepare variables.
328
+ $key = '';
329
+ $level = '';
330
+ $option = false;
331
+ switch ( $this->plugin ) {
332
+ case 'wpforms' :
333
+ $option = get_option( 'wpforms_license' );
334
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
335
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
336
+
337
+ // Possibly check for a constant.
338
+ if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
339
+ $key = WPFORMS_LICENSE_KEY;
340
+ }
341
+ break;
342
+ case 'mi' :
343
+ $option = get_option( 'monsterinsights_license' );
344
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
345
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
346
+
347
+ // Possibly check for a constant.
348
+ if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
349
+ $key = MONSTERINSIGHTS_LICENSE_KEY;
350
+ }
351
+ break;
352
+ case 'sol' :
353
+ $option = get_option( 'soliloquy' );
354
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
355
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
356
+
357
+ // Possibly check for a constant.
358
+ if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
359
+ $key = SOLILOQUY_LICENSE_KEY;
360
+ }
361
+ break;
362
+ case 'envira' :
363
+ $option = get_option( 'envira_gallery' );
364
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
365
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
366
+
367
+ // Possibly check for a constant.
368
+ if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
369
+ $key = ENVIRA_LICENSE_KEY;
370
+ }
371
+ break;
372
+ case 'om' :
373
+ $option = get_option( 'optin_monster_api' );
374
+ $key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
375
+
376
+ // Possibly check for a constant.
377
+ if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
378
+ $key = OPTINMONSTER_REST_API_LICENSE_KEY;
379
+ }
380
+
381
+ // If the key is still empty, check for the old legacy key.
382
+ if ( empty( $key ) ) {
383
+ $key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
384
+ }
385
+ break;
386
+ }
387
+
388
+ // Possibly set the level to 'none' if the key is empty and no level has been set.
389
+ if ( empty( $key ) && empty( $level ) ) {
390
+ $level = 'none';
391
+ }
392
+
393
+ // Normalize the level.
394
+ switch ( $level ) {
395
+ case 'bronze' :
396
+ case 'personal' :
397
+ $level = 'basic';
398
+ break;
399
+ case 'silver' :
400
+ case 'multi' :
401
+ $level = 'plus';
402
+ break;
403
+ case 'gold' :
404
+ case 'developer' :
405
+ $level = 'pro';
406
+ break;
407
+ case 'platinum' :
408
+ case 'master' :
409
+ $level = 'ultimate';
410
+ break;
411
+ }
412
+
413
+ // Return the plan level.
414
+ return $level;
415
+ }
416
+
417
+ /**
418
+ * Dismiss the notification via AJAX.
419
+ *
420
+ * @since 1.0.0
421
+ */
422
+ public function dismiss_notification() {
423
+ if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
424
+ die;
425
+ }
426
+
427
+ $notification_id = intval( $_POST['notification_id'] );
428
+ update_post_meta( $notification_id, 'viewed', 1 );
429
+ die;
430
+ }
431
+
432
+ /**
433
+ * Revokes notifications.
434
+ *
435
+ * @since 1.0.0
436
+ *
437
+ * @param array $ids An array of notification IDs to revoke.
438
+ */
439
+ public function revoke_notifications( $ids ) {
440
+ // Loop through each of the IDs and find the post that has it as meta.
441
+ foreach ( (array) $ids as $id ) {
442
+ $notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
443
+ if ( $notifications ) {
444
+ foreach ( $notifications as $notification ) {
445
+ update_post_meta( $notification->ID, 'viewed', 1 );
446
+ }
447
+ }
448
+ }
449
+ }
450
+ }
readme.txt CHANGED
@@ -1,348 +1,351 @@
1
- === WP Mail SMTP by WPForms ===
2
- Contributors: wpforms, jaredatch, smub, slaFFik
3
- Tags: smtp, wp mail smtp, wordpress smtp, gmail smtp, sendgrid smtp, mailgun smtp, mail, mailer, phpmailer, wp_mail, email, mailgun, sengrid, gmail, wp smtp
4
- Requires at least: 3.6
5
- Tested up to: 4.9
6
- Stable tag: trunk
7
- Requires PHP: 5.3
8
-
9
- The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 700k sites.
10
-
11
- == Description ==
12
-
13
- = WordPress Mail SMTP Plugin =
14
-
15
- Having problems with your WordPress site not sending emails? You're not alone. Over 700,000 websites use WP Mail SMTP to fix their email deliverability issues.
16
-
17
- WP Mail SMTP fixes your email deliverability by reconfiguring the wp_mail() PHP function to use a proper SMTP provider.
18
-
19
- = What is SMTP? =
20
-
21
- SMTP (Simple Mail Transfer Protocol) is an industry standard for sending emails. SMTP helps increase email deliverability by using proper authentication.
22
-
23
- Popular email clients like Gmail, Yahoo, Outlook, etc are constantly improving their services to reduce email spam. One of the things their spam tools look for is whether an email is originating from the location it claims to be originating from.
24
-
25
- If the proper authentication isn't there, then the emails either go in your SPAM folder or worst not get delivered at all.
26
-
27
- This is a problem for a lot of WordPress sites because by default, WordPress uses the PHP mail function to send emails generated by WordPress or any contact form plugin like <a href="https://wpforms.com/" rel="friend">WPForms</a>.
28
-
29
- The issue is that most <a href"http://www.wpbeginner.com/wordpress-hosting/" rel="friend">WordPress hosting companies</a> don't have their servers properly configured for sending PHP emails.
30
-
31
- The combination of two causes your WordPress emails to not get delivered.
32
-
33
- = How does WP Mail SMTP work? =
34
-
35
- WP Mail SMTP plugin allows you to easily reconfigure the wp_mail() function to use a trusted SMTP provider.
36
-
37
- This helps you fix all WordPress not sending email issues.
38
-
39
- WP Mail SMTP plugin includes four different SMTP setup options:
40
-
41
- 1. Mailgun SMTP
42
- 2. SendGrid SMTP
43
- 3. Gmail SMTP
44
- 4. All Other SMTP
45
-
46
- For all options, you can specify the "from name" and "email address" for outgoing emails.
47
-
48
- Instead of having users use different SMTP plugins and workflows for different SMTP providers, we decided to bring it all in one. This is what makes WP Mail SMTP, the best SMTP solution for WordPress.
49
-
50
- = Mailgun SMTP =
51
-
52
- Mailgun SMTP is a popular SMTP service provider that allows you to send large quantities of emails. They allow you to send your first 10,000 emails for free every month.
53
-
54
- WP Mail SMTP plugin offers a native integration with MailGun. All you have to do is connect your Mailgun account, and you will improve your email deliverability.
55
-
56
- Read our <a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" rel="friend">Mailgun documentation</a> for more details.
57
-
58
- = Gmail SMTP =
59
-
60
- Often bloggers and small business owners don't want to use third-party SMTP services. Well you can use your Gmail or G Suite account for SMTP emails.
61
-
62
- This allows you to use your <a href="http://www.wpbeginner.com/beginners-guide/how-to-setup-a-professional-email-address-with-gmail-and-google-apps/" rel="friend">professional email address</a> and improve email deliverability.
63
-
64
- Unlike other Gmail SMTP plugins, our Gmail SMTP option uses OAuth to authenticate your Google account, keeping your login information 100% secure.
65
-
66
- Read our <a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" rel="friend">Gmail documentation</a> for more details.
67
-
68
- = SendGrid SMTP =
69
-
70
- SendGrid has a free SMTP plan that you can use to send up to 100 emails per day. With our native SendGrid SMTP integration, you can easily and securely set up SendGrid SMTP on your WordPress site.
71
-
72
- Read our <a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" rel="friend">SendGrid documentation</a> for more details.
73
-
74
- = Other SMTP =
75
-
76
- WP Mail SMTP plugin also works with all major email services such as Gmail, Yahoo, Outlook, Microsoft Live, and any other email sending service that offers SMTP.
77
-
78
- You can set the following options:
79
-
80
- * Specify an SMTP host.
81
- * Specify an SMTP port.
82
- * Choose SSL / TLS encryption.
83
- * Choose to use SMTP authentication or not.
84
- * Specify an SMTP username and password.
85
-
86
- WP Mail SMTP also gives you the option to insert your password in your wp-config.php file, so it's not visible in your WordPress settings.
87
-
88
- To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">SMTP documentation</a>.
89
-
90
- We hope that you find WP Mail SMTP plugin helpful.
91
-
92
- = Credits =
93
-
94
- WP Mail SMTP plugin was originally created by Callum Macdonald. It is now owned and maintained by the team behind <a href="https://wpforms.com/" rel="friend">WPForms</a> - the best drag & drop form builder for WordPress.
95
-
96
- You can try the <a href="https://wordpress.org/plugins/wpforms-lite/" rel="friend">free version of WPForms plugin</a> to see why it's the best in the market.
97
-
98
- = What's Next =
99
-
100
- If you like this plugin, then please consider checking out our other popular plugins:
101
-
102
- * <a href="http://optinmonster.com/" rel="friend" title="OptinMonster">OptinMonster</a> - Get More Email Subscribers
103
- * <a href="https://www.monsterinsights.com/" rel="friend" title="MonsterInsights">MonsterInsights</a> - Best Google Analytics Plugin for WordPress
104
-
105
- Visit <a href="http://www.wpbeginner.com/" rel="friend" title="WPBeginner">WPBeginner</a> to learn from our <a href="http://www.wpbeginner.com/category/wp-tutorials/" rel="friend" title="WordPress Tutorials">WordPress Tutorials</a> and find out about other <a href="http://www.wpbeginner.com/category/plugins/" rel="friend" title="Best WordPress Plugins">best WordPress plugins</a>.
106
-
107
- == Installation ==
108
-
109
- 1. Install WP Mail SMTP by WPForms either via the WordPress.org plugin repository or by uploading the files to your server. (See instructions on <a href="http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/" rel="friend">how to install a WordPress plugin</a>)
110
- 2. Activate WP Mail SMTP by WPForms.
111
- 3. Navigate to the Settings area of WP Mail SMTP in the WordPress admin.
112
- 4. Choose your SMTP option (Mailgun SMTP, SendGrid SMTP, Gmail SMTP, or Other SMTP) and follow the instructions to set it up.
113
- 5. Want to support us? Consider trying <a href="https://wpforms.com/?utm_source=wprepo&utm_medium=link&utm_campaign=liteversion" rel="friend" title="WPForms">WPForms Pro</a> - the best WordPress contact form plugin!
114
-
115
- == Frequently Asked Questions ==
116
-
117
- = Can I use this plugin to send email via Gmail, G Suite, Outlook.com, Office 365, Hotmail, Yahoo, or AOL SMTP? =
118
-
119
- Yes! We have extensive documentation that covers setting up SMTP most popular email services.
120
-
121
- <a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">Read our docs</a> to see the correct SMTP settings for each service.
122
-
123
- = Help! I need support or have an issue. =
124
-
125
- Please read <a href="https://wordpress.org/support/topic/wp-mail-smtp-support-policy/">our support policy</a> for more information.
126
-
127
- = I found a bug, now what? =
128
-
129
- If you've stumbled upon a bug, the best place to report it is in the <a href="https://github.com/awesomemotive/wp-mail-smtp">WP Mail SMTP GitHub repository</a>. GitHub is where the plugin is actively developed, and posting there will get your issue quickly seen by our developers (myself and Slava). Once posted, we'll review your bug report and triage the bug. When creating an issue, the more details you can add to your report, the faster the bug can be solved.
130
-
131
- = Can you add feature x, y or z to the plugin? =
132
-
133
- Short answer: maybe.
134
-
135
- By all means please contact us to discuss features or options you'd like to see added to the plugin. We can't guarantee to add all of them, but we will consider all sensible requests. We can be contacted here:
136
- <a href="https://wpforms.com/contact/" rel="friend">https://wpforms.com/contact/</a>
137
-
138
- == Screenshots ==
139
-
140
- 1. WP Mail SMTP Settings page
141
- 2. Gmail / G Suite settings
142
- 3. Mailgun settings
143
- 4. SendGrid settings
144
- 5. SMTP settings
145
- 6. Send a Test Email
146
-
147
- == Changelog ==
148
-
149
- = 1.2.3 - 2018-01-22 =
150
- * Fixed: Gmail tokens were reset after clicking Save Settings.
151
- * Fixed: Slight typo in Gmail success message.
152
-
153
- = 1.2.2 - 2017-12-27 =
154
- * Fixed: Correctly handle Mailgun debug message for an incorrect api key.
155
- * Fixed: Fatal error for Gmail and SMTP mailers with Nginx web-server (without Apache at all).
156
- * Changed: Update X-Mailer emails header to show the real sender with a mailer and plugin version.
157
-
158
- = 1.2.1 - 2017-12-21 =
159
- * Fixed: Failed SMTP connections generate fatal errors.
160
-
161
- = 1.2.0 - 2017-12-21 =
162
- * Fixed: Decrease the factual minimum WordPress version from 3.9 to 3.6.
163
- * Changed: Improve debug output for all mail providers.
164
-
165
- = 1.1.0 - 2017-12-18 =
166
- * Added: New option "Auto TLS" for SMTP mailer. Default is enabled. Migration routine for all sites.
167
- * Changed: Improve debug output - clear styles and context-aware content.
168
- * Changed: Better exceptions handling for Google authentication process.
169
- * Changed: Do not sanitize passwords, api keys etc - as they may contain special characters in certain order and sanitization will break those values.
170
- * Changed: Improve wording of some helpful texts inside plugin admin area.
171
- * Fixed: Do not include certain files in dependency libraries that are not used by Google mailer. This should stop flagging plugin by Wordfence and VaultPress.
172
- * Fixed: Constants usage is working now, to define the SMTP password, for example.
173
- * Fixed: Notice for default mailer.
174
-
175
- = 1.0.2 - 2017-12-12 =
176
- * Fixed: PHPMailer using incorrect SMTPSecure value.
177
-
178
- = 1.0.1 - 2017-12-12 =
179
- * Fixed: Global POST processing conflict.
180
-
181
- = 1.0.0 - 2017-12-12 =
182
- * Added: Automatic migration tool to move options from older storage format to a new one.
183
- * Added: Added Gmail & G Suite email provider integration - without your email and password.
184
- * Added: Added SendGrid email provider integration - using the API key only.
185
- * Added: Added Mailgun email provider integration - using the API key and configured domain only.
186
- * Added: New compatibility mode - for PHP 5.2 old plugin will be loaded, for PHP 5.3 and higher - new version of admin area and new functionality.
187
- * Changed: The new look of the admin area.
188
- * Changed: SMTP password field now has "password" type.
189
- * Changed: SMTP password field does not display real password at all when using constants in `wp-config.php` to define it.
190
- * Changed: Escape properly all translations.
191
- * Changed: More helpful test email content (with a mailer name).
192
-
193
- = 0.11.2 - 2017-11-28 =
194
- * Added: Setting to hide announcement feed.
195
- * Changed: Announcement feed data.
196
-
197
- = 0.11.1 - 2017-10-30 =
198
- * Fixed: Older PHP compatibility fix.
199
-
200
- = 0.11 - 2017-10-30 =
201
- * Added: Helper description to Return Path option.
202
- * Added: Filter `wp_mail_smtp_admin_test_email_smtp_debug` to increase the debug message verbosity.
203
- * Added: PHP 5.2 notice.
204
- * Added: Announcement feed.
205
- * Changed: Localization fixes, proper locale name.
206
- * Changed: Code style improvements and optimizations for both HTML and PHP.
207
- * Changed: Inputs for emails now have a proper type `email`, instead of a generic `text`.
208
- * Changed: Turn off `$phpmailer->SMTPAutoTLS` when `No encryption` option is set to prevent error while sending emails.
209
- * Changed: Hide Pepipost for those who are not using it.
210
- * Changed: WP CLI support improved.
211
-
212
- = 0.10.1 =
213
- * Addition of Pepipost and cleanup of admin page.
214
-
215
- = 0.10.0 =
216
- * Addition of Pepipost and cleanup of admin page.
217
-
218
- = 0.9.6 =
219
- * Minor security fix, sanitize test email address.
220
-
221
- = 0.9.5 =
222
- * Minor security fix, hat tip JD Grimes.
223
-
224
- = 0.9.4 =
225
- * Improvement to the test email function, very low priority update.
226
-
227
- = 0.9.3 =
228
- * Fixing reported issue with passing by reference. props Adam Conway
229
-
230
- = 0.9.2 =
231
- * Removing the deprecation notice.
232
-
233
- = 0.9.1 =
234
- * $phpmailer->language became protected in WP 3.2, no longer unset on debug output.
235
-
236
- = 0.9.0 =
237
- * Typo in the From email description.
238
- * Removed changelog from plugin file, no need to duplicate it.
239
- * Optionally set $phpmailer->Sender from from email, helps with sendmail / mail().
240
-
241
- = 0.8.7 =
242
- * Fix for a long standing bug that caused an error during plugin activation.
243
-
244
- = 0.8.6 =
245
- * The Settings link really does work this time, promise. Apologies for the unnecessary updates.
246
-
247
- = 0.8.5 =
248
- * Bugfix, the settings link on the Plugin page was broken by 0.8.4.
249
-
250
- = 0.8.4 =
251
- * Minor bugfix, remove use of esc_html() to improve backwards compatibility.
252
- * Removed second options page menu props ovidiu.
253
-
254
- = 0.8.3 =
255
- * Bugfix, return WPMS_MAIL_FROM_NAME, props nacin.
256
- * Add Settings link, props Mike Challis http://profiles.wordpress.org/MikeChallis/
257
-
258
- = 0.8.2 =
259
- * Bugfix, call phpmailer_init_smtp() correctly, props Sinklar.
260
-
261
- = 0.8.1 =
262
- * Internationalisation improvements.
263
-
264
- = 0.8 =
265
- * Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
266
-
267
- = 0.7 =
268
- * Added checks to only override the default from name / email
269
-
270
- = 0.6 =
271
- * Added additional SMTP debugging output
272
-
273
- = 0.5.2 =
274
- * Fixed a pre 2.3 bug to do with mail from
275
-
276
- = 0.5.1 =
277
- * Added a check to display a warning on versions prior to 2.3
278
-
279
- = 0.5.0 =
280
- * Upgraded to match 2.3 filters which add a second filter for from name
281
-
282
- = 0.4.2 =
283
- * Fixed a bug in 0.4.1 and added more debugging output
284
-
285
- = 0.4.1 =
286
- * Added $phpmailer->ErroInfo to the test mail output
287
-
288
- = 0.4 =
289
- * Added the test email feature and cleaned up some other bits and pieces
290
-
291
- = 0.3.2 =
292
- * Changed to use register_activation_hook for greater compatability
293
-
294
- = 0.3.1 =
295
- * Added readme for WP-Plugins.org compatability
296
-
297
- = 0.3 =
298
- * Various bugfixes and added From options
299
-
300
- = 0.2 =
301
- * Reworked approach as suggested by westi, added options page
302
-
303
- = 0.1 =
304
- * Initial approach, copying the wp_mail function and replacing it
305
-
306
- == Upgrade Notice ==
307
-
308
- = 0.10.1 =
309
- Addition of Pepipost and cleanup of admin page.
310
-
311
- = 0.10.0 =
312
- Addition of Pepipost and cleanup of admin page.
313
-
314
- = 0.9.6 =
315
- Minor security fix, sanitize test email address.
316
-
317
- = 0.9.5 =
318
- Minor security fix, hat tip JD Grimes.
319
-
320
- = 0.9.4 =
321
- Improvement to the test email function, very low priority update.
322
-
323
- = 0.9.3 =
324
- Fixing reported issue with passing by reference.
325
-
326
- = 0.9.2 =
327
- Removing the deprecation notice.
328
-
329
- = 0.9.1 =
330
- Test mail functionality was broken on upgrade to 3.2, now restored.
331
-
332
- = 0.9.0 =
333
- Low priority upgrade. Improves the appearance of the options page.
334
-
335
- = 0.8.7 =
336
- Very low priority update. Fixes a bug that causes a spurious error during activation.
337
-
338
- = 0.8.6 =
339
- Low priority update. The Settings link was still broken in 0.8.5.
340
-
341
- = 0.8.5 =
342
- Minor bugfix correcting the Settings link bug introduced in 0.8.4. Very low priority update.
343
-
344
- = 0.8.4 =
345
- Minor bugfix for users using constants. Another very low priority upgrade. Apologies for the version creep.
346
-
347
- = 0.8.3 =
348
- Minor bugfix for users using constants. Very low priority upgrade.
 
 
 
1
+ === WP Mail SMTP by WPForms ===
2
+ Contributors: wpforms, jaredatch, smub, slaFFik
3
+ Tags: smtp, wp mail smtp, wordpress smtp, gmail smtp, sendgrid smtp, mailgun smtp, mail, mailer, phpmailer, wp_mail, email, mailgun, sengrid, gmail, wp smtp
4
+ Requires at least: 3.6
5
+ Tested up to: 4.9
6
+ Stable tag: trunk
7
+ Requires PHP: 5.3
8
+
9
+ The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 700k sites.
10
+
11
+ == Description ==
12
+
13
+ = WordPress Mail SMTP Plugin =
14
+
15
+ Having problems with your WordPress site not sending emails? You're not alone. Over 700,000 websites use WP Mail SMTP to fix their email deliverability issues.
16
+
17
+ WP Mail SMTP fixes your email deliverability by reconfiguring the wp_mail() PHP function to use a proper SMTP provider.
18
+
19
+ = What is SMTP? =
20
+
21
+ SMTP (Simple Mail Transfer Protocol) is an industry standard for sending emails. SMTP helps increase email deliverability by using proper authentication.
22
+
23
+ Popular email clients like Gmail, Yahoo, Outlook, etc are constantly improving their services to reduce email spam. One of the things their spam tools look for is whether an email is originating from the location it claims to be originating from.
24
+
25
+ If the proper authentication isn't there, then the emails either go in your SPAM folder or worst not get delivered at all.
26
+
27
+ This is a problem for a lot of WordPress sites because by default, WordPress uses the PHP mail function to send emails generated by WordPress or any contact form plugin like <a href="https://wpforms.com/" rel="friend">WPForms</a>.
28
+
29
+ The issue is that most <a href"http://www.wpbeginner.com/wordpress-hosting/" rel="friend">WordPress hosting companies</a> don't have their servers properly configured for sending PHP emails.
30
+
31
+ The combination of two causes your WordPress emails to not get delivered.
32
+
33
+ = How does WP Mail SMTP work? =
34
+
35
+ WP Mail SMTP plugin allows you to easily reconfigure the wp_mail() function to use a trusted SMTP provider.
36
+
37
+ This helps you fix all WordPress not sending email issues.
38
+
39
+ WP Mail SMTP plugin includes four different SMTP setup options:
40
+
41
+ 1. Mailgun SMTP
42
+ 2. SendGrid SMTP
43
+ 3. Gmail SMTP
44
+ 4. All Other SMTP
45
+
46
+ For all options, you can specify the "from name" and "email address" for outgoing emails.
47
+
48
+ Instead of having users use different SMTP plugins and workflows for different SMTP providers, we decided to bring it all in one. This is what makes WP Mail SMTP, the best SMTP solution for WordPress.
49
+
50
+ = Mailgun SMTP =
51
+
52
+ Mailgun SMTP is a popular SMTP service provider that allows you to send large quantities of emails. They allow you to send your first 10,000 emails for free every month.
53
+
54
+ WP Mail SMTP plugin offers a native integration with MailGun. All you have to do is connect your Mailgun account, and you will improve your email deliverability.
55
+
56
+ Read our <a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" rel="friend">Mailgun documentation</a> for more details.
57
+
58
+ = Gmail SMTP =
59
+
60
+ Often bloggers and small business owners don't want to use third-party SMTP services. Well you can use your Gmail or G Suite account for SMTP emails.
61
+
62
+ This allows you to use your <a href="http://www.wpbeginner.com/beginners-guide/how-to-setup-a-professional-email-address-with-gmail-and-google-apps/" rel="friend">professional email address</a> and improve email deliverability.
63
+
64
+ Unlike other Gmail SMTP plugins, our Gmail SMTP option uses OAuth to authenticate your Google account, keeping your login information 100% secure.
65
+
66
+ Read our <a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" rel="friend">Gmail documentation</a> for more details.
67
+
68
+ = SendGrid SMTP =
69
+
70
+ SendGrid has a free SMTP plan that you can use to send up to 100 emails per day. With our native SendGrid SMTP integration, you can easily and securely set up SendGrid SMTP on your WordPress site.
71
+
72
+ Read our <a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" rel="friend">SendGrid documentation</a> for more details.
73
+
74
+ = Other SMTP =
75
+
76
+ WP Mail SMTP plugin also works with all major email services such as Gmail, Yahoo, Outlook, Microsoft Live, and any other email sending service that offers SMTP.
77
+
78
+ You can set the following options:
79
+
80
+ * Specify an SMTP host.
81
+ * Specify an SMTP port.
82
+ * Choose SSL / TLS encryption.
83
+ * Choose to use SMTP authentication or not.
84
+ * Specify an SMTP username and password.
85
+
86
+ WP Mail SMTP also gives you the option to insert your password in your wp-config.php file, so it's not visible in your WordPress settings.
87
+
88
+ To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">SMTP documentation</a>.
89
+
90
+ We hope that you find WP Mail SMTP plugin helpful.
91
+
92
+ = Credits =
93
+
94
+ WP Mail SMTP plugin was originally created by Callum Macdonald. It is now owned and maintained by the team behind <a href="https://wpforms.com/" rel="friend">WPForms</a> - the best drag & drop form builder for WordPress.
95
+
96
+ You can try the <a href="https://wordpress.org/plugins/wpforms-lite/" rel="friend">free version of WPForms plugin</a> to see why it's the best in the market.
97
+
98
+ = What's Next =
99
+
100
+ If you like this plugin, then please consider checking out our other popular plugins:
101
+
102
+ * <a href="http://optinmonster.com/" rel="friend" title="OptinMonster">OptinMonster</a> - Get More Email Subscribers
103
+ * <a href="https://www.monsterinsights.com/" rel="friend" title="MonsterInsights">MonsterInsights</a> - Best Google Analytics Plugin for WordPress
104
+
105
+ Visit <a href="http://www.wpbeginner.com/" rel="friend" title="WPBeginner">WPBeginner</a> to learn from our <a href="http://www.wpbeginner.com/category/wp-tutorials/" rel="friend" title="WordPress Tutorials">WordPress Tutorials</a> and find out about other <a href="http://www.wpbeginner.com/category/plugins/" rel="friend" title="Best WordPress Plugins">best WordPress plugins</a>.
106
+
107
+ == Installation ==
108
+
109
+ 1. Install WP Mail SMTP by WPForms either via the WordPress.org plugin repository or by uploading the files to your server. (See instructions on <a href="http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/" rel="friend">how to install a WordPress plugin</a>)
110
+ 2. Activate WP Mail SMTP by WPForms.
111
+ 3. Navigate to the Settings area of WP Mail SMTP in the WordPress admin.
112
+ 4. Choose your SMTP option (Mailgun SMTP, SendGrid SMTP, Gmail SMTP, or Other SMTP) and follow the instructions to set it up.
113
+ 5. Want to support us? Consider trying <a href="https://wpforms.com/?utm_source=wprepo&utm_medium=link&utm_campaign=liteversion" rel="friend" title="WPForms">WPForms Pro</a> - the best WordPress contact form plugin!
114
+
115
+ == Frequently Asked Questions ==
116
+
117
+ = Can I use this plugin to send email via Gmail, G Suite, Outlook.com, Office 365, Hotmail, Yahoo, or AOL SMTP? =
118
+
119
+ Yes! We have extensive documentation that covers setting up SMTP most popular email services.
120
+
121
+ <a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">Read our docs</a> to see the correct SMTP settings for each service.
122
+
123
+ = Help! I need support or have an issue. =
124
+
125
+ Please read <a href="https://wordpress.org/support/topic/wp-mail-smtp-support-policy/">our support policy</a> for more information.
126
+
127
+ = I found a bug, now what? =
128
+
129
+ If you've stumbled upon a bug, the best place to report it is in the <a href="https://github.com/awesomemotive/wp-mail-smtp">WP Mail SMTP GitHub repository</a>. GitHub is where the plugin is actively developed, and posting there will get your issue quickly seen by our developers (myself and Slava). Once posted, we'll review your bug report and triage the bug. When creating an issue, the more details you can add to your report, the faster the bug can be solved.
130
+
131
+ = Can you add feature x, y or z to the plugin? =
132
+
133
+ Short answer: maybe.
134
+
135
+ By all means please contact us to discuss features or options you'd like to see added to the plugin. We can't guarantee to add all of them, but we will consider all sensible requests. We can be contacted here:
136
+ <a href="https://wpforms.com/contact/" rel="friend">https://wpforms.com/contact/</a>
137
+
138
+ == Screenshots ==
139
+
140
+ 1. WP Mail SMTP Settings page
141
+ 2. Gmail / G Suite settings
142
+ 3. Mailgun settings
143
+ 4. SendGrid settings
144
+ 5. SMTP settings
145
+ 6. Send a Test Email
146
+
147
+ == Changelog ==
148
+
149
+ = 1.2.4 - 2018-01-28 =
150
+ * Fixed: Improved escaping with debug reporting.
151
+
152
+ = 1.2.3 - 2018-01-22 =
153
+ * Fixed: Gmail tokens were resetted after clicking Save Settings.
154
+ * Fixed: Slight typo in Gmail success message.
155
+
156
+ = 1.2.2 - 2017-12-27 =
157
+ * Fixed: Correctly handle Mailgun debug message for an incorrect api key.
158
+ * Fixed: Fatal error for Gmail and SMTP mailers with Nginx web-server (without Apache at all).
159
+ * Changed: Update X-Mailer emails header to show the real sender with a mailer and plugin version.
160
+
161
+ = 1.2.1 - 2017-12-21 =
162
+ * Fixed: Failed SMTP connections generate fatal errors.
163
+
164
+ = 1.2.0 - 2017-12-21 =
165
+ * Fixed: Decrease the factual minimum WordPress version from 3.9 to 3.6.
166
+ * Changed: Improve debug output for all mail providers.
167
+
168
+ = 1.1.0 - 2017-12-18 =
169
+ * Added: New option "Auto TLS" for SMTP mailer. Default is enabled. Migration routine for all sites.
170
+ * Changed: Improve debug output - clear styles and context-aware content.
171
+ * Changed: Better exceptions handling for Google authentication process.
172
+ * Changed: Do not sanitize passwords, api keys etc - as they may contain special characters in certain order and sanitization will break those values.
173
+ * Changed: Improve wording of some helpful texts inside plugin admin area.
174
+ * Fixed: Do not include certain files in dependency libraries that are not used by Google mailer. This should stop flagging plugin by Wordfence and VaultPress.
175
+ * Fixed: Constants usage is working now, to define the SMTP password, for example.
176
+ * Fixed: Notice for default mailer.
177
+
178
+ = 1.0.2 - 2017-12-12 =
179
+ * Fixed: PHPMailer using incorrect SMTPSecure value.
180
+
181
+ = 1.0.1 - 2017-12-12 =
182
+ * Fixed: Global POST processing conflict.
183
+
184
+ = 1.0.0 - 2017-12-12 =
185
+ * Added: Automatic migration tool to move options from older storage format to a new one.
186
+ * Added: Added Gmail & G Suite email provider integration - without your email and password.
187
+ * Added: Added SendGrid email provider integration - using the API key only.
188
+ * Added: Added Mailgun email provider integration - using the API key and configured domain only.
189
+ * Added: New compatibility mode - for PHP 5.2 old plugin will be loaded, for PHP 5.3 and higher - new version of admin area and new functionality.
190
+ * Changed: The new look of the admin area.
191
+ * Changed: SMTP password field now has "password" type.
192
+ * Changed: SMTP password field does not display real password at all when using constants in `wp-config.php` to define it.
193
+ * Changed: Escape properly all translations.
194
+ * Changed: More helpful test email content (with a mailer name).
195
+
196
+ = 0.11.2 - 2017-11-28 =
197
+ * Added: Setting to hide announcement feed.
198
+ * Changed: Announcement feed data.
199
+
200
+ = 0.11.1 - 2017-10-30 =
201
+ * Fixed: Older PHP compatibility fix.
202
+
203
+ = 0.11 - 2017-10-30 =
204
+ * Added: Helper description to Return Path option.
205
+ * Added: Filter `wp_mail_smtp_admin_test_email_smtp_debug` to increase the debug message verbosity.
206
+ * Added: PHP 5.2 notice.
207
+ * Added: Announcement feed.
208
+ * Changed: Localization fixes, proper locale name.
209
+ * Changed: Code style improvements and optimizations for both HTML and PHP.
210
+ * Changed: Inputs for emails now have a proper type `email`, instead of a generic `text`.
211
+ * Changed: Turn off `$phpmailer->SMTPAutoTLS` when `No encryption` option is set to prevent error while sending emails.
212
+ * Changed: Hide Pepipost for those who are not using it.
213
+ * Changed: WP CLI support improved.
214
+
215
+ = 0.10.1 =
216
+ * Addition of Pepipost and cleanup of admin page.
217
+
218
+ = 0.10.0 =
219
+ * Addition of Pepipost and cleanup of admin page.
220
+
221
+ = 0.9.6 =
222
+ * Minor security fix, sanitize test email address.
223
+
224
+ = 0.9.5 =
225
+ * Minor security fix, hat tip JD Grimes.
226
+
227
+ = 0.9.4 =
228
+ * Improvement to the test email function, very low priority update.
229
+
230
+ = 0.9.3 =
231
+ * Fixing reported issue with passing by reference. props Adam Conway
232
+
233
+ = 0.9.2 =
234
+ * Removing the deprecation notice.
235
+
236
+ = 0.9.1 =
237
+ * $phpmailer->language became protected in WP 3.2, no longer unset on debug output.
238
+
239
+ = 0.9.0 =
240
+ * Typo in the From email description.
241
+ * Removed changelog from plugin file, no need to duplicate it.
242
+ * Optionally set $phpmailer->Sender from from email, helps with sendmail / mail().
243
+
244
+ = 0.8.7 =
245
+ * Fix for a long standing bug that caused an error during plugin activation.
246
+
247
+ = 0.8.6 =
248
+ * The Settings link really does work this time, promise. Apologies for the unnecessary updates.
249
+
250
+ = 0.8.5 =
251
+ * Bugfix, the settings link on the Plugin page was broken by 0.8.4.
252
+
253
+ = 0.8.4 =
254
+ * Minor bugfix, remove use of esc_html() to improve backwards compatibility.
255
+ * Removed second options page menu props ovidiu.
256
+
257
+ = 0.8.3 =
258
+ * Bugfix, return WPMS_MAIL_FROM_NAME, props nacin.
259
+ * Add Settings link, props Mike Challis http://profiles.wordpress.org/MikeChallis/
260
+
261
+ = 0.8.2 =
262
+ * Bugfix, call phpmailer_init_smtp() correctly, props Sinklar.
263
+
264
+ = 0.8.1 =
265
+ * Internationalisation improvements.
266
+
267
+ = 0.8 =
268
+ * Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
269
+
270
+ = 0.7 =
271
+ * Added checks to only override the default from name / email
272
+
273
+ = 0.6 =
274
+ * Added additional SMTP debugging output
275
+
276
+ = 0.5.2 =
277
+ * Fixed a pre 2.3 bug to do with mail from
278
+
279
+ = 0.5.1 =
280
+ * Added a check to display a warning on versions prior to 2.3
281
+
282
+ = 0.5.0 =
283
+ * Upgraded to match 2.3 filters which add a second filter for from name
284
+
285
+ = 0.4.2 =
286
+ * Fixed a bug in 0.4.1 and added more debugging output
287
+
288
+ = 0.4.1 =
289
+ * Added $phpmailer->ErroInfo to the test mail output
290
+
291
+ = 0.4 =
292
+ * Added the test email feature and cleaned up some other bits and pieces
293
+
294
+ = 0.3.2 =
295
+ * Changed to use register_activation_hook for greater compatability
296
+
297
+ = 0.3.1 =
298
+ * Added readme for WP-Plugins.org compatability
299
+
300
+ = 0.3 =
301
+ * Various bugfixes and added From options
302
+
303
+ = 0.2 =
304
+ * Reworked approach as suggested by westi, added options page
305
+
306
+ = 0.1 =
307
+ * Initial approach, copying the wp_mail function and replacing it
308
+
309
+ == Upgrade Notice ==
310
+
311
+ = 0.10.1 =
312
+ Addition of Pepipost and cleanup of admin page.
313
+
314
+ = 0.10.0 =
315
+ Addition of Pepipost and cleanup of admin page.
316
+
317
+ = 0.9.6 =
318
+ Minor security fix, sanitize test email address.
319
+
320
+ = 0.9.5 =
321
+ Minor security fix, hat tip JD Grimes.
322
+
323
+ = 0.9.4 =
324
+ Improvement to the test email function, very low priority update.
325
+
326
+ = 0.9.3 =
327
+ Fixing reported issue with passing by reference.
328
+
329
+ = 0.9.2 =
330
+ Removing the deprecation notice.
331
+
332
+ = 0.9.1 =
333
+ Test mail functionality was broken on upgrade to 3.2, now restored.
334
+
335
+ = 0.9.0 =
336
+ Low priority upgrade. Improves the appearance of the options page.
337
+
338
+ = 0.8.7 =
339
+ Very low priority update. Fixes a bug that causes a spurious error during activation.
340
+
341
+ = 0.8.6 =
342
+ Low priority update. The Settings link was still broken in 0.8.5.
343
+
344
+ = 0.8.5 =
345
+ Minor bugfix correcting the Settings link bug introduced in 0.8.4. Very low priority update.
346
+
347
+ = 0.8.4 =
348
+ Minor bugfix for users using constants. Another very low priority upgrade. Apologies for the version creep.
349
+
350
+ = 0.8.3 =
351
+ Minor bugfix for users using constants. Very low priority upgrade.
src/AM_Notification.php CHANGED
@@ -1,452 +1,452 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Awesome Motive Notifications
7
- *
8
- * This creates a custom post type (if it doesn't exist) and calls the API to
9
- * retrieve notifications for this product.
10
- *
11
- * @package AwesomeMotive
12
- * @author Benjamin Rojas
13
- * @license GPL-2.0+
14
- * @copyright Copyright (c) 2017, Retyp LLC
15
- * @version 1.0.2
16
- */
17
- class AM_Notification {
18
- /**
19
- * The api url we are calling.
20
- *
21
- * @since 1.0.0
22
- *
23
- * @var string
24
- */
25
- public $api_url = 'https://api.awesomemotive.com/v1/notification/';
26
-
27
- /**
28
- * A unique slug for this plugin.
29
- * (Not the WordPress plugin slug)
30
- *
31
- * @since 1.0.0
32
- *
33
- * @var string
34
- */
35
- public $plugin;
36
-
37
- /**
38
- * The current plugin version.
39
- *
40
- * @since 1.0.0
41
- *
42
- * @var string
43
- */
44
- public $plugin_version;
45
-
46
- /**
47
- * Flag if a notice has been registered.
48
- *
49
- * @since 1.0.0
50
- *
51
- * @var bool
52
- */
53
- public static $registered = false;
54
-
55
- /**
56
- * Construct.
57
- *
58
- * @since 1.0.0
59
- *
60
- * @param string $plugin The plugin slug.
61
- * @param mixed $version The version of the plugin.
62
- */
63
- public function __construct( $plugin = '', $version = 0 ) {
64
- $this->plugin = $plugin;
65
- $this->plugin_version = $version;
66
-
67
- add_action( 'init', array( $this, 'custom_post_type' ) );
68
- add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
69
- add_action( 'admin_notices', array( $this, 'display_notifications' ) );
70
- add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
71
- }
72
-
73
- /**
74
- * Registers a custom post type.
75
- *
76
- * @since 1.0.0
77
- */
78
- public function custom_post_type() {
79
- register_post_type( 'amn_' . $this->plugin, array(
80
- 'label' => $this->plugin . ' Announcements',
81
- 'can_export' => false,
82
- 'supports' => false,
83
- ) );
84
- }
85
-
86
- /**
87
- * Retrieve the remote notifications if the time has expired.
88
- *
89
- * @since 1.0.0
90
- */
91
- public function get_remote_notifications() {
92
- if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
93
- return;
94
- }
95
-
96
- $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
97
-
98
- if ( $last_checked < strtotime( 'today midnight' ) ) {
99
- $plugin_notifications = $this->get_plugin_notifications( 1 );
100
- $notification_id = null;
101
-
102
- if ( ! empty( $plugin_notifications ) ) {
103
- // Unset it from the array.
104
- $notification = $plugin_notifications[0];
105
- $notification_id = get_post_meta( $notification->ID, 'notification_id', true );
106
- }
107
-
108
- $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
109
- 'body' => array(
110
- 'slug' => $this->plugin,
111
- 'version' => $this->plugin_version,
112
- 'last_notification' => $notification_id,
113
- ),
114
- ) ) );
115
-
116
- $data = json_decode( $response );
117
-
118
- if ( ! empty( $data->id ) ) {
119
- $notifications = array();
120
-
121
- foreach ( (array) $data->slugs as $slug ) {
122
- $notifications = array_merge(
123
- $notifications,
124
- (array) get_posts(
125
- array(
126
- 'post_type' => 'amn_' . $slug,
127
- 'post_status' => 'all',
128
- 'meta_key' => 'notification_id',
129
- 'meta_value' => $data->id,
130
- )
131
- )
132
- );
133
- }
134
-
135
- if ( empty( $notifications ) ) {
136
- $new_notification_id = wp_insert_post( array(
137
- 'post_content' => wp_kses_post( $data->content ),
138
- 'post_type' => 'amn_' . $this->plugin,
139
- ) );
140
-
141
- update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
142
- update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
143
- update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
144
- update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
145
- update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
146
- update_post_meta( $new_notification_id, 'viewed', 0 );
147
- update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
148
- update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
149
- }
150
- }
151
-
152
- // Possibly revoke notifications.
153
- if ( ! empty( $data->revoked ) ) {
154
- $this->revoke_notifications( $data->revoked );
155
- }
156
-
157
- // Set the option now so we can't run this again until after 24 hours.
158
- update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
159
- }
160
- }
161
-
162
- /**
163
- * Get local plugin notifications that have already been set.
164
- *
165
- * @since 1.0.0
166
- *
167
- * @param integer $limit Set the limit for how many posts to retrieve.
168
- * @param array $args Any top-level arguments to add to the array.
169
- *
170
- * @return WP_Post[] WP_Post that match the query.
171
- */
172
- public function get_plugin_notifications( $limit = -1, $args = array() ) {
173
- return get_posts(
174
- array(
175
- 'posts_per_page' => $limit,
176
- 'post_type' => 'amn_' . $this->plugin,
177
- ) + $args
178
- );
179
- }
180
-
181
- /**
182
- * Display any notifications that should be displayed.
183
- *
184
- * @since 1.0.0
185
- */
186
- public function display_notifications() {
187
- if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
188
- return;
189
- }
190
-
191
- $plugin_notifications = $this->get_plugin_notifications( -1, array(
192
- 'post_status' => 'all',
193
- 'meta_key' => 'viewed',
194
- 'meta_value' => '0',
195
- ) );
196
-
197
- $plugin_notifications = $this->validate_notifications( $plugin_notifications );
198
-
199
- if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
200
- foreach ( $plugin_notifications as $notification ) {
201
- $dismissable = get_post_meta( $notification->ID, 'dismissable', true );
202
- $type = get_post_meta( $notification->ID, 'type', true );
203
- ?>
204
- <div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
205
- <?php echo $notification->post_content; ?>
206
- </div>
207
- <script type="text/javascript">
208
- jQuery(document).ready(function ($) {
209
- $(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
210
- $.post(ajaxurl, {
211
- action: 'am_notification_dismiss',
212
- notification_id: '<?php echo $notification->ID; ?>'
213
- });
214
- });
215
- });
216
- </script>
217
- <?php
218
- }
219
-
220
- self::$registered = true;
221
- }
222
- }
223
-
224
- /**
225
- * Validate the notifications before displaying them.
226
- *
227
- * @since 1.0.0
228
- *
229
- * @param array $plugin_notifications An array of plugin notifications.
230
- *
231
- * @return array A filtered array of plugin notifications.
232
- */
233
- public function validate_notifications( $plugin_notifications ) {
234
- global $pagenow;
235
-
236
- foreach ( $plugin_notifications as $key => $notification ) {
237
- // Location validation.
238
- $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
239
- $continue = false;
240
- if ( ! in_array( 'everywhere', $location, true ) ) {
241
- if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
242
- $continue = true;
243
- }
244
-
245
- if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
246
- $continue = true;
247
- }
248
-
249
- if ( ! $continue ) {
250
- unset( $plugin_notifications[ $key ] );
251
- }
252
- }
253
-
254
- // Plugin validation (OR conditional).
255
- $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
256
- $continue = false;
257
- if ( ! empty( $plugins ) ) {
258
- foreach ( $plugins as $plugin ) {
259
- if ( is_plugin_active( $plugin ) ) {
260
- $continue = true;
261
- }
262
- }
263
-
264
- if ( ! $continue ) {
265
- unset( $plugin_notifications[ $key ] );
266
- }
267
- }
268
-
269
- // Theme validation.
270
- $theme = get_post_meta( $notification->ID, 'theme', true );
271
- $continue = (string) wp_get_theme() === $theme;
272
-
273
- if ( ! empty( $theme ) && ! $continue ) {
274
- unset( $plugin_notifications[ $key ] );
275
- }
276
-
277
- // Version validation.
278
- $version = get_post_meta( $notification->ID, 'version', true );
279
- $continue = false;
280
- if ( ! empty( $version ) ) {
281
- if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
282
- $continue = true;
283
- }
284
-
285
- if ( ! $continue ) {
286
- unset( $plugin_notifications[ $key ] );
287
- }
288
- }
289
-
290
- // Expiration validation.
291
- $expiration = get_post_meta( $notification->ID, 'expiration', true );
292
- $continue = false;
293
- if ( ! empty( $expiration ) ) {
294
- if ( $expiration > time() ) {
295
- $continue = true;
296
- }
297
-
298
- if ( ! $continue ) {
299
- unset( $plugin_notifications[ $key ] );
300
- }
301
- }
302
-
303
- // Plan validation.
304
- $plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
305
- $continue = false;
306
- if ( ! empty( $plans ) ) {
307
- $level = $this->get_plan_level();
308
- if ( in_array( $level, $plans, true ) ) {
309
- $continue = true;
310
- }
311
-
312
- if ( ! $continue ) {
313
- unset( $plugin_notifications[ $key ] );
314
- }
315
- }
316
- }
317
-
318
- return $plugin_notifications;
319
- }
320
-
321
- /**
322
- * Grab the current plan level.
323
- *
324
- * @since 1.0.0
325
- *
326
- * @return string The current plan level.
327
- */
328
- public function get_plan_level() {
329
- // Prepare variables.
330
- $key = '';
331
- $level = '';
332
- $option = false;
333
- switch ( $this->plugin ) {
334
- case 'wpforms' :
335
- $option = get_option( 'wpforms_license' );
336
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
337
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
338
-
339
- // Possibly check for a constant.
340
- if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
341
- $key = WPFORMS_LICENSE_KEY;
342
- }
343
- break;
344
- case 'mi' :
345
- $option = get_option( 'monsterinsights_license' );
346
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
347
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
348
-
349
- // Possibly check for a constant.
350
- if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
351
- $key = MONSTERINSIGHTS_LICENSE_KEY;
352
- }
353
- break;
354
- case 'sol' :
355
- $option = get_option( 'soliloquy' );
356
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
357
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
358
-
359
- // Possibly check for a constant.
360
- if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
361
- $key = SOLILOQUY_LICENSE_KEY;
362
- }
363
- break;
364
- case 'envira' :
365
- $option = get_option( 'envira_gallery' );
366
- $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
367
- $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
368
-
369
- // Possibly check for a constant.
370
- if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
371
- $key = ENVIRA_LICENSE_KEY;
372
- }
373
- break;
374
- case 'om' :
375
- $option = get_option( 'optin_monster_api' );
376
- $key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
377
-
378
- // Possibly check for a constant.
379
- if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
380
- $key = OPTINMONSTER_REST_API_LICENSE_KEY;
381
- }
382
-
383
- // If the key is still empty, check for the old legacy key.
384
- if ( empty( $key ) ) {
385
- $key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
386
- }
387
- break;
388
- }
389
-
390
- // Possibly set the level to 'none' if the key is empty and no level has been set.
391
- if ( empty( $key ) && empty( $level ) ) {
392
- $level = 'none';
393
- }
394
-
395
- // Normalize the level.
396
- switch ( $level ) {
397
- case 'bronze' :
398
- case 'personal' :
399
- $level = 'basic';
400
- break;
401
- case 'silver' :
402
- case 'multi' :
403
- $level = 'plus';
404
- break;
405
- case 'gold' :
406
- case 'developer' :
407
- $level = 'pro';
408
- break;
409
- case 'platinum' :
410
- case 'master' :
411
- $level = 'ultimate';
412
- break;
413
- }
414
-
415
- // Return the plan level.
416
- return $level;
417
- }
418
-
419
- /**
420
- * Dismiss the notification via AJAX.
421
- *
422
- * @since 1.0.0
423
- */
424
- public function dismiss_notification() {
425
- if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
426
- die;
427
- }
428
-
429
- $notification_id = intval( $_POST['notification_id'] );
430
- update_post_meta( $notification_id, 'viewed', 1 );
431
- die;
432
- }
433
-
434
- /**
435
- * Revokes notifications.
436
- *
437
- * @since 1.0.0
438
- *
439
- * @param array $ids An array of notification IDs to revoke.
440
- */
441
- public function revoke_notifications( $ids ) {
442
- // Loop through each of the IDs and find the post that has it as meta.
443
- foreach ( (array) $ids as $id ) {
444
- $notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
445
- if ( $notifications ) {
446
- foreach ( $notifications as $notification ) {
447
- update_post_meta( $notification->ID, 'viewed', 1 );
448
- }
449
- }
450
- }
451
- }
452
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Awesome Motive Notifications
7
+ *
8
+ * This creates a custom post type (if it doesn't exist) and calls the API to
9
+ * retrieve notifications for this product.
10
+ *
11
+ * @package AwesomeMotive
12
+ * @author Benjamin Rojas
13
+ * @license GPL-2.0+
14
+ * @copyright Copyright (c) 2017, Retyp LLC
15
+ * @version 1.0.2
16
+ */
17
+ class AM_Notification {
18
+ /**
19
+ * The api url we are calling.
20
+ *
21
+ * @since 1.0.0
22
+ *
23
+ * @var string
24
+ */
25
+ public $api_url = 'https://api.awesomemotive.com/v1/notification/';
26
+
27
+ /**
28
+ * A unique slug for this plugin.
29
+ * (Not the WordPress plugin slug)
30
+ *
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ public $plugin;
36
+
37
+ /**
38
+ * The current plugin version.
39
+ *
40
+ * @since 1.0.0
41
+ *
42
+ * @var string
43
+ */
44
+ public $plugin_version;
45
+
46
+ /**
47
+ * Flag if a notice has been registered.
48
+ *
49
+ * @since 1.0.0
50
+ *
51
+ * @var bool
52
+ */
53
+ public static $registered = false;
54
+
55
+ /**
56
+ * Construct.
57
+ *
58
+ * @since 1.0.0
59
+ *
60
+ * @param string $plugin The plugin slug.
61
+ * @param mixed $version The version of the plugin.
62
+ */
63
+ public function __construct( $plugin = '', $version = 0 ) {
64
+ $this->plugin = $plugin;
65
+ $this->plugin_version = $version;
66
+
67
+ add_action( 'init', array( $this, 'custom_post_type' ) );
68
+ add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
69
+ add_action( 'admin_notices', array( $this, 'display_notifications' ) );
70
+ add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
71
+ }
72
+
73
+ /**
74
+ * Registers a custom post type.
75
+ *
76
+ * @since 1.0.0
77
+ */
78
+ public function custom_post_type() {
79
+ register_post_type( 'amn_' . $this->plugin, array(
80
+ 'label' => $this->plugin . ' Announcements',
81
+ 'can_export' => false,
82
+ 'supports' => false,
83
+ ) );
84
+ }
85
+
86
+ /**
87
+ * Retrieve the remote notifications if the time has expired.
88
+ *
89
+ * @since 1.0.0
90
+ */
91
+ public function get_remote_notifications() {
92
+ if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
93
+ return;
94
+ }
95
+
96
+ $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
97
+
98
+ if ( $last_checked < strtotime( 'today midnight' ) ) {
99
+ $plugin_notifications = $this->get_plugin_notifications( 1 );
100
+ $notification_id = null;
101
+
102
+ if ( ! empty( $plugin_notifications ) ) {
103
+ // Unset it from the array.
104
+ $notification = $plugin_notifications[0];
105
+ $notification_id = get_post_meta( $notification->ID, 'notification_id', true );
106
+ }
107
+
108
+ $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
109
+ 'body' => array(
110
+ 'slug' => $this->plugin,
111
+ 'version' => $this->plugin_version,
112
+ 'last_notification' => $notification_id,
113
+ ),
114
+ ) ) );
115
+
116
+ $data = json_decode( $response );
117
+
118
+ if ( ! empty( $data->id ) ) {
119
+ $notifications = array();
120
+
121
+ foreach ( (array) $data->slugs as $slug ) {
122
+ $notifications = array_merge(
123
+ $notifications,
124
+ (array) get_posts(
125
+ array(
126
+ 'post_type' => 'amn_' . $slug,
127
+ 'post_status' => 'all',
128
+ 'meta_key' => 'notification_id',
129
+ 'meta_value' => $data->id,
130
+ )
131
+ )
132
+ );
133
+ }
134
+
135
+ if ( empty( $notifications ) ) {
136
+ $new_notification_id = wp_insert_post( array(
137
+ 'post_content' => wp_kses_post( $data->content ),
138
+ 'post_type' => 'amn_' . $this->plugin,
139
+ ) );
140
+
141
+ update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
142
+ update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
143
+ update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
144
+ update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
145
+ update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
146
+ update_post_meta( $new_notification_id, 'viewed', 0 );
147
+ update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
148
+ update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
149
+ }
150
+ }
151
+
152
+ // Possibly revoke notifications.
153
+ if ( ! empty( $data->revoked ) ) {
154
+ $this->revoke_notifications( $data->revoked );
155
+ }
156
+
157
+ // Set the option now so we can't run this again until after 24 hours.
158
+ update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Get local plugin notifications that have already been set.
164
+ *
165
+ * @since 1.0.0
166
+ *
167
+ * @param integer $limit Set the limit for how many posts to retrieve.
168
+ * @param array $args Any top-level arguments to add to the array.
169
+ *
170
+ * @return WP_Post[] WP_Post that match the query.
171
+ */
172
+ public function get_plugin_notifications( $limit = -1, $args = array() ) {
173
+ return get_posts(
174
+ array(
175
+ 'posts_per_page' => $limit,
176
+ 'post_type' => 'amn_' . $this->plugin,
177
+ ) + $args
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Display any notifications that should be displayed.
183
+ *
184
+ * @since 1.0.0
185
+ */
186
+ public function display_notifications() {
187
+ if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
188
+ return;
189
+ }
190
+
191
+ $plugin_notifications = $this->get_plugin_notifications( -1, array(
192
+ 'post_status' => 'all',
193
+ 'meta_key' => 'viewed',
194
+ 'meta_value' => '0',
195
+ ) );
196
+
197
+ $plugin_notifications = $this->validate_notifications( $plugin_notifications );
198
+
199
+ if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
200
+ foreach ( $plugin_notifications as $notification ) {
201
+ $dismissable = get_post_meta( $notification->ID, 'dismissable', true );
202
+ $type = get_post_meta( $notification->ID, 'type', true );
203
+ ?>
204
+ <div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
205
+ <?php echo $notification->post_content; ?>
206
+ </div>
207
+ <script type="text/javascript">
208
+ jQuery(document).ready(function ($) {
209
+ $(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
210
+ $.post(ajaxurl, {
211
+ action: 'am_notification_dismiss',
212
+ notification_id: '<?php echo $notification->ID; ?>'
213
+ });
214
+ });
215
+ });
216
+ </script>
217
+ <?php
218
+ }
219
+
220
+ self::$registered = true;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Validate the notifications before displaying them.
226
+ *
227
+ * @since 1.0.0
228
+ *
229
+ * @param array $plugin_notifications An array of plugin notifications.
230
+ *
231
+ * @return array A filtered array of plugin notifications.
232
+ */
233
+ public function validate_notifications( $plugin_notifications ) {
234
+ global $pagenow;
235
+
236
+ foreach ( $plugin_notifications as $key => $notification ) {
237
+ // Location validation.
238
+ $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
239
+ $continue = false;
240
+ if ( ! in_array( 'everywhere', $location, true ) ) {
241
+ if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
242
+ $continue = true;
243
+ }
244
+
245
+ if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
246
+ $continue = true;
247
+ }
248
+
249
+ if ( ! $continue ) {
250
+ unset( $plugin_notifications[ $key ] );
251
+ }
252
+ }
253
+
254
+ // Plugin validation (OR conditional).
255
+ $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
256
+ $continue = false;
257
+ if ( ! empty( $plugins ) ) {
258
+ foreach ( $plugins as $plugin ) {
259
+ if ( is_plugin_active( $plugin ) ) {
260
+ $continue = true;
261
+ }
262
+ }
263
+
264
+ if ( ! $continue ) {
265
+ unset( $plugin_notifications[ $key ] );
266
+ }
267
+ }
268
+
269
+ // Theme validation.
270
+ $theme = get_post_meta( $notification->ID, 'theme', true );
271
+ $continue = (string) wp_get_theme() === $theme;
272
+
273
+ if ( ! empty( $theme ) && ! $continue ) {
274
+ unset( $plugin_notifications[ $key ] );
275
+ }
276
+
277
+ // Version validation.
278
+ $version = get_post_meta( $notification->ID, 'version', true );
279
+ $continue = false;
280
+ if ( ! empty( $version ) ) {
281
+ if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
282
+ $continue = true;
283
+ }
284
+
285
+ if ( ! $continue ) {
286
+ unset( $plugin_notifications[ $key ] );
287
+ }
288
+ }
289
+
290
+ // Expiration validation.
291
+ $expiration = get_post_meta( $notification->ID, 'expiration', true );
292
+ $continue = false;
293
+ if ( ! empty( $expiration ) ) {
294
+ if ( $expiration > time() ) {
295
+ $continue = true;
296
+ }
297
+
298
+ if ( ! $continue ) {
299
+ unset( $plugin_notifications[ $key ] );
300
+ }
301
+ }
302
+
303
+ // Plan validation.
304
+ $plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
305
+ $continue = false;
306
+ if ( ! empty( $plans ) ) {
307
+ $level = $this->get_plan_level();
308
+ if ( in_array( $level, $plans, true ) ) {
309
+ $continue = true;
310
+ }
311
+
312
+ if ( ! $continue ) {
313
+ unset( $plugin_notifications[ $key ] );
314
+ }
315
+ }
316
+ }
317
+
318
+ return $plugin_notifications;
319
+ }
320
+
321
+ /**
322
+ * Grab the current plan level.
323
+ *
324
+ * @since 1.0.0
325
+ *
326
+ * @return string The current plan level.
327
+ */
328
+ public function get_plan_level() {
329
+ // Prepare variables.
330
+ $key = '';
331
+ $level = '';
332
+ $option = false;
333
+ switch ( $this->plugin ) {
334
+ case 'wpforms' :
335
+ $option = get_option( 'wpforms_license' );
336
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
337
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
338
+
339
+ // Possibly check for a constant.
340
+ if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
341
+ $key = WPFORMS_LICENSE_KEY;
342
+ }
343
+ break;
344
+ case 'mi' :
345
+ $option = get_option( 'monsterinsights_license' );
346
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
347
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
348
+
349
+ // Possibly check for a constant.
350
+ if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
351
+ $key = MONSTERINSIGHTS_LICENSE_KEY;
352
+ }
353
+ break;
354
+ case 'sol' :
355
+ $option = get_option( 'soliloquy' );
356
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
357
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
358
+
359
+ // Possibly check for a constant.
360
+ if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
361
+ $key = SOLILOQUY_LICENSE_KEY;
362
+ }
363
+ break;
364
+ case 'envira' :
365
+ $option = get_option( 'envira_gallery' );
366
+ $key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
367
+ $level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
368
+
369
+ // Possibly check for a constant.
370
+ if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
371
+ $key = ENVIRA_LICENSE_KEY;
372
+ }
373
+ break;
374
+ case 'om' :
375
+ $option = get_option( 'optin_monster_api' );
376
+ $key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
377
+
378
+ // Possibly check for a constant.
379
+ if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
380
+ $key = OPTINMONSTER_REST_API_LICENSE_KEY;
381
+ }
382
+
383
+ // If the key is still empty, check for the old legacy key.
384
+ if ( empty( $key ) ) {
385
+ $key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
386
+ }
387
+ break;
388
+ }
389
+
390
+ // Possibly set the level to 'none' if the key is empty and no level has been set.
391
+ if ( empty( $key ) && empty( $level ) ) {
392
+ $level = 'none';
393
+ }
394
+
395
+ // Normalize the level.
396
+ switch ( $level ) {
397
+ case 'bronze' :
398
+ case 'personal' :
399
+ $level = 'basic';
400
+ break;
401
+ case 'silver' :
402
+ case 'multi' :
403
+ $level = 'plus';
404
+ break;
405
+ case 'gold' :
406
+ case 'developer' :
407
+ $level = 'pro';
408
+ break;
409
+ case 'platinum' :
410
+ case 'master' :
411
+ $level = 'ultimate';
412
+ break;
413
+ }
414
+
415
+ // Return the plan level.
416
+ return $level;
417
+ }
418
+
419
+ /**
420
+ * Dismiss the notification via AJAX.
421
+ *
422
+ * @since 1.0.0
423
+ */
424
+ public function dismiss_notification() {
425
+ if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
426
+ die;
427
+ }
428
+
429
+ $notification_id = intval( $_POST['notification_id'] );
430
+ update_post_meta( $notification_id, 'viewed', 1 );
431
+ die;
432
+ }
433
+
434
+ /**
435
+ * Revokes notifications.
436
+ *
437
+ * @since 1.0.0
438
+ *
439
+ * @param array $ids An array of notification IDs to revoke.
440
+ */
441
+ public function revoke_notifications( $ids ) {
442
+ // Loop through each of the IDs and find the post that has it as meta.
443
+ foreach ( (array) $ids as $id ) {
444
+ $notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
445
+ if ( $notifications ) {
446
+ foreach ( $notifications as $notification ) {
447
+ update_post_meta( $notification->ID, 'viewed', 1 );
448
+ }
449
+ }
450
+ }
451
+ }
452
+ }
src/Admin/Area.php CHANGED
@@ -1,457 +1,457 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin;
4
-
5
- use WPMailSMTP\WP;
6
-
7
- /**
8
- * Class Area registers and process all wp-admin display functionality.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Area {
13
-
14
- /**
15
- * @var string Slug of the admin area page.
16
- */
17
- const SLUG = 'wp-mail-smtp';
18
-
19
- /**
20
- * @var string Admin page unique hook.
21
- */
22
- public $hook;
23
-
24
- /**
25
- * @var PageAbstract[]
26
- */
27
- private $pages;
28
-
29
- /**
30
- * Area constructor.
31
- *
32
- * @since 1.0.0
33
- */
34
- public function __construct() {
35
- $this->hooks();
36
- }
37
-
38
- /**
39
- * Assign all hooks to proper places.
40
- *
41
- * @since 1.0.0
42
- */
43
- protected function hooks() {
44
-
45
- // Add the Settings link to a plugin on Plugins page.
46
- add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_link' ), 10, 2 );
47
-
48
- // Add the options page.
49
- add_action( 'admin_menu', array( $this, 'add_admin_options_page' ) );
50
-
51
- // Admin footer text.
52
- add_filter( 'admin_footer_text', array( $this, 'get_admin_footer' ), 1, 2 );
53
-
54
- // Enqueue admin area scripts and styles.
55
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
56
-
57
- // Process the admin page forms actions.
58
- add_action( 'admin_init', array( $this, 'process_actions' ) );
59
-
60
- // Display custom notices based on the error/success codes.
61
- add_action( 'admin_init', array( $this, 'display_custom_auth_notices' ) );
62
-
63
- // Outputs the plugin admin header.
64
- add_action( 'in_admin_header', array( $this, 'display_admin_header' ), 100 );
65
-
66
- // Hide all unrelated to the plugin notices on the plugin admin pages.
67
- add_action( 'admin_print_scripts', array( $this, 'hide_unrelated_notices' ) );
68
- }
69
-
70
- /**
71
- * Display custom notices based on the error/success codes.
72
- *
73
- * @since 1.0.0
74
- */
75
- public function display_custom_auth_notices() {
76
-
77
- $error = isset( $_GET['error'] ) ? $_GET['error'] : '';
78
- $success = isset( $_GET['success'] ) ? $_GET['success'] : '';
79
-
80
- if ( empty( $error ) && empty( $success ) ) {
81
- return;
82
- }
83
-
84
- switch ( $error ) {
85
- case 'google_access_denied':
86
- WP::add_admin_notice(
87
- /* translators: %s - error code, returned by Google API. */
88
- sprintf( esc_html__( 'There was an error while processing the authentication request: %s. Please try again.', 'wp-mail-smtp' ), '<code>' . $error . '</code>' ),
89
- WP::ADMIN_NOTICE_ERROR
90
- );
91
- break;
92
-
93
- case 'google_no_code_scope':
94
- WP::add_admin_notice(
95
- esc_html__( 'There was an error while processing the authentication request. Please try again.', 'wp-mail-smtp' ),
96
- WP::ADMIN_NOTICE_ERROR
97
- );
98
- break;
99
-
100
- case 'google_no_clients':
101
- WP::add_admin_notice(
102
- esc_html__( 'There was an error while processing the authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.', 'wp-mail-smtp' ),
103
- WP::ADMIN_NOTICE_ERROR
104
- );
105
- break;
106
- }
107
-
108
- switch ( $success ) {
109
- case 'google_site_linked':
110
- WP::add_admin_notice(
111
- esc_html__( 'You have successfully linked the current site with your Google API project. Now you can start sending emails through Google.', 'wp-mail-smtp' ),
112
- WP::ADMIN_NOTICE_SUCCESS
113
- );
114
- break;
115
- }
116
- }
117
-
118
- /**
119
- * Add admin area menu item.
120
- *
121
- * @since 1.0.0
122
- */
123
- public function add_admin_options_page() {
124
-
125
- $this->hook = add_options_page(
126
- esc_html__( 'WP Mail SMTP Options', 'wp-mail-smtp' ),
127
- esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
128
- 'manage_options',
129
- self::SLUG,
130
- array( $this, 'display' )
131
- );
132
- }
133
-
134
- /**
135
- * Enqueue admin area scripts and styles.
136
- *
137
- * @since 1.0.0
138
- *
139
- * @param string $hook
140
- */
141
- public function enqueue_assets( $hook ) {
142
-
143
- if ( $hook !== $this->hook ) {
144
- return;
145
- }
146
-
147
- wp_enqueue_style(
148
- 'wp-mail-smtp-admin',
149
- wp_mail_smtp()->plugin_url . '/assets/css/smtp-admin.min.css',
150
- false,
151
- WPMS_PLUGIN_VER
152
- );
153
-
154
- wp_enqueue_script(
155
- 'wp-mail-smtp-admin',
156
- wp_mail_smtp()->plugin_url . '/assets/js/smtp-admin' . WP::asset_min() . '.js',
157
- array( 'jquery' ),
158
- WPMS_PLUGIN_VER
159
- );
160
- }
161
-
162
- /**
163
- * Outputs the plugin admin header.
164
- *
165
- * @since 1.0.0
166
- */
167
- public function display_admin_header() {
168
-
169
- // Bail if we're not on a plugin page.
170
- if ( ! $this->is_admin_page() ) {
171
- return;
172
- }
173
- ?>
174
-
175
- <div id="wp-mail-smtp-header">
176
- <!--suppress HtmlUnknownTarget -->
177
- <img class="wp-mail-smtp-header-logo" src="<?php echo wp_mail_smtp()->plugin_url; ?>/assets/images/logo.png" alt="WP Mail SMTP"/>
178
- </div>
179
-
180
- <?php
181
- }
182
-
183
- /**
184
- * Display a text to ask users to review the plugin on WP.org.
185
- *
186
- * @since 1.0.0
187
- *
188
- * @param string $text
189
- *
190
- * @return string
191
- */
192
- public function get_admin_footer( $text ) {
193
-
194
- if ( $this->is_admin_page() ) {
195
- $url = 'https://wordpress.org/support/plugin/wp-mail-smtp/reviews/?filter=5#new-post';
196
-
197
- $text = sprintf(
198
- /* translators: %1$s - WP.org link; %2$s - same WP.org link. */
199
- __( 'Please rate <strong>WP Mail SMTP</strong> <a href="%1$s" target="_blank" rel="noopener noreferrer">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%2$s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the WP Mail SMTP team!', 'wp-mail-smtp' ),
200
- $url,
201
- $url
202
- );
203
- }
204
-
205
- return $text;
206
- }
207
-
208
- /**
209
- * Display content of the admin area page.
210
- *
211
- * @since 1.0.0
212
- */
213
- public function display() {
214
- ?>
215
-
216
- <div class="wrap" id="wp-mail-smtp">
217
-
218
- <div class="wp-mail-smtp-page-title">
219
- <?php
220
- foreach ( $this->get_pages() as $page_slug => $page ) :
221
- $label = $page->get_label();
222
- if ( empty( $label ) ) {
223
- continue;
224
- }
225
- $class = $page_slug === $this->get_current_tab() ? 'class="active"' : '';
226
- ?>
227
-
228
- <a href="<?php echo $page->get_link(); ?>" <?php echo $class; ?>><?php echo $label; ?></a>
229
-
230
- <?php endforeach; ?>
231
- </div>
232
-
233
- <div class="wp-mail-smtp-page wp-mail-smtp-tab-<?php echo $this->get_current_tab(); ?>">
234
- <h1 class="screen-reader-text"><?php echo $this->get_current_tab_title(); ?></h1>
235
-
236
- <?php $this->display_current_tab_content(); ?>
237
- </div>
238
-
239
- </div>
240
-
241
- <?php
242
- }
243
-
244
- /**
245
- * Get the current tab title.
246
- *
247
- * @since 1.0.0
248
- */
249
- public function display_current_tab_content() {
250
-
251
- if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
252
- return;
253
- }
254
-
255
- $this->pages[ $this->get_current_tab() ]->display();
256
- }
257
-
258
- /**
259
- * Get the current admin area tab.
260
- *
261
- * @since 1.0.0
262
- *
263
- * @return string
264
- */
265
- protected function get_current_tab() {
266
-
267
- $current = '';
268
-
269
- if ( $this->is_admin_page() ) {
270
- $current = ! empty( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings';
271
- }
272
-
273
- return $current;
274
- }
275
-
276
- /**
277
- * Get the array of default registered tabs for plugin admin area.
278
- *
279
- * @since 1.0.0
280
- *
281
- * @return \WPMailSMTP\Admin\PageAbstract[]
282
- */
283
- public function get_pages() {
284
-
285
- if ( empty( $this->pages ) ) {
286
- $this->pages = array(
287
- 'settings' => new Pages\Settings(),
288
- 'test' => new Pages\Test(),
289
- 'misc' => new Pages\Misc(),
290
- 'auth' => new Pages\Auth(),
291
- );
292
- }
293
-
294
- return apply_filters( 'wp_mail_smtp_admin_get_pages', $this->pages );
295
- }
296
-
297
- /**
298
- * Get the current tab title.
299
- *
300
- * @since 1.0.0
301
- *
302
- * @return string
303
- */
304
- public function get_current_tab_title() {
305
-
306
- if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
307
- return '';
308
- }
309
-
310
- return $this->pages[ $this->get_current_tab() ]->get_title();
311
- }
312
-
313
- /**
314
- * Check whether we are on an admin page.
315
- *
316
- * @since 1.0.0
317
- *
318
- * @return bool
319
- */
320
- public function is_admin_page() {
321
-
322
- $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
323
-
324
- return self::SLUG === $page;
325
- }
326
-
327
- /**
328
- * All possible plugin forms manipulation will be done here.
329
- *
330
- * @since 1.0.0
331
- */
332
- public function process_actions() {
333
-
334
- // Allow to process only own tabs.
335
- if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
336
- return;
337
- }
338
-
339
- // Process POST only if it exists.
340
- if ( ! empty( $_POST ) ) {
341
- if ( ! empty( $_POST['wp-mail-smtp'] ) ) {
342
- $post = $_POST['wp-mail-smtp'];
343
- } else {
344
- $post = array();
345
- }
346
-
347
- $this->pages[ $this->get_current_tab() ]->process_post( $post );
348
- }
349
-
350
- // This won't do anything for most pages.
351
- $this->pages[ $this->get_current_tab() ]->process_auth();
352
- }
353
-
354
- /**
355
- * Add a link to Settings page of a plugin on Plugins page.
356
- *
357
- * @since 1.0.0
358
- *
359
- * @param array $links
360
- * @param string $file
361
- *
362
- * @return mixed
363
- */
364
- public function add_plugin_action_link( $links, $file ) {
365
-
366
- if ( strpos( $file, 'wp-mail-smtp' ) === false ) {
367
- return $links;
368
- }
369
-
370
- $settings_link = '<a href="' . $this->get_admin_page_url() . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
371
-
372
- array_unshift( $links, $settings_link );
373
-
374
- return $links;
375
- }
376
-
377
- /**
378
- * Get plugin admin area page URL.
379
- *
380
- * @since 1.0.0
381
- *
382
- * @return string
383
- */
384
- public function get_admin_page_url() {
385
- return add_query_arg(
386
- 'page',
387
- self::SLUG,
388
- admin_url( 'options-general.php' )
389
- );
390
- }
391
-
392
- /**
393
- * Remove all non-WP Mail SMTP plugin notices from plugin pages.
394
- *
395
- * @since 1.0.0
396
- */
397
- public function hide_unrelated_notices() {
398
-
399
- // Bail if we're not on a our screen or page.
400
- if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], self::SLUG ) === false ) {
401
- return;
402
- }
403
-
404
- global $wp_filter;
405
-
406
- if ( ! empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) {
407
- foreach ( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) {
408
- foreach ( $hooks as $name => $arr ) {
409
- if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
410
- unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
411
- continue;
412
- }
413
- if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
414
- continue;
415
- }
416
- if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
417
- unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
418
- }
419
- }
420
- }
421
- }
422
-
423
- if ( ! empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) {
424
- foreach ( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) {
425
- foreach ( $hooks as $name => $arr ) {
426
- if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
427
- unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
428
- continue;
429
- }
430
- if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
431
- continue;
432
- }
433
- if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
434
- unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
435
- }
436
- }
437
- }
438
- }
439
-
440
- if ( ! empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) {
441
- foreach ( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) {
442
- foreach ( $hooks as $name => $arr ) {
443
- if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
444
- unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
445
- continue;
446
- }
447
- if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
448
- continue;
449
- }
450
- if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
451
- unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
452
- }
453
- }
454
- }
455
- }
456
- }
457
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin;
4
+
5
+ use WPMailSMTP\WP;
6
+
7
+ /**
8
+ * Class Area registers and process all wp-admin display functionality.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Area {
13
+
14
+ /**
15
+ * @var string Slug of the admin area page.
16
+ */
17
+ const SLUG = 'wp-mail-smtp';
18
+
19
+ /**
20
+ * @var string Admin page unique hook.
21
+ */
22
+ public $hook;
23
+
24
+ /**
25
+ * @var PageAbstract[]
26
+ */
27
+ private $pages;
28
+
29
+ /**
30
+ * Area constructor.
31
+ *
32
+ * @since 1.0.0
33
+ */
34
+ public function __construct() {
35
+ $this->hooks();
36
+ }
37
+
38
+ /**
39
+ * Assign all hooks to proper places.
40
+ *
41
+ * @since 1.0.0
42
+ */
43
+ protected function hooks() {
44
+
45
+ // Add the Settings link to a plugin on Plugins page.
46
+ add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_link' ), 10, 2 );
47
+
48
+ // Add the options page.
49
+ add_action( 'admin_menu', array( $this, 'add_admin_options_page' ) );
50
+
51
+ // Admin footer text.
52
+ add_filter( 'admin_footer_text', array( $this, 'get_admin_footer' ), 1, 2 );
53
+
54
+ // Enqueue admin area scripts and styles.
55
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
56
+
57
+ // Process the admin page forms actions.
58
+ add_action( 'admin_init', array( $this, 'process_actions' ) );
59
+
60
+ // Display custom notices based on the error/success codes.
61
+ add_action( 'admin_init', array( $this, 'display_custom_auth_notices' ) );
62
+
63
+ // Outputs the plugin admin header.
64
+ add_action( 'in_admin_header', array( $this, 'display_admin_header' ), 100 );
65
+
66
+ // Hide all unrelated to the plugin notices on the plugin admin pages.
67
+ add_action( 'admin_print_scripts', array( $this, 'hide_unrelated_notices' ) );
68
+ }
69
+
70
+ /**
71
+ * Display custom notices based on the error/success codes.
72
+ *
73
+ * @since 1.0.0
74
+ */
75
+ public function display_custom_auth_notices() {
76
+
77
+ $error = isset( $_GET['error'] ) ? $_GET['error'] : '';
78
+ $success = isset( $_GET['success'] ) ? $_GET['success'] : '';
79
+
80
+ if ( empty( $error ) && empty( $success ) ) {
81
+ return;
82
+ }
83
+
84
+ switch ( $error ) {
85
+ case 'google_access_denied':
86
+ WP::add_admin_notice(
87
+ /* translators: %s - error code, returned by Google API. */
88
+ sprintf( esc_html__( 'There was an error while processing the authentication request: %s. Please try again.', 'wp-mail-smtp' ), '<code>' . $error . '</code>' ),
89
+ WP::ADMIN_NOTICE_ERROR
90
+ );
91
+ break;
92
+
93
+ case 'google_no_code_scope':
94
+ WP::add_admin_notice(
95
+ esc_html__( 'There was an error while processing the authentication request. Please try again.', 'wp-mail-smtp' ),
96
+ WP::ADMIN_NOTICE_ERROR
97
+ );
98
+ break;
99
+
100
+ case 'google_no_clients':
101
+ WP::add_admin_notice(
102
+ esc_html__( 'There was an error while processing the authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.', 'wp-mail-smtp' ),
103
+ WP::ADMIN_NOTICE_ERROR
104
+ );
105
+ break;
106
+ }
107
+
108
+ switch ( $success ) {
109
+ case 'google_site_linked':
110
+ WP::add_admin_notice(
111
+ esc_html__( 'You have successfully linked the current site with your Google API project. Now you can start sending emails through Google.', 'wp-mail-smtp' ),
112
+ WP::ADMIN_NOTICE_SUCCESS
113
+ );
114
+ break;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Add admin area menu item.
120
+ *
121
+ * @since 1.0.0
122
+ */
123
+ public function add_admin_options_page() {
124
+
125
+ $this->hook = add_options_page(
126
+ esc_html__( 'WP Mail SMTP Options', 'wp-mail-smtp' ),
127
+ esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
128
+ 'manage_options',
129
+ self::SLUG,
130
+ array( $this, 'display' )
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Enqueue admin area scripts and styles.
136
+ *
137
+ * @since 1.0.0
138
+ *
139
+ * @param string $hook
140
+ */
141
+ public function enqueue_assets( $hook ) {
142
+
143
+ if ( $hook !== $this->hook ) {
144
+ return;
145
+ }
146
+
147
+ wp_enqueue_style(
148
+ 'wp-mail-smtp-admin',
149
+ wp_mail_smtp()->plugin_url . '/assets/css/smtp-admin.min.css',
150
+ false,
151
+ WPMS_PLUGIN_VER
152
+ );
153
+
154
+ wp_enqueue_script(
155
+ 'wp-mail-smtp-admin',
156
+ wp_mail_smtp()->plugin_url . '/assets/js/smtp-admin' . WP::asset_min() . '.js',
157
+ array( 'jquery' ),
158
+ WPMS_PLUGIN_VER
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Outputs the plugin admin header.
164
+ *
165
+ * @since 1.0.0
166
+ */
167
+ public function display_admin_header() {
168
+
169
+ // Bail if we're not on a plugin page.
170
+ if ( ! $this->is_admin_page() ) {
171
+ return;
172
+ }
173
+ ?>
174
+
175
+ <div id="wp-mail-smtp-header">
176
+ <!--suppress HtmlUnknownTarget -->
177
+ <img class="wp-mail-smtp-header-logo" src="<?php echo wp_mail_smtp()->plugin_url; ?>/assets/images/logo.png" alt="WP Mail SMTP"/>
178
+ </div>
179
+
180
+ <?php
181
+ }
182
+
183
+ /**
184
+ * Display a text to ask users to review the plugin on WP.org.
185
+ *
186
+ * @since 1.0.0
187
+ *
188
+ * @param string $text
189
+ *
190
+ * @return string
191
+ */
192
+ public function get_admin_footer( $text ) {
193
+
194
+ if ( $this->is_admin_page() ) {
195
+ $url = 'https://wordpress.org/support/plugin/wp-mail-smtp/reviews/?filter=5#new-post';
196
+
197
+ $text = sprintf(
198
+ /* translators: %1$s - WP.org link; %2$s - same WP.org link. */
199
+ __( 'Please rate <strong>WP Mail SMTP</strong> <a href="%1$s" target="_blank" rel="noopener noreferrer">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%2$s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the WP Mail SMTP team!', 'wp-mail-smtp' ),
200
+ $url,
201
+ $url
202
+ );
203
+ }
204
+
205
+ return $text;
206
+ }
207
+
208
+ /**
209
+ * Display content of the admin area page.
210
+ *
211
+ * @since 1.0.0
212
+ */
213
+ public function display() {
214
+ ?>
215
+
216
+ <div class="wrap" id="wp-mail-smtp">
217
+
218
+ <div class="wp-mail-smtp-page-title">
219
+ <?php
220
+ foreach ( $this->get_pages() as $page_slug => $page ) :
221
+ $label = $page->get_label();
222
+ if ( empty( $label ) ) {
223
+ continue;
224
+ }
225
+ $class = $page_slug === $this->get_current_tab() ? 'class="active"' : '';
226
+ ?>
227
+
228
+ <a href="<?php echo $page->get_link(); ?>" <?php echo $class; ?>><?php echo $label; ?></a>
229
+
230
+ <?php endforeach; ?>
231
+ </div>
232
+
233
+ <div class="wp-mail-smtp-page wp-mail-smtp-tab-<?php echo $this->get_current_tab(); ?>">
234
+ <h1 class="screen-reader-text"><?php echo $this->get_current_tab_title(); ?></h1>
235
+
236
+ <?php $this->display_current_tab_content(); ?>
237
+ </div>
238
+
239
+ </div>
240
+
241
+ <?php
242
+ }
243
+
244
+ /**
245
+ * Get the current tab title.
246
+ *
247
+ * @since 1.0.0
248
+ */
249
+ public function display_current_tab_content() {
250
+
251
+ if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
252
+ return;
253
+ }
254
+
255
+ $this->pages[ $this->get_current_tab() ]->display();
256
+ }
257
+
258
+ /**
259
+ * Get the current admin area tab.
260
+ *
261
+ * @since 1.0.0
262
+ *
263
+ * @return string
264
+ */
265
+ protected function get_current_tab() {
266
+
267
+ $current = '';
268
+
269
+ if ( $this->is_admin_page() ) {
270
+ $current = ! empty( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings';
271
+ }
272
+
273
+ return $current;
274
+ }
275
+
276
+ /**
277
+ * Get the array of default registered tabs for plugin admin area.
278
+ *
279
+ * @since 1.0.0
280
+ *
281
+ * @return \WPMailSMTP\Admin\PageAbstract[]
282
+ */
283
+ public function get_pages() {
284
+
285
+ if ( empty( $this->pages ) ) {
286
+ $this->pages = array(
287
+ 'settings' => new Pages\Settings(),
288
+ 'test' => new Pages\Test(),
289
+ 'misc' => new Pages\Misc(),
290
+ 'auth' => new Pages\Auth(),
291
+ );
292
+ }
293
+
294
+ return apply_filters( 'wp_mail_smtp_admin_get_pages', $this->pages );
295
+ }
296
+
297
+ /**
298
+ * Get the current tab title.
299
+ *
300
+ * @since 1.0.0
301
+ *
302
+ * @return string
303
+ */
304
+ public function get_current_tab_title() {
305
+
306
+ if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
307
+ return '';
308
+ }
309
+
310
+ return $this->pages[ $this->get_current_tab() ]->get_title();
311
+ }
312
+
313
+ /**
314
+ * Check whether we are on an admin page.
315
+ *
316
+ * @since 1.0.0
317
+ *
318
+ * @return bool
319
+ */
320
+ public function is_admin_page() {
321
+
322
+ $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
323
+
324
+ return self::SLUG === $page;
325
+ }
326
+
327
+ /**
328
+ * All possible plugin forms manipulation will be done here.
329
+ *
330
+ * @since 1.0.0
331
+ */
332
+ public function process_actions() {
333
+
334
+ // Allow to process only own tabs.
335
+ if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
336
+ return;
337
+ }
338
+
339
+ // Process POST only if it exists.
340
+ if ( ! empty( $_POST ) ) {
341
+ if ( ! empty( $_POST['wp-mail-smtp'] ) ) {
342
+ $post = $_POST['wp-mail-smtp'];
343
+ } else {
344
+ $post = array();
345
+ }
346
+
347
+ $this->pages[ $this->get_current_tab() ]->process_post( $post );
348
+ }
349
+
350
+ // This won't do anything for most pages.
351
+ $this->pages[ $this->get_current_tab() ]->process_auth();
352
+ }
353
+
354
+ /**
355
+ * Add a link to Settings page of a plugin on Plugins page.
356
+ *
357
+ * @since 1.0.0
358
+ *
359
+ * @param array $links
360
+ * @param string $file
361
+ *
362
+ * @return mixed
363
+ */
364
+ public function add_plugin_action_link( $links, $file ) {
365
+
366
+ if ( strpos( $file, 'wp-mail-smtp' ) === false ) {
367
+ return $links;
368
+ }
369
+
370
+ $settings_link = '<a href="' . $this->get_admin_page_url() . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
371
+
372
+ array_unshift( $links, $settings_link );
373
+
374
+ return $links;
375
+ }
376
+
377
+ /**
378
+ * Get plugin admin area page URL.
379
+ *
380
+ * @since 1.0.0
381
+ *
382
+ * @return string
383
+ */
384
+ public function get_admin_page_url() {
385
+ return add_query_arg(
386
+ 'page',
387
+ self::SLUG,
388
+ admin_url( 'options-general.php' )
389
+ );
390
+ }
391
+
392
+ /**
393
+ * Remove all non-WP Mail SMTP plugin notices from plugin pages.
394
+ *
395
+ * @since 1.0.0
396
+ */
397
+ public function hide_unrelated_notices() {
398
+
399
+ // Bail if we're not on a our screen or page.
400
+ if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], self::SLUG ) === false ) {
401
+ return;
402
+ }
403
+
404
+ global $wp_filter;
405
+
406
+ if ( ! empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) {
407
+ foreach ( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) {
408
+ foreach ( $hooks as $name => $arr ) {
409
+ if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
410
+ unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
411
+ continue;
412
+ }
413
+ if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
414
+ continue;
415
+ }
416
+ if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
417
+ unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
418
+ }
419
+ }
420
+ }
421
+ }
422
+
423
+ if ( ! empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) {
424
+ foreach ( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) {
425
+ foreach ( $hooks as $name => $arr ) {
426
+ if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
427
+ unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
428
+ continue;
429
+ }
430
+ if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
431
+ continue;
432
+ }
433
+ if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
434
+ unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
435
+ }
436
+ }
437
+ }
438
+ }
439
+
440
+ if ( ! empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) {
441
+ foreach ( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) {
442
+ foreach ( $hooks as $name => $arr ) {
443
+ if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) {
444
+ unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
445
+ continue;
446
+ }
447
+ if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'wpmailsmtp' ) !== false ) {
448
+ continue;
449
+ }
450
+ if ( ! empty( $name ) && strpos( strtolower( $name ), 'wpmailsmtp' ) === false ) {
451
+ unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
452
+ }
453
+ }
454
+ }
455
+ }
456
+ }
457
+ }
src/Admin/PageAbstract.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin;
4
-
5
- /**
6
- * Class PageAbstract.
7
- *
8
- * @since 1.0.0
9
- */
10
- abstract class PageAbstract implements PageInterface {
11
-
12
- /**
13
- * @var string Slug of a tab.
14
- */
15
- protected $slug;
16
-
17
- /**
18
- * @inheritdoc
19
- */
20
- public function get_link() {
21
- return esc_url(
22
- add_query_arg(
23
- 'tab',
24
- $this->slug,
25
- admin_url( 'options-general.php?page=' . Area::SLUG )
26
- )
27
- );
28
- }
29
-
30
- /**
31
- * Process tab form submission ($_POST ).
32
- *
33
- * @since 1.0.0
34
- *
35
- * @param array $data $_POST data specific for the plugin.
36
- */
37
- public function process_post( $data ) {
38
- }
39
-
40
- /**
41
- * Process tab & mailer specific Auth actions.
42
- *
43
- * @since 1.0.0
44
- */
45
- public function process_auth() {
46
- }
47
-
48
- /**
49
- * Print the nonce field for a specific tab.
50
- *
51
- * @since 1.0.0
52
- */
53
- public function wp_nonce_field() {
54
- wp_nonce_field( Area::SLUG . '-' . $this->slug );
55
- }
56
-
57
- /**
58
- * Make sure that a user was referred from plugin admin page.
59
- * To avoid security problems.
60
- *
61
- * @since 1.0.0
62
- */
63
- public function check_admin_referer() {
64
- check_admin_referer( Area::SLUG . '-' . $this->slug );
65
- }
66
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin;
4
+
5
+ /**
6
+ * Class PageAbstract.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ abstract class PageAbstract implements PageInterface {
11
+
12
+ /**
13
+ * @var string Slug of a tab.
14
+ */
15
+ protected $slug;
16
+
17
+ /**
18
+ * @inheritdoc
19
+ */
20
+ public function get_link() {
21
+ return esc_url(
22
+ add_query_arg(
23
+ 'tab',
24
+ $this->slug,
25
+ admin_url( 'options-general.php?page=' . Area::SLUG )
26
+ )
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Process tab form submission ($_POST ).
32
+ *
33
+ * @since 1.0.0
34
+ *
35
+ * @param array $data $_POST data specific for the plugin.
36
+ */
37
+ public function process_post( $data ) {
38
+ }
39
+
40
+ /**
41
+ * Process tab & mailer specific Auth actions.
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ public function process_auth() {
46
+ }
47
+
48
+ /**
49
+ * Print the nonce field for a specific tab.
50
+ *
51
+ * @since 1.0.0
52
+ */
53
+ public function wp_nonce_field() {
54
+ wp_nonce_field( Area::SLUG . '-' . $this->slug );
55
+ }
56
+
57
+ /**
58
+ * Make sure that a user was referred from plugin admin page.
59
+ * To avoid security problems.
60
+ *
61
+ * @since 1.0.0
62
+ */
63
+ public function check_admin_referer() {
64
+ check_admin_referer( Area::SLUG . '-' . $this->slug );
65
+ }
66
+ }
src/Admin/PageInterface.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin;
4
-
5
- /**
6
- * Class PageInterface defines what should be in each page class.
7
- *
8
- * @since 1.0.0
9
- */
10
- interface PageInterface {
11
-
12
- /**
13
- * URL to a tab.
14
- *
15
- * @since 1.0.0
16
- *
17
- * @return string
18
- */
19
- public function get_link();
20
-
21
- /**
22
- * Title of a tab.
23
- *
24
- * @since 1.0.0
25
- *
26
- * @return string
27
- */
28
- public function get_title();
29
-
30
- /**
31
- * Link label of a tab.
32
- *
33
- * @since 1.0.0
34
- *
35
- * @return string
36
- */
37
- public function get_label();
38
-
39
- /**
40
- * Tab content.
41
- *
42
- * @since 1.0.0
43
- */
44
- public function display();
45
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin;
4
+
5
+ /**
6
+ * Class PageInterface defines what should be in each page class.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ interface PageInterface {
11
+
12
+ /**
13
+ * URL to a tab.
14
+ *
15
+ * @since 1.0.0
16
+ *
17
+ * @return string
18
+ */
19
+ public function get_link();
20
+
21
+ /**
22
+ * Title of a tab.
23
+ *
24
+ * @since 1.0.0
25
+ *
26
+ * @return string
27
+ */
28
+ public function get_title();
29
+
30
+ /**
31
+ * Link label of a tab.
32
+ *
33
+ * @since 1.0.0
34
+ *
35
+ * @return string
36
+ */
37
+ public function get_label();
38
+
39
+ /**
40
+ * Tab content.
41
+ *
42
+ * @since 1.0.0
43
+ */
44
+ public function display();
45
+ }
src/Admin/Pages/Auth.php CHANGED
@@ -1,59 +1,59 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin\Pages;
4
-
5
- use WPMailSMTP\Options;
6
- use WPMailSMTP\Providers\AuthAbstract;
7
-
8
- /**
9
- * Class Auth.
10
- *
11
- * @since 1.0.0
12
- */
13
- class Auth {
14
-
15
- /**
16
- * @var string Slug of a tab.
17
- */
18
- protected $slug = 'auth';
19
-
20
- /**
21
- * Launch mailer specific Auth logic.
22
- *
23
- * @since 1.0.0
24
- */
25
- public function process_auth() {
26
-
27
- $auth = wp_mail_smtp()->get_providers()->get_auth( Options::init()->get( 'mail', 'mailer' ) );
28
-
29
- if ( $auth && $auth instanceof AuthAbstract ) {
30
- $auth->process();
31
- }
32
- }
33
-
34
- /**
35
- * Return nothing, as we don't need this functionality.
36
- *
37
- * @since 1.0.0
38
- */
39
- public function get_label() {
40
- return '';
41
- }
42
-
43
- /**
44
- * Return nothing, as we don't need this functionality.
45
- *
46
- * @since 1.0.0
47
- */
48
- public function get_title() {
49
- return '';
50
- }
51
-
52
- /**
53
- * Do nothing, as we don't need this functionality.
54
- *
55
- * @since 1.0.0
56
- */
57
- public function display() {
58
- }
59
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin\Pages;
4
+
5
+ use WPMailSMTP\Options;
6
+ use WPMailSMTP\Providers\AuthAbstract;
7
+
8
+ /**
9
+ * Class Auth.
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Auth {
14
+
15
+ /**
16
+ * @var string Slug of a tab.
17
+ */
18
+ protected $slug = 'auth';
19
+
20
+ /**
21
+ * Launch mailer specific Auth logic.
22
+ *
23
+ * @since 1.0.0
24
+ */
25
+ public function process_auth() {
26
+
27
+ $auth = wp_mail_smtp()->get_providers()->get_auth( Options::init()->get( 'mail', 'mailer' ) );
28
+
29
+ if ( $auth && $auth instanceof AuthAbstract ) {
30
+ $auth->process();
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Return nothing, as we don't need this functionality.
36
+ *
37
+ * @since 1.0.0
38
+ */
39
+ public function get_label() {
40
+ return '';
41
+ }
42
+
43
+ /**
44
+ * Return nothing, as we don't need this functionality.
45
+ *
46
+ * @since 1.0.0
47
+ */
48
+ public function get_title() {
49
+ return '';
50
+ }
51
+
52
+ /**
53
+ * Do nothing, as we don't need this functionality.
54
+ *
55
+ * @since 1.0.0
56
+ */
57
+ public function display() {
58
+ }
59
+ }
src/Admin/Pages/Misc.php CHANGED
@@ -1,99 +1,99 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin\Pages;
4
-
5
- use WPMailSMTP\Admin\PageAbstract;
6
- use WPMailSMTP\Options;
7
- use WPMailSMTP\WP;
8
-
9
- /**
10
- * Class Misc is part of Area, displays different plugin-related settings of the plugin (not related to emails).
11
- *
12
- * @since 1.0.0
13
- */
14
- class Misc extends PageAbstract {
15
- /**
16
- * @var string Slug of a tab.
17
- */
18
- protected $slug = 'misc';
19
-
20
- /**
21
- * @inheritdoc
22
- */
23
- public function get_label() {
24
- return esc_html__( 'Misc', 'wp-mail-smtp' );
25
- }
26
-
27
- /**
28
- * @inheritdoc
29
- */
30
- public function get_title() {
31
- return $this->get_label();
32
- }
33
-
34
- /**
35
- * @inheritdoc
36
- */
37
- public function display() {
38
-
39
- $options = new Options();
40
- ?>
41
-
42
- <form method="POST" action="">
43
- <?php $this->wp_nonce_field(); ?>
44
-
45
- <!-- General Section Title -->
46
- <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
47
- <div class="wp-mail-smtp-setting-field">
48
- <h2><?php esc_html_e( 'General', 'wp-mail-smtp' ); ?></h2>
49
- </div>
50
- </div>
51
-
52
- <!-- Hide Announcements -->
53
- <div id="wp-mail-smtp-setting-row-am_notifications_hidden" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
54
- <div class="wp-mail-smtp-setting-label">
55
- <label for="wp-mail-smtp-setting-am_notifications_hidden"><?php esc_html_e( 'Hide Announcements', 'wp-mail-smtp' ); ?></label>
56
- </div>
57
- <div class="wp-mail-smtp-setting-field">
58
- <input name="wp-mail-smtp[general][am_notifications_hidden]" type="checkbox"
59
- value="true" <?php checked( true, $options->get( 'general', 'am_notifications_hidden' ) ); ?>
60
- id="wp-mail-smtp-setting-am_notifications_hidden"
61
- />
62
- <label for="wp-mail-smtp-setting-am_notifications_hidden"><?php esc_html_e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?></label>
63
- </div>
64
- </div>
65
-
66
- <p class="wp-mail-smtp-submit">
67
- <button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?></button>
68
- </p>
69
-
70
- </form>
71
-
72
- <?php
73
- }
74
-
75
- /**
76
- * @inheritdoc
77
- */
78
- public function process_post( $data ) {
79
-
80
- $this->check_admin_referer();
81
-
82
- $options = new Options();
83
-
84
- // Unchecked checkbox doesn't exist in $_POST, so we need to ensure we actually have it.
85
- if ( empty( $data['general']['am_notifications_hidden'] ) ) {
86
- $data['general']['am_notifications_hidden'] = false;
87
- }
88
-
89
- $to_save = array_merge( $options->get_all(), $data );
90
-
91
- // All the sanitization is done there.
92
- $options->set( $to_save );
93
-
94
- WP::add_admin_notice(
95
- esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
96
- WP::ADMIN_NOTICE_SUCCESS
97
- );
98
- }
99
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin\Pages;
4
+
5
+ use WPMailSMTP\Admin\PageAbstract;
6
+ use WPMailSMTP\Options;
7
+ use WPMailSMTP\WP;
8
+
9
+ /**
10
+ * Class Misc is part of Area, displays different plugin-related settings of the plugin (not related to emails).
11
+ *
12
+ * @since 1.0.0
13
+ */
14
+ class Misc extends PageAbstract {
15
+ /**
16
+ * @var string Slug of a tab.
17
+ */
18
+ protected $slug = 'misc';
19
+
20
+ /**
21
+ * @inheritdoc
22
+ */
23
+ public function get_label() {
24
+ return esc_html__( 'Misc', 'wp-mail-smtp' );
25
+ }
26
+
27
+ /**
28
+ * @inheritdoc
29
+ */
30
+ public function get_title() {
31
+ return $this->get_label();
32
+ }
33
+
34
+ /**
35
+ * @inheritdoc
36
+ */
37
+ public function display() {
38
+
39
+ $options = new Options();
40
+ ?>
41
+
42
+ <form method="POST" action="">
43
+ <?php $this->wp_nonce_field(); ?>
44
+
45
+ <!-- General Section Title -->
46
+ <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
47
+ <div class="wp-mail-smtp-setting-field">
48
+ <h2><?php esc_html_e( 'General', 'wp-mail-smtp' ); ?></h2>
49
+ </div>
50
+ </div>
51
+
52
+ <!-- Hide Announcements -->
53
+ <div id="wp-mail-smtp-setting-row-am_notifications_hidden" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
54
+ <div class="wp-mail-smtp-setting-label">
55
+ <label for="wp-mail-smtp-setting-am_notifications_hidden"><?php esc_html_e( 'Hide Announcements', 'wp-mail-smtp' ); ?></label>
56
+ </div>
57
+ <div class="wp-mail-smtp-setting-field">
58
+ <input name="wp-mail-smtp[general][am_notifications_hidden]" type="checkbox"
59
+ value="true" <?php checked( true, $options->get( 'general', 'am_notifications_hidden' ) ); ?>
60
+ id="wp-mail-smtp-setting-am_notifications_hidden"
61
+ />
62
+ <label for="wp-mail-smtp-setting-am_notifications_hidden"><?php esc_html_e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?></label>
63
+ </div>
64
+ </div>
65
+
66
+ <p class="wp-mail-smtp-submit">
67
+ <button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?></button>
68
+ </p>
69
+
70
+ </form>
71
+
72
+ <?php
73
+ }
74
+
75
+ /**
76
+ * @inheritdoc
77
+ */
78
+ public function process_post( $data ) {
79
+
80
+ $this->check_admin_referer();
81
+
82
+ $options = new Options();
83
+
84
+ // Unchecked checkbox doesn't exist in $_POST, so we need to ensure we actually have it.
85
+ if ( empty( $data['general']['am_notifications_hidden'] ) ) {
86
+ $data['general']['am_notifications_hidden'] = false;
87
+ }
88
+
89
+ $to_save = array_merge( $options->get_all(), $data );
90
+
91
+ // All the sanitization is done there.
92
+ $options->set( $to_save );
93
+
94
+ WP::add_admin_notice(
95
+ esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
96
+ WP::ADMIN_NOTICE_SUCCESS
97
+ );
98
+ }
99
+ }
src/Admin/Pages/Settings.php CHANGED
@@ -1,250 +1,250 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin\Pages;
4
-
5
- use WPMailSMTP\Admin\PageAbstract;
6
- use WPMailSMTP\Debug;
7
- use WPMailSMTP\Options;
8
- use WPMailSMTP\WP;
9
-
10
- /**
11
- * Class Settings is part of Area, displays general settings of the plugin.
12
- *
13
- * @since 1.0.0
14
- */
15
- class Settings extends PageAbstract {
16
-
17
- /**
18
- * @var string Slug of a tab.
19
- */
20
- protected $slug = 'settings';
21
-
22
- /**
23
- * @inheritdoc
24
- */
25
- public function get_label() {
26
- return esc_html__( 'Settings', 'wp-mail-smtp' );
27
- }
28
-
29
- /**
30
- * @inheritdoc
31
- */
32
- public function get_title() {
33
- return $this->get_label();
34
- }
35
-
36
- /**
37
- * @inheritdoc
38
- */
39
- public function display() {
40
-
41
- $options = new Options();
42
- $mailer = $options->get( 'mail', 'mailer' );
43
- ?>
44
-
45
- <form method="POST" action="">
46
- <?php $this->wp_nonce_field(); ?>
47
-
48
- <!-- Mail Section Title -->
49
- <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
50
- <div class="wp-mail-smtp-setting-field">
51
- <h2><?php esc_html_e( 'Mail', 'wp-mail-smtp' ); ?></h2>
52
- </div>
53
- </div>
54
-
55
- <!-- From Email -->
56
- <div id="wp-mail-smtp-setting-row-from_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
57
- <div class="wp-mail-smtp-setting-label">
58
- <label for="wp-mail-smtp-setting-from_email"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
59
- </div>
60
- <div class="wp-mail-smtp-setting-field">
61
- <input name="wp-mail-smtp[mail][from_email]" type="email"
62
- value="<?php echo esc_attr( $options->get( 'mail', 'from_email' ) ); ?>"
63
- <?php echo $options->is_const_defined( 'mail', 'from_email' ) ? 'disabled' : ''; ?>
64
- id="wp-mail-smtp-setting-from_email" spellcheck="false"
65
- />
66
- <p class="desc">
67
- <?php esc_html_e( 'You can specify the email address that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
68
- <?php
69
- printf(
70
- /* translators: %s - default email address. */
71
- esc_html__( 'If you leave this blank, the default one will be used: %s.', 'wp-mail-smtp' ),
72
- '<code>' . wp_mail_smtp()->get_processor()->get_default_email() . '</code>'
73
- );
74
- ?>
75
- </p>
76
- <p class="desc">
77
- <?php esc_html_e( 'Please note if you are sending using an email provider (Gmail, Yahoo, Hotmail, Outlook.com, etc) this setting should be your email address for that account.', 'wp-mail-smtp' ); ?>
78
- </p>
79
- </div>
80
- </div>
81
-
82
- <!-- From Name -->
83
- <div id="wp-mail-smtp-setting-row-from_name" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
84
- <div class="wp-mail-smtp-setting-label">
85
- <label for="wp-mail-smtp-setting-from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
86
- </div>
87
- <div class="wp-mail-smtp-setting-field">
88
- <input name="wp-mail-smtp[mail][from_name]" type="text"
89
- value="<?php echo esc_attr( $options->get( 'mail', 'from_name' ) ); ?>"
90
- <?php echo $options->is_const_defined( 'mail', 'from_name' ) ? 'disabled' : ''; ?>
91
- id="wp-mail-smtp-setting-from_name" spellcheck="false"
92
- />
93
- <p class="desc">
94
- <?php esc_html_e( 'You can specify the name that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
95
- <?php
96
- printf(
97
- /* translators: %s - WordPress. */
98
- esc_html__( 'If you leave this blank, the emails will be sent from %s.', 'wp-mail-smtp' ),
99
- '<code>WordPress</code>'
100
- );
101
- ?>
102
- </p>
103
- </div>
104
- </div>
105
-
106
- <!-- Mailer -->
107
- <div id="wp-mail-smtp-setting-row-mailer" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-mailer wp-mail-smtp-clear">
108
- <div class="wp-mail-smtp-setting-label">
109
- <label for="wp-mail-smtp-setting-mailer"><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></label>
110
- </div>
111
- <div class="wp-mail-smtp-setting-field">
112
- <div class="wp-mail-smtp-mailers">
113
-
114
- <?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
115
-
116
- <?php
117
- if ( ! $options->is_pepipost_active() && $provider->get_slug() === 'pepipost' ) {
118
- continue;
119
- }
120
- ?>
121
-
122
- <div class="wp-mail-smtp-mailer <?php echo $mailer === $provider->get_slug() ? 'active' : ''; ?>">
123
- <div class="wp-mail-smtp-mailer-image">
124
- <img src="<?php echo esc_url( $provider->get_logo_url() ); ?>"
125
- alt="<?php echo esc_attr( $provider->get_title() ); ?>">
126
- </div>
127
-
128
- <div class="wp-mail-smtp-mailer-text">
129
- <input id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
130
- type="radio" name="wp-mail-smtp[mail][mailer]"
131
- value="<?php echo esc_attr( $provider->get_slug() ); ?>"
132
- <?php checked( $provider->get_slug(), $mailer ); ?>
133
- <?php echo $options->is_const_defined( 'mail', 'mailer' ) ? 'disabled' : ''; ?>
134
- />
135
- <label for="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"><?php echo $provider->get_title(); ?></label>
136
- </div>
137
- </div>
138
-
139
- <?php endforeach; ?>
140
-
141
- </div>
142
- </div>
143
- </div>
144
-
145
- <!-- Return Path -->
146
- <div id="wp-mail-smtp-setting-row-return_path" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
147
- <div class="wp-mail-smtp-setting-label">
148
- <label for="wp-mail-smtp-setting-return_path"><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></label>
149
- </div>
150
- <div class="wp-mail-smtp-setting-field">
151
- <input name="wp-mail-smtp[mail][return_path]" type="checkbox"
152
- value="true" <?php checked( true, $options->get( 'mail', 'return_path' ) ); ?>
153
- <?php echo $options->is_const_defined( 'mail', 'return_path' ) ? 'disabled' : ''; ?>
154
- id="wp-mail-smtp-setting-return_path"
155
- />
156
- <label for="wp-mail-smtp-setting-return_path">
157
- <?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?>
158
- </label>
159
- <p class="desc">
160
- <?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?><br/>
161
- <?php esc_html_e( 'If unchecked bounce messages may be lost.', 'wp-mail-smtp' ); ?>
162
- </p>
163
- </div>
164
- </div>
165
-
166
- <!-- Mailer Options -->
167
- <div class="wp-mail-smtp-mailer-options">
168
- <?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
169
-
170
- <div class="wp-mail-smtp-mailer-option wp-mail-smtp-mailer-option-<?php echo esc_attr( $provider->get_slug() ); ?> <?php echo $mailer === $provider->get_slug() ? 'active' : 'hidden'; ?>">
171
-
172
- <!-- Mailer Option Title -->
173
- <?php $provider_desc = $provider->get_description(); ?>
174
- <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading <?php echo empty( $provider_desc ) ? 'no-desc' : ''; ?>" id="wp-mail-smtp-setting-row-email-heading">
175
- <div class="wp-mail-smtp-setting-field">
176
- <h2><?php echo $provider->get_title(); ?></h2>
177
- <?php if ( ! empty( $provider_desc ) ) : ?>
178
- <p class="desc"><?php echo $provider_desc; ?></p>
179
- <?php endif; ?>
180
- </div>
181
- </div>
182
-
183
- <?php $provider->display_options(); ?>
184
- </div>
185
-
186
- <?php endforeach; ?>
187
-
188
- </div>
189
-
190
- <p class="wp-mail-smtp-submit">
191
- <button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?></button>
192
- </p>
193
-
194
- </form>
195
-
196
- <?php
197
- }
198
-
199
- /**
200
- * @inheritdoc
201
- */
202
- public function process_post( $data ) {
203
-
204
- $this->check_admin_referer();
205
-
206
- $options = new Options();
207
- $old_opt = $options->get_all();
208
-
209
- // Remove all debug messages when switching mailers.
210
- if ( $old_opt['mail']['mailer'] !== $data['mail']['mailer'] ) {
211
- Debug::clear();
212
- }
213
-
214
- $to_redirect = false;
215
-
216
- // Old and new Gmail client id/secret values are different - we need to invalidate tokens and scroll to Auth button.
217
- if (
218
- $options->get( 'mail', 'mailer' ) === 'gmail' &&
219
- (
220
- $options->get( 'gmail', 'client_id' ) !== $data['gmail']['client_id'] ||
221
- $options->get( 'gmail', 'client_secret' ) !== $data['gmail']['client_secret']
222
- )
223
- ) {
224
- unset( $old_opt['gmail'] );
225
-
226
- if (
227
- ! empty( $data['gmail']['client_id'] ) &&
228
- ! empty( $data['gmail']['client_secret'] )
229
- ) {
230
- $to_redirect = true;
231
- }
232
- }
233
-
234
- // New gmail clients data will be added from new $data.
235
- $to_save = Options::array_merge_recursive( $old_opt, $data );
236
-
237
- // All the sanitization is done in Options class.
238
- $options->set( $to_save );
239
-
240
- if ( $to_redirect ) {
241
- wp_redirect( $_POST['_wp_http_referer'] . '#wp-mail-smtp-setting-row-gmail-authorize' );
242
- exit;
243
- }
244
-
245
- WP::add_admin_notice(
246
- esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
247
- WP::ADMIN_NOTICE_SUCCESS
248
- );
249
- }
250
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin\Pages;
4
+
5
+ use WPMailSMTP\Admin\PageAbstract;
6
+ use WPMailSMTP\Debug;
7
+ use WPMailSMTP\Options;
8
+ use WPMailSMTP\WP;
9
+
10
+ /**
11
+ * Class Settings is part of Area, displays general settings of the plugin.
12
+ *
13
+ * @since 1.0.0
14
+ */
15
+ class Settings extends PageAbstract {
16
+
17
+ /**
18
+ * @var string Slug of a tab.
19
+ */
20
+ protected $slug = 'settings';
21
+
22
+ /**
23
+ * @inheritdoc
24
+ */
25
+ public function get_label() {
26
+ return esc_html__( 'Settings', 'wp-mail-smtp' );
27
+ }
28
+
29
+ /**
30
+ * @inheritdoc
31
+ */
32
+ public function get_title() {
33
+ return $this->get_label();
34
+ }
35
+
36
+ /**
37
+ * @inheritdoc
38
+ */
39
+ public function display() {
40
+
41
+ $options = new Options();
42
+ $mailer = $options->get( 'mail', 'mailer' );
43
+ ?>
44
+
45
+ <form method="POST" action="">
46
+ <?php $this->wp_nonce_field(); ?>
47
+
48
+ <!-- Mail Section Title -->
49
+ <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
50
+ <div class="wp-mail-smtp-setting-field">
51
+ <h2><?php esc_html_e( 'Mail', 'wp-mail-smtp' ); ?></h2>
52
+ </div>
53
+ </div>
54
+
55
+ <!-- From Email -->
56
+ <div id="wp-mail-smtp-setting-row-from_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
57
+ <div class="wp-mail-smtp-setting-label">
58
+ <label for="wp-mail-smtp-setting-from_email"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
59
+ </div>
60
+ <div class="wp-mail-smtp-setting-field">
61
+ <input name="wp-mail-smtp[mail][from_email]" type="email"
62
+ value="<?php echo esc_attr( $options->get( 'mail', 'from_email' ) ); ?>"
63
+ <?php echo $options->is_const_defined( 'mail', 'from_email' ) ? 'disabled' : ''; ?>
64
+ id="wp-mail-smtp-setting-from_email" spellcheck="false"
65
+ />
66
+ <p class="desc">
67
+ <?php esc_html_e( 'You can specify the email address that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
68
+ <?php
69
+ printf(
70
+ /* translators: %s - default email address. */
71
+ esc_html__( 'If you leave this blank, the default one will be used: %s.', 'wp-mail-smtp' ),
72
+ '<code>' . wp_mail_smtp()->get_processor()->get_default_email() . '</code>'
73
+ );
74
+ ?>
75
+ </p>
76
+ <p class="desc">
77
+ <?php esc_html_e( 'Please note if you are sending using an email provider (Gmail, Yahoo, Hotmail, Outlook.com, etc) this setting should be your email address for that account.', 'wp-mail-smtp' ); ?>
78
+ </p>
79
+ </div>
80
+ </div>
81
+
82
+ <!-- From Name -->
83
+ <div id="wp-mail-smtp-setting-row-from_name" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
84
+ <div class="wp-mail-smtp-setting-label">
85
+ <label for="wp-mail-smtp-setting-from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
86
+ </div>
87
+ <div class="wp-mail-smtp-setting-field">
88
+ <input name="wp-mail-smtp[mail][from_name]" type="text"
89
+ value="<?php echo esc_attr( $options->get( 'mail', 'from_name' ) ); ?>"
90
+ <?php echo $options->is_const_defined( 'mail', 'from_name' ) ? 'disabled' : ''; ?>
91
+ id="wp-mail-smtp-setting-from_name" spellcheck="false"
92
+ />
93
+ <p class="desc">
94
+ <?php esc_html_e( 'You can specify the name that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
95
+ <?php
96
+ printf(
97
+ /* translators: %s - WordPress. */
98
+ esc_html__( 'If you leave this blank, the emails will be sent from %s.', 'wp-mail-smtp' ),
99
+ '<code>WordPress</code>'
100
+ );
101
+ ?>
102
+ </p>
103
+ </div>
104
+ </div>
105
+
106
+ <!-- Mailer -->
107
+ <div id="wp-mail-smtp-setting-row-mailer" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-mailer wp-mail-smtp-clear">
108
+ <div class="wp-mail-smtp-setting-label">
109
+ <label for="wp-mail-smtp-setting-mailer"><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></label>
110
+ </div>
111
+ <div class="wp-mail-smtp-setting-field">
112
+ <div class="wp-mail-smtp-mailers">
113
+
114
+ <?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
115
+
116
+ <?php
117
+ if ( ! $options->is_pepipost_active() && $provider->get_slug() === 'pepipost' ) {
118
+ continue;
119
+ }
120
+ ?>
121
+
122
+ <div class="wp-mail-smtp-mailer <?php echo $mailer === $provider->get_slug() ? 'active' : ''; ?>">
123
+ <div class="wp-mail-smtp-mailer-image">
124
+ <img src="<?php echo esc_url( $provider->get_logo_url() ); ?>"
125
+ alt="<?php echo esc_attr( $provider->get_title() ); ?>">
126
+ </div>
127
+
128
+ <div class="wp-mail-smtp-mailer-text">
129
+ <input id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
130
+ type="radio" name="wp-mail-smtp[mail][mailer]"
131
+ value="<?php echo esc_attr( $provider->get_slug() ); ?>"
132
+ <?php checked( $provider->get_slug(), $mailer ); ?>
133
+ <?php echo $options->is_const_defined( 'mail', 'mailer' ) ? 'disabled' : ''; ?>
134
+ />
135
+ <label for="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"><?php echo $provider->get_title(); ?></label>
136
+ </div>
137
+ </div>
138
+
139
+ <?php endforeach; ?>
140
+
141
+ </div>
142
+ </div>
143
+ </div>
144
+
145
+ <!-- Return Path -->
146
+ <div id="wp-mail-smtp-setting-row-return_path" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
147
+ <div class="wp-mail-smtp-setting-label">
148
+ <label for="wp-mail-smtp-setting-return_path"><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></label>
149
+ </div>
150
+ <div class="wp-mail-smtp-setting-field">
151
+ <input name="wp-mail-smtp[mail][return_path]" type="checkbox"
152
+ value="true" <?php checked( true, $options->get( 'mail', 'return_path' ) ); ?>
153
+ <?php echo $options->is_const_defined( 'mail', 'return_path' ) ? 'disabled' : ''; ?>
154
+ id="wp-mail-smtp-setting-return_path"
155
+ />
156
+ <label for="wp-mail-smtp-setting-return_path">
157
+ <?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?>
158
+ </label>
159
+ <p class="desc">
160
+ <?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?><br/>
161
+ <?php esc_html_e( 'If unchecked bounce messages may be lost.', 'wp-mail-smtp' ); ?>
162
+ </p>
163
+ </div>
164
+ </div>
165
+
166
+ <!-- Mailer Options -->
167
+ <div class="wp-mail-smtp-mailer-options">
168
+ <?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
169
+
170
+ <div class="wp-mail-smtp-mailer-option wp-mail-smtp-mailer-option-<?php echo esc_attr( $provider->get_slug() ); ?> <?php echo $mailer === $provider->get_slug() ? 'active' : 'hidden'; ?>">
171
+
172
+ <!-- Mailer Option Title -->
173
+ <?php $provider_desc = $provider->get_description(); ?>
174
+ <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading <?php echo empty( $provider_desc ) ? 'no-desc' : ''; ?>" id="wp-mail-smtp-setting-row-email-heading">
175
+ <div class="wp-mail-smtp-setting-field">
176
+ <h2><?php echo $provider->get_title(); ?></h2>
177
+ <?php if ( ! empty( $provider_desc ) ) : ?>
178
+ <p class="desc"><?php echo $provider_desc; ?></p>
179
+ <?php endif; ?>
180
+ </div>
181
+ </div>
182
+
183
+ <?php $provider->display_options(); ?>
184
+ </div>
185
+
186
+ <?php endforeach; ?>
187
+
188
+ </div>
189
+
190
+ <p class="wp-mail-smtp-submit">
191
+ <button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?></button>
192
+ </p>
193
+
194
+ </form>
195
+
196
+ <?php
197
+ }
198
+
199
+ /**
200
+ * @inheritdoc
201
+ */
202
+ public function process_post( $data ) {
203
+
204
+ $this->check_admin_referer();
205
+
206
+ $options = new Options();
207
+ $old_opt = $options->get_all();
208
+
209
+ // Remove all debug messages when switching mailers.
210
+ if ( $old_opt['mail']['mailer'] !== $data['mail']['mailer'] ) {
211
+ Debug::clear();
212
+ }
213
+
214
+ $to_redirect = false;
215
+
216
+ // Old and new Gmail client id/secret values are different - we need to invalidate tokens and scroll to Auth button.
217
+ if (
218
+ $options->get( 'mail', 'mailer' ) === 'gmail' &&
219
+ (
220
+ $options->get( 'gmail', 'client_id' ) !== $data['gmail']['client_id'] ||
221
+ $options->get( 'gmail', 'client_secret' ) !== $data['gmail']['client_secret']
222
+ )
223
+ ) {
224
+ unset( $old_opt['gmail'] );
225
+
226
+ if (
227
+ ! empty( $data['gmail']['client_id'] ) &&
228
+ ! empty( $data['gmail']['client_secret'] )
229
+ ) {
230
+ $to_redirect = true;
231
+ }
232
+ }
233
+
234
+ // New gmail clients data will be added from new $data.
235
+ $to_save = Options::array_merge_recursive( $old_opt, $data );
236
+
237
+ // All the sanitization is done in Options class.
238
+ $options->set( $to_save );
239
+
240
+ if ( $to_redirect ) {
241
+ wp_redirect( $_POST['_wp_http_referer'] . '#wp-mail-smtp-setting-row-gmail-authorize' );
242
+ exit;
243
+ }
244
+
245
+ WP::add_admin_notice(
246
+ esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
247
+ WP::ADMIN_NOTICE_SUCCESS
248
+ );
249
+ }
250
+ }
src/Admin/Pages/Test.php CHANGED
@@ -1,216 +1,216 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Admin\Pages;
4
-
5
- use WPMailSMTP\Debug;
6
- use WPMailSMTP\MailCatcher;
7
- use WPMailSMTP\Options;
8
- use WPMailSMTP\WP;
9
- use WPMailSMTP\Admin\PageAbstract;
10
-
11
- /**
12
- * Class Test is part of Area, displays email testing page of the plugin.
13
- *
14
- * @since 1.0.0
15
- */
16
- class Test extends PageAbstract {
17
-
18
- /**
19
- * @var string Slug of a tab.
20
- */
21
- protected $slug = 'test';
22
-
23
- /**
24
- * @inheritdoc
25
- */
26
- public function get_label() {
27
- return esc_html__( 'Email Test', 'wp-mail-smtp' );
28
- }
29
-
30
- /**
31
- * @inheritdoc
32
- */
33
- public function get_title() {
34
- return $this->get_label();
35
- }
36
-
37
- /**
38
- * @inheritdoc
39
- */
40
- public function display() {
41
- ?>
42
-
43
- <form method="POST" action="">
44
- <?php $this->wp_nonce_field(); ?>
45
-
46
- <!-- Test Email Section Title -->
47
- <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
48
- <div class="wp-mail-smtp-setting-field">
49
- <h2><?php esc_html_e( 'Send a Test Email', 'wp-mail-smtp' ); ?></h2>
50
- </div>
51
- </div>
52
-
53
- <!-- Test Email -->
54
- <div id="wp-mail-smtp-setting-row-test_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
55
- <div class="wp-mail-smtp-setting-label">
56
- <label for="wp-mail-smtp-setting-test_email"><?php esc_html_e( 'Send To', 'wp-mail-smtp' ); ?></label>
57
- </div>
58
- <div class="wp-mail-smtp-setting-field">
59
- <input name="wp-mail-smtp[test_email]" type="email" id="wp-mail-smtp-setting-test_email" spellcheck="false" required />
60
- <p class="desc">
61
- <?php esc_html_e( 'Type an email address here and then click a button below to generate a test email.', 'wp-mail-smtp' ); ?>
62
- </p>
63
- </div>
64
- </div>
65
-
66
- <p class="wp-mail-smtp-submit">
67
- <button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Send Email', 'wp-mail-smtp' ); ?></button>
68
- </p>
69
- </form>
70
-
71
- <?php
72
- }
73
-
74
- /**
75
- * @inheritdoc
76
- */
77
- public function process_post( $data ) {
78
-
79
- $this->check_admin_referer();
80
-
81
- if ( isset( $data['test_email'] ) ) {
82
- $data['test_email'] = filter_var( $data['test_email'], FILTER_VALIDATE_EMAIL );
83
- }
84
-
85
- if ( empty( $data['test_email'] ) ) {
86
- WP::add_admin_notice(
87
- esc_html__( 'Test failed. Please use a valid email address and try to resend the test email.', 'wp-mail-smtp' ),
88
- WP::ADMIN_NOTICE_WARNING
89
- );
90
- return;
91
- }
92
-
93
- global $phpmailer;
94
-
95
- // Make sure the PHPMailer class has been instantiated.
96
- if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
97
- require_once ABSPATH . WPINC . '/class-phpmailer.php';
98
- $phpmailer = new MailCatcher( true );
99
- }
100
-
101
- // Set SMTPDebug level, default is 3 (commands + data + connection status).
102
- $phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 3 );
103
-
104
- // Start output buffering to grab smtp debugging output.
105
- ob_start();
106
-
107
- // Send the test mail.
108
- $result = wp_mail(
109
- $data['test_email'],
110
- /* translators: %s - email address a test email will be sent to. */
111
- 'WP Mail SMTP: ' . sprintf( esc_html__( 'Test email to %s', 'wp-mail-smtp' ), $data['test_email'] ),
112
- sprintf(
113
- /* translators: %s - mailer name. */
114
- esc_html__( 'This email was sent by %s mailer, and generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' ),
115
- wp_mail_smtp()->get_providers()->get_options( Options::init()->get( 'mail', 'mailer' ) )->get_title()
116
- )
117
- );
118
-
119
- // Grab the smtp debugging output.
120
- $smtp_debug = ob_get_clean();
121
-
122
- /*
123
- * Notify a user about the results.
124
- */
125
- if ( $result ) {
126
- WP::add_admin_notice(
127
- esc_html__( 'Your email was sent successfully!', 'wp-mail-smtp' ),
128
- WP::ADMIN_NOTICE_SUCCESS
129
- );
130
- } else {
131
- $error = $this->get_debug_messages( $phpmailer, $smtp_debug );
132
-
133
- WP::add_admin_notice(
134
- '<p><strong>' . esc_html__( 'There was a problem while sending a test email. Related debugging output is shown below:', 'wp-mail-smtp' ) . '</strong></p>' .
135
- '<blockquote style="border-left:1px solid orange;padding-left:10px">' . $error . '</blockquote>' .
136
- '<p class="description">' . esc_html__( 'Please copy only the content of the error debug message above, identified with an orange left border, into the support forum topic if you experience any issues.', 'wp-mail-smtp' ) . '</p>',
137
- WP::ADMIN_NOTICE_ERROR
138
- );
139
- }
140
- }
141
-
142
- /**
143
- * Prepare debug information, that will help users to identify the error.
144
- *
145
- * @since 1.0.0
146
- *
147
- * @param MailCatcher $phpmailer
148
- * @param string $smtp_debug
149
- *
150
- * @return string
151
- */
152
- protected function get_debug_messages( $phpmailer, $smtp_debug ) {
153
-
154
- $options = new Options();
155
-
156
- /*
157
- * Versions Debug.
158
- */
159
-
160
- $versions_text = '<strong>Versions:</strong><br>';
161
-
162
- $versions_text .= '<strong>WordPress:</strong> ' . get_bloginfo( 'version' ) . '<br>';
163
- $versions_text .= '<strong>WordPress MS:</strong> ' . ( is_multisite() ? 'Yes' : 'No' ) . '<br>';
164
- $versions_text .= '<strong>PHP:</strong> ' . PHP_VERSION . '<br>';
165
- $versions_text .= '<strong>WP Mail SMTP:</strong> ' . WPMS_PLUGIN_VER . '<br>';
166
-
167
- /*
168
- * Mailer Debug.
169
- */
170
-
171
- $mailer_text = '<strong>Params:</strong><br>';
172
-
173
- $mailer_text .= '<strong>Mailer:</strong> ' . $phpmailer->Mailer . '<br>';
174
- $mailer_text .= '<strong>Constants:</strong> ' . ( $options->is_const_enabled() ? 'Yes' : 'No' ) . '<br>';
175
-
176
- // Display different debug info based on the mailer.
177
- $mailer = wp_mail_smtp()->get_providers()->get_mailer( $options->get( 'mail', 'mailer' ), $phpmailer );
178
-
179
- if ( $mailer ) {
180
- $mailer_text .= $mailer->get_debug_info();
181
- }
182
-
183
- /*
184
- * General Debug.
185
- */
186
-
187
- $debug_text = implode( '<br>', Debug::get() );
188
- Debug::clear();
189
- if ( ! empty( $debug_text ) ) {
190
- $debug_text = '<br><strong>Debug:</strong><br>' . $debug_text . '<br>';
191
- }
192
-
193
- /*
194
- * SMTP Debug.
195
- */
196
-
197
- $smtp_text = '';
198
- if ( $options->is_mailer_smtp() ) {
199
- $smtp_text = '<strong>SMTP Debug:</strong><br>';
200
- if ( ! empty( $smtp_debug ) ) {
201
- $smtp_text .= $smtp_debug;
202
- } else {
203
- $smtp_text .= '[empty]';
204
- }
205
- }
206
-
207
- $errors = apply_filters( 'wp_mail_smtp_admin_test_get_debug_messages', array(
208
- $versions_text,
209
- $mailer_text,
210
- $debug_text,
211
- $smtp_text,
212
- ) );
213
-
214
- return '<pre>' . implode( '<br>', array_filter( $errors ) ) . '</pre>';
215
- }
216
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Admin\Pages;
4
+
5
+ use WPMailSMTP\Debug;
6
+ use WPMailSMTP\MailCatcher;
7
+ use WPMailSMTP\Options;
8
+ use WPMailSMTP\WP;
9
+ use WPMailSMTP\Admin\PageAbstract;
10
+
11
+ /**
12
+ * Class Test is part of Area, displays email testing page of the plugin.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Test extends PageAbstract {
17
+
18
+ /**
19
+ * @var string Slug of a tab.
20
+ */
21
+ protected $slug = 'test';
22
+
23
+ /**
24
+ * @inheritdoc
25
+ */
26
+ public function get_label() {
27
+ return esc_html__( 'Email Test', 'wp-mail-smtp' );
28
+ }
29
+
30
+ /**
31
+ * @inheritdoc
32
+ */
33
+ public function get_title() {
34
+ return $this->get_label();
35
+ }
36
+
37
+ /**
38
+ * @inheritdoc
39
+ */
40
+ public function display() {
41
+ ?>
42
+
43
+ <form method="POST" action="">
44
+ <?php $this->wp_nonce_field(); ?>
45
+
46
+ <!-- Test Email Section Title -->
47
+ <div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
48
+ <div class="wp-mail-smtp-setting-field">
49
+ <h2><?php esc_html_e( 'Send a Test Email', 'wp-mail-smtp' ); ?></h2>
50
+ </div>
51
+ </div>
52
+
53
+ <!-- Test Email -->
54
+ <div id="wp-mail-smtp-setting-row-test_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
55
+ <div class="wp-mail-smtp-setting-label">
56
+ <label for="wp-mail-smtp-setting-test_email"><?php esc_html_e( 'Send To', 'wp-mail-smtp' ); ?></label>
57
+ </div>
58
+ <div class="wp-mail-smtp-setting-field">
59
+ <input name="wp-mail-smtp[test_email]" type="email" id="wp-mail-smtp-setting-test_email" spellcheck="false" required />
60
+ <p class="desc">
61
+ <?php esc_html_e( 'Type an email address here and then click a button below to generate a test email.', 'wp-mail-smtp' ); ?>
62
+ </p>
63
+ </div>
64
+ </div>
65
+
66
+ <p class="wp-mail-smtp-submit">
67
+ <button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Send Email', 'wp-mail-smtp' ); ?></button>
68
+ </p>
69
+ </form>
70
+
71
+ <?php
72
+ }
73
+
74
+ /**
75
+ * @inheritdoc
76
+ */
77
+ public function process_post( $data ) {
78
+
79
+ $this->check_admin_referer();
80
+
81
+ if ( isset( $data['test_email'] ) ) {
82
+ $data['test_email'] = filter_var( $data['test_email'], FILTER_VALIDATE_EMAIL );
83
+ }
84
+
85
+ if ( empty( $data['test_email'] ) ) {
86
+ WP::add_admin_notice(
87
+ esc_html__( 'Test failed. Please use a valid email address and try to resend the test email.', 'wp-mail-smtp' ),
88
+ WP::ADMIN_NOTICE_WARNING
89
+ );
90
+ return;
91
+ }
92
+
93
+ global $phpmailer;
94
+
95
+ // Make sure the PHPMailer class has been instantiated.
96
+ if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
97
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
98
+ $phpmailer = new MailCatcher( true );
99
+ }
100
+
101
+ // Set SMTPDebug level, default is 3 (commands + data + connection status).
102
+ $phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 3 );
103
+
104
+ // Start output buffering to grab smtp debugging output.
105
+ ob_start();
106
+
107
+ // Send the test mail.
108
+ $result = wp_mail(
109
+ $data['test_email'],
110
+ /* translators: %s - email address a test email will be sent to. */
111
+ 'WP Mail SMTP: ' . sprintf( esc_html__( 'Test email to %s', 'wp-mail-smtp' ), $data['test_email'] ),
112
+ sprintf(
113
+ /* translators: %s - mailer name. */
114
+ esc_html__( 'This email was sent by %s mailer, and generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' ),
115
+ wp_mail_smtp()->get_providers()->get_options( Options::init()->get( 'mail', 'mailer' ) )->get_title()
116
+ )
117
+ );
118
+
119
+ // Grab the smtp debugging output.
120
+ $smtp_debug = ob_get_clean();
121
+
122
+ /*
123
+ * Notify a user about the results.
124
+ */
125
+ if ( $result ) {
126
+ WP::add_admin_notice(
127
+ esc_html__( 'Your email was sent successfully!', 'wp-mail-smtp' ),
128
+ WP::ADMIN_NOTICE_SUCCESS
129
+ );
130
+ } else {
131
+ $error = $this->get_debug_messages( $phpmailer, $smtp_debug );
132
+
133
+ WP::add_admin_notice(
134
+ '<p><strong>' . esc_html__( 'There was a problem while sending a test email. Related debugging output is shown below:', 'wp-mail-smtp' ) . '</strong></p>' .
135
+ '<blockquote style="border-left:1px solid orange;padding-left:10px">' . $error . '</blockquote>' .
136
+ '<p class="description">' . esc_html__( 'Please copy only the content of the error debug message above, identified with an orange left border, into the support forum topic if you experience any issues.', 'wp-mail-smtp' ) . '</p>',
137
+ WP::ADMIN_NOTICE_ERROR
138
+ );
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Prepare debug information, that will help users to identify the error.
144
+ *
145
+ * @since 1.0.0
146
+ *
147
+ * @param MailCatcher $phpmailer
148
+ * @param string $smtp_debug
149
+ *
150
+ * @return string
151
+ */
152
+ protected function get_debug_messages( $phpmailer, $smtp_debug ) {
153
+
154
+ $options = new Options();
155
+
156
+ /*
157
+ * Versions Debug.
158
+ */
159
+
160
+ $versions_text = '<strong>Versions:</strong><br>';
161
+
162
+ $versions_text .= '<strong>WordPress:</strong> ' . get_bloginfo( 'version' ) . '<br>';
163
+ $versions_text .= '<strong>WordPress MS:</strong> ' . ( is_multisite() ? 'Yes' : 'No' ) . '<br>';
164
+ $versions_text .= '<strong>PHP:</strong> ' . PHP_VERSION . '<br>';
165
+ $versions_text .= '<strong>WP Mail SMTP:</strong> ' . WPMS_PLUGIN_VER . '<br>';
166
+
167
+ /*
168
+ * Mailer Debug.
169
+ */
170
+
171
+ $mailer_text = '<strong>Params:</strong><br>';
172
+
173
+ $mailer_text .= '<strong>Mailer:</strong> ' . $phpmailer->Mailer . '<br>';
174
+ $mailer_text .= '<strong>Constants:</strong> ' . ( $options->is_const_enabled() ? 'Yes' : 'No' ) . '<br>';
175
+
176
+ // Display different debug info based on the mailer.
177
+ $mailer = wp_mail_smtp()->get_providers()->get_mailer( $options->get( 'mail', 'mailer' ), $phpmailer );
178
+
179
+ if ( $mailer ) {
180
+ $mailer_text .= $mailer->get_debug_info();
181
+ }
182
+
183
+ /*
184
+ * General Debug.
185
+ */
186
+
187
+ $debug_text = implode( '<br>', Debug::get() );
188
+ Debug::clear();
189
+ if ( ! empty( $debug_text ) ) {
190
+ $debug_text = '<br><strong>Debug:</strong><br>' . $debug_text . '<br>';
191
+ }
192
+
193
+ /*
194
+ * SMTP Debug.
195
+ */
196
+
197
+ $smtp_text = '';
198
+ if ( $options->is_mailer_smtp() ) {
199
+ $smtp_text = '<strong>SMTP Debug:</strong><br>';
200
+ if ( ! empty( $smtp_debug ) ) {
201
+ $smtp_text .= esc_textarea( $smtp_debug );
202
+ } else {
203
+ $smtp_text .= '[empty]';
204
+ }
205
+ }
206
+
207
+ $errors = apply_filters( 'wp_mail_smtp_admin_test_get_debug_messages', array(
208
+ $versions_text,
209
+ $mailer_text,
210
+ $debug_text,
211
+ $smtp_text,
212
+ ) );
213
+
214
+ return '<pre>' . implode( '<br>', array_filter( $errors ) ) . '</pre>';
215
+ }
216
+ }
src/Core.php CHANGED
@@ -1,239 +1,239 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class Core to handle all plugin initialization.
7
- *
8
- * @since 1.0.0
9
- */
10
- class Core {
11
-
12
- /**
13
- * Without trailing slash.
14
- *
15
- * @var string
16
- */
17
- public $plugin_url;
18
- /**
19
- * Without trailing slash.
20
- *
21
- * @var string
22
- */
23
- public $plugin_path;
24
-
25
- /**
26
- * Core constructor.
27
- *
28
- * @since 1.0.0
29
- */
30
- public function __construct() {
31
-
32
- $this->plugin_url = rtrim( plugin_dir_url( __DIR__ ), '/\\' );
33
- $this->plugin_path = rtrim( plugin_dir_path( __DIR__ ), '/\\' );
34
-
35
- $this->hooks();
36
- }
37
-
38
- /**
39
- * Assign all hooks to proper places.
40
- *
41
- * @since 1.0.0
42
- */
43
- public function hooks() {
44
-
45
- // Activation hook.
46
- add_action( 'activate_wp-mail-smtp/wp_mail_smtp.php', array( $this, 'activate' ) );
47
-
48
- add_action( 'plugins_loaded', array( $this, 'get_processor' ) );
49
- add_action( 'plugins_loaded', array( $this, 'replace_phpmailer' ) );
50
- add_action( 'plugins_loaded', array( $this, 'init_notifications' ) );
51
-
52
- add_action( 'admin_notices', array( '\WPMailSMTP\WP', 'display_admin_notices' ) );
53
-
54
- add_action( 'init', array( $this, 'init' ) );
55
- }
56
-
57
- /**
58
- * Initial plugin actions.
59
- *
60
- * @since 1.0.0
61
- */
62
- public function init() {
63
-
64
- // Load translations just in case.
65
- load_plugin_textdomain( 'wp-mail-smtp', false, wp_mail_smtp()->plugin_path . '/languages' );
66
-
67
- /*
68
- * Constantly check in admin area, that we don't need to upgrade DB.
69
- * Do not wait for the `admin_init` hook, because some actions are already done
70
- * on `plugins_loaded`, so migration has to be done before.
71
- */
72
- if ( WP::in_wp_admin() ) {
73
- $this->get_migration();
74
- $this->get_upgrade();
75
- $this->get_admin();
76
- }
77
- }
78
-
79
- /**
80
- * Load the plugin core processor.
81
- *
82
- * @since 1.0.0
83
- *
84
- * @return Processor
85
- */
86
- public function get_processor() {
87
-
88
- static $processor;
89
-
90
- if ( ! isset( $processor ) ) {
91
- $processor = apply_filters( 'wp_mail_smtp_core_get_processor', new Processor() );
92
- }
93
-
94
- return $processor;
95
- }
96
-
97
- /**
98
- * Load the plugin admin area.
99
- *
100
- * @since 1.0.0
101
- *
102
- * @return Admin\Area
103
- */
104
- public function get_admin() {
105
-
106
- static $admin;
107
-
108
- if ( ! isset( $admin ) ) {
109
- $admin = apply_filters( 'wp_mail_smtp_core_get_admin', new Admin\Area() );
110
- }
111
-
112
- return $admin;
113
- }
114
-
115
- /**
116
- * Load the plugin providers loader.
117
- *
118
- * @since 1.0.0
119
- *
120
- * @return Providers\Loader
121
- */
122
- public function get_providers() {
123
-
124
- static $providers;
125
-
126
- if ( ! isset( $providers ) ) {
127
- $providers = apply_filters( 'wp_mail_smtp_core_get_providers', new Providers\Loader() );
128
- }
129
-
130
- return $providers;
131
- }
132
-
133
- /**
134
- * Load the plugin option migrator.
135
- *
136
- * @since 1.0.0
137
- *
138
- * @return Migration
139
- */
140
- public function get_migration() {
141
-
142
- static $migration;
143
-
144
- if ( ! isset( $migration ) ) {
145
- $migration = apply_filters( 'wp_mail_smtp_core_get_migration', new Migration() );
146
- }
147
-
148
- return $migration;
149
- }
150
-
151
- /**
152
- * Load the plugin upgrader.
153
- *
154
- * @since 1.1.0
155
- *
156
- * @return Upgrade
157
- */
158
- public function get_upgrade() {
159
-
160
- static $upgrade;
161
-
162
- if ( ! isset( $upgrade ) ) {
163
- $upgrade = apply_filters( 'wp_mail_smtp_core_get_upgrade', new Upgrade() );
164
- }
165
-
166
- return $upgrade;
167
- }
168
-
169
- /**
170
- * Awesome Motive Notifications.
171
- *
172
- * @since 1.0.0
173
- */
174
- public function init_notifications() {
175
-
176
- if ( Options::init()->get( 'general', 'am_notifications_hidden' ) ) {
177
- return;
178
- }
179
-
180
- static $notification;
181
-
182
- if ( ! isset( $notification ) ) {
183
- $notification = new AM_Notification( 'smtp', WPMS_PLUGIN_VER );
184
- }
185
- }
186
-
187
- /**
188
- * Init the \PHPMailer replacement.
189
- *
190
- * @since 1.0.0
191
- *
192
- * @return \WPMailSMTP\MailCatcher
193
- */
194
- public function replace_phpmailer() {
195
- global $phpmailer;
196
-
197
- return $this->replace_w_fake_phpmailer( $phpmailer );
198
- }
199
-
200
- /**
201
- * Overwrite default PhpMailer with out MailCatcher.
202
- *
203
- * @since 1.0.0
204
- *
205
- * @param null $obj
206
- *
207
- * @return \WPMailSMTP\MailCatcher
208
- */
209
- protected function replace_w_fake_phpmailer( &$obj = null ) {
210
-
211
- $obj = new MailCatcher();
212
-
213
- return $obj;
214
- }
215
-
216
- /**
217
- * What to do on plugin activation.
218
- *
219
- * @since 1.0.0
220
- */
221
- public function activate() {
222
-
223
- // Store the plugin version activated to reference with upgrades.
224
- update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
225
-
226
- // Create and store initial plugin settings.
227
- $options['mail'] = array(
228
- 'from_email' => get_option( 'admin_email' ),
229
- 'from_name' => get_bloginfo( 'name' ),
230
- 'mailer' => 'mail',
231
- 'return_path' => false,
232
- 'smtp' => array(
233
- 'autotls' => true,
234
- ),
235
- );
236
-
237
- Options::init()->set( $options );
238
- }
239
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class Core to handle all plugin initialization.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ class Core {
11
+
12
+ /**
13
+ * Without trailing slash.
14
+ *
15
+ * @var string
16
+ */
17
+ public $plugin_url;
18
+ /**
19
+ * Without trailing slash.
20
+ *
21
+ * @var string
22
+ */
23
+ public $plugin_path;
24
+
25
+ /**
26
+ * Core constructor.
27
+ *
28
+ * @since 1.0.0
29
+ */
30
+ public function __construct() {
31
+
32
+ $this->plugin_url = rtrim( plugin_dir_url( __DIR__ ), '/\\' );
33
+ $this->plugin_path = rtrim( plugin_dir_path( __DIR__ ), '/\\' );
34
+
35
+ $this->hooks();
36
+ }
37
+
38
+ /**
39
+ * Assign all hooks to proper places.
40
+ *
41
+ * @since 1.0.0
42
+ */
43
+ public function hooks() {
44
+
45
+ // Activation hook.
46
+ add_action( 'activate_wp-mail-smtp/wp_mail_smtp.php', array( $this, 'activate' ) );
47
+
48
+ add_action( 'plugins_loaded', array( $this, 'get_processor' ) );
49
+ add_action( 'plugins_loaded', array( $this, 'replace_phpmailer' ) );
50
+ add_action( 'plugins_loaded', array( $this, 'init_notifications' ) );
51
+
52
+ add_action( 'admin_notices', array( '\WPMailSMTP\WP', 'display_admin_notices' ) );
53
+
54
+ add_action( 'init', array( $this, 'init' ) );
55
+ }
56
+
57
+ /**
58
+ * Initial plugin actions.
59
+ *
60
+ * @since 1.0.0
61
+ */
62
+ public function init() {
63
+
64
+ // Load translations just in case.
65
+ load_plugin_textdomain( 'wp-mail-smtp', false, wp_mail_smtp()->plugin_path . '/languages' );
66
+
67
+ /*
68
+ * Constantly check in admin area, that we don't need to upgrade DB.
69
+ * Do not wait for the `admin_init` hook, because some actions are already done
70
+ * on `plugins_loaded`, so migration has to be done before.
71
+ */
72
+ if ( WP::in_wp_admin() ) {
73
+ $this->get_migration();
74
+ $this->get_upgrade();
75
+ $this->get_admin();
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Load the plugin core processor.
81
+ *
82
+ * @since 1.0.0
83
+ *
84
+ * @return Processor
85
+ */
86
+ public function get_processor() {
87
+
88
+ static $processor;
89
+
90
+ if ( ! isset( $processor ) ) {
91
+ $processor = apply_filters( 'wp_mail_smtp_core_get_processor', new Processor() );
92
+ }
93
+
94
+ return $processor;
95
+ }
96
+
97
+ /**
98
+ * Load the plugin admin area.
99
+ *
100
+ * @since 1.0.0
101
+ *
102
+ * @return Admin\Area
103
+ */
104
+ public function get_admin() {
105
+
106
+ static $admin;
107
+
108
+ if ( ! isset( $admin ) ) {
109
+ $admin = apply_filters( 'wp_mail_smtp_core_get_admin', new Admin\Area() );
110
+ }
111
+
112
+ return $admin;
113
+ }
114
+
115
+ /**
116
+ * Load the plugin providers loader.
117
+ *
118
+ * @since 1.0.0
119
+ *
120
+ * @return Providers\Loader
121
+ */
122
+ public function get_providers() {
123
+
124
+ static $providers;
125
+
126
+ if ( ! isset( $providers ) ) {
127
+ $providers = apply_filters( 'wp_mail_smtp_core_get_providers', new Providers\Loader() );
128
+ }
129
+
130
+ return $providers;
131
+ }
132
+
133
+ /**
134
+ * Load the plugin option migrator.
135
+ *
136
+ * @since 1.0.0
137
+ *
138
+ * @return Migration
139
+ */
140
+ public function get_migration() {
141
+
142
+ static $migration;
143
+
144
+ if ( ! isset( $migration ) ) {
145
+ $migration = apply_filters( 'wp_mail_smtp_core_get_migration', new Migration() );
146
+ }
147
+
148
+ return $migration;
149
+ }
150
+
151
+ /**
152
+ * Load the plugin upgrader.
153
+ *
154
+ * @since 1.1.0
155
+ *
156
+ * @return Upgrade
157
+ */
158
+ public function get_upgrade() {
159
+
160
+ static $upgrade;
161
+
162
+ if ( ! isset( $upgrade ) ) {
163
+ $upgrade = apply_filters( 'wp_mail_smtp_core_get_upgrade', new Upgrade() );
164
+ }
165
+
166
+ return $upgrade;
167
+ }
168
+
169
+ /**
170
+ * Awesome Motive Notifications.
171
+ *
172
+ * @since 1.0.0
173
+ */
174
+ public function init_notifications() {
175
+
176
+ if ( Options::init()->get( 'general', 'am_notifications_hidden' ) ) {
177
+ return;
178
+ }
179
+
180
+ static $notification;
181
+
182
+ if ( ! isset( $notification ) ) {
183
+ $notification = new AM_Notification( 'smtp', WPMS_PLUGIN_VER );
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Init the \PHPMailer replacement.
189
+ *
190
+ * @since 1.0.0
191
+ *
192
+ * @return \WPMailSMTP\MailCatcher
193
+ */
194
+ public function replace_phpmailer() {
195
+ global $phpmailer;
196
+
197
+ return $this->replace_w_fake_phpmailer( $phpmailer );
198
+ }
199
+
200
+ /**
201
+ * Overwrite default PhpMailer with out MailCatcher.
202
+ *
203
+ * @since 1.0.0
204
+ *
205
+ * @param null $obj
206
+ *
207
+ * @return \WPMailSMTP\MailCatcher
208
+ */
209
+ protected function replace_w_fake_phpmailer( &$obj = null ) {
210
+
211
+ $obj = new MailCatcher();
212
+
213
+ return $obj;
214
+ }
215
+
216
+ /**
217
+ * What to do on plugin activation.
218
+ *
219
+ * @since 1.0.0
220
+ */
221
+ public function activate() {
222
+
223
+ // Store the plugin version activated to reference with upgrades.
224
+ update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
225
+
226
+ // Create and store initial plugin settings.
227
+ $options['mail'] = array(
228
+ 'from_email' => get_option( 'admin_email' ),
229
+ 'from_name' => get_bloginfo( 'name' ),
230
+ 'mailer' => 'mail',
231
+ 'return_path' => false,
232
+ 'smtp' => array(
233
+ 'autotls' => true,
234
+ ),
235
+ );
236
+
237
+ Options::init()->set( $options );
238
+ }
239
+ }
src/Debug.php CHANGED
@@ -1,118 +1,118 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class Debug that will save all errors or warnings generated by APIs or SMTP
7
- * and display in area for administrators.
8
- *
9
- * Usage example:
10
- * Debug::set( 'Some warning: %s', array( '%s' => $e->getMessage() );
11
- * $debug = Debug::get(); // array
12
- * $debug = Debug::get_last(); // string
13
- *
14
- * @since 1.2.0
15
- */
16
- class Debug {
17
-
18
- /**
19
- * Key for options table where all messages will be saved to.
20
- */
21
- const OPTION_KEY = 'wp_mail_smtp_debug';
22
-
23
- /**
24
- * Save the debug message to a debug log.
25
- * Adds one more to a list, at the end.
26
- *
27
- * @since 1.2.0
28
- *
29
- * @param string $message
30
- */
31
- public static function set( $message ) {
32
-
33
- if ( ! is_string( $message ) ) {
34
- $message = \json_encode( $message );
35
- }
36
-
37
- $message = wp_strip_all_tags( $message, false );
38
-
39
- $all = self::get();
40
-
41
- array_push( $all, $message );
42
-
43
- update_option( self::OPTION_KEY, $all, false );
44
- }
45
-
46
- /**
47
- * Remove all messages for a debug log.
48
- *
49
- * @since 1.2.0
50
- */
51
- public static function clear() {
52
- update_option( self::OPTION_KEY, array(), false );
53
- }
54
-
55
- /**
56
- * Retrieve all messages from a debug log.
57
- *
58
- * @since 1.2.0
59
- *
60
- * @return array
61
- */
62
- public static function get() {
63
-
64
- $all = get_option( self::OPTION_KEY, array() );
65
-
66
- if ( ! is_array( $all ) ) {
67
- $all = (array) $all;
68
- }
69
-
70
- return $all;
71
- }
72
-
73
- /**
74
- * Get the last message that was saved to a debug log.
75
- *
76
- * @since 1.2.0
77
- *
78
- * @return string
79
- */
80
- public static function get_last() {
81
-
82
- $all = self::get();
83
-
84
- if ( ! empty( $all ) && is_array( $all ) ) {
85
- return (string) $all[ count( $all ) - 1 ];
86
- }
87
-
88
- return '';
89
- }
90
-
91
- /**
92
- * Get the proper variable content output to debug.
93
- *
94
- * @since 1.2.0
95
- *
96
- * @param mixed $var
97
- *
98
- * @return string
99
- */
100
- public static function pvar( $var = '' ) {
101
-
102
- ob_start();
103
-
104
- echo '<code>';
105
-
106
- if ( is_bool( $var ) || empty( $var ) ) {
107
- var_dump( $var );
108
- } else {
109
- print_r( $var );
110
- }
111
-
112
- echo '</code>';
113
-
114
- $output = ob_get_clean();
115
-
116
- return str_replace( array( "\r\n", "\r", "\n" ), '', $output );
117
- }
118
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class Debug that will save all errors or warnings generated by APIs or SMTP
7
+ * and display in area for administrators.
8
+ *
9
+ * Usage example:
10
+ * Debug::set( 'Some warning: %s', array( '%s' => $e->getMessage() );
11
+ * $debug = Debug::get(); // array
12
+ * $debug = Debug::get_last(); // string
13
+ *
14
+ * @since 1.2.0
15
+ */
16
+ class Debug {
17
+
18
+ /**
19
+ * Key for options table where all messages will be saved to.
20
+ */
21
+ const OPTION_KEY = 'wp_mail_smtp_debug';
22
+
23
+ /**
24
+ * Save the debug message to a debug log.
25
+ * Adds one more to a list, at the end.
26
+ *
27
+ * @since 1.2.0
28
+ *
29
+ * @param string $message
30
+ */
31
+ public static function set( $message ) {
32
+
33
+ if ( ! is_string( $message ) ) {
34
+ $message = \json_encode( $message );
35
+ }
36
+
37
+ $message = wp_strip_all_tags( $message, false );
38
+
39
+ $all = self::get();
40
+
41
+ array_push( $all, $message );
42
+
43
+ update_option( self::OPTION_KEY, $all, false );
44
+ }
45
+
46
+ /**
47
+ * Remove all messages for a debug log.
48
+ *
49
+ * @since 1.2.0
50
+ */
51
+ public static function clear() {
52
+ update_option( self::OPTION_KEY, array(), false );
53
+ }
54
+
55
+ /**
56
+ * Retrieve all messages from a debug log.
57
+ *
58
+ * @since 1.2.0
59
+ *
60
+ * @return array
61
+ */
62
+ public static function get() {
63
+
64
+ $all = get_option( self::OPTION_KEY, array() );
65
+
66
+ if ( ! is_array( $all ) ) {
67
+ $all = (array) $all;
68
+ }
69
+
70
+ return $all;
71
+ }
72
+
73
+ /**
74
+ * Get the last message that was saved to a debug log.
75
+ *
76
+ * @since 1.2.0
77
+ *
78
+ * @return string
79
+ */
80
+ public static function get_last() {
81
+
82
+ $all = self::get();
83
+
84
+ if ( ! empty( $all ) && is_array( $all ) ) {
85
+ return (string) $all[ count( $all ) - 1 ];
86
+ }
87
+
88
+ return '';
89
+ }
90
+
91
+ /**
92
+ * Get the proper variable content output to debug.
93
+ *
94
+ * @since 1.2.0
95
+ *
96
+ * @param mixed $var
97
+ *
98
+ * @return string
99
+ */
100
+ public static function pvar( $var = '' ) {
101
+
102
+ ob_start();
103
+
104
+ echo '<code>';
105
+
106
+ if ( is_bool( $var ) || empty( $var ) ) {
107
+ var_dump( $var );
108
+ } else {
109
+ print_r( $var );
110
+ }
111
+
112
+ echo '</code>';
113
+
114
+ $output = ob_get_clean();
115
+
116
+ return str_replace( array( "\r\n", "\r", "\n" ), '', $output );
117
+ }
118
+ }
src/MailCatcher.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- // Load PHPMailer class, so we can subclass it.
6
- if ( ! class_exists( 'PHPMailer', false ) ) {
7
- require_once ABSPATH . WPINC . '/class-phpmailer.php';
8
- }
9
-
10
- /**
11
- * Class MailCatcher replaces the \PHPMailer and modifies the email sending logic.
12
- * Thus, we can use other mailers API to do what we need, or stop emails completely.
13
- *
14
- * @since 1.0.0
15
- */
16
- class MailCatcher extends \PHPMailer {
17
-
18
- /**
19
- * Modify the default send() behaviour.
20
- * For those mailers, that relies on PHPMailer class - call it directly.
21
- * For others - init the correct provider and process it.
22
- *
23
- * @since 1.0.0
24
- *
25
- * @throws \phpmailerException Throws when sending via PhpMailer fails for some reason.
26
- *
27
- * @return bool
28
- */
29
- public function send() {
30
-
31
- $options = new Options();
32
- $mail_mailer = $options->get( 'mail', 'mailer' );
33
-
34
- // Define a custom header, that will be used in Gmail/SMTP mailers.
35
- $this->XMailer = 'WPMailSMTP/Mailer/' . $mail_mailer . ' ' . WPMS_PLUGIN_VER;
36
-
37
- // Use the default PHPMailer, as we inject our settings there for certain providers.
38
- if (
39
- $mail_mailer === 'mail' ||
40
- $mail_mailer === 'smtp' ||
41
- $mail_mailer === 'pepipost'
42
- ) {
43
- return parent::send();
44
- }
45
-
46
- // Prepare everything (including the message) for sending.
47
- if ( ! $this->preSend() ) {
48
- return false;
49
- }
50
-
51
- $mailer = wp_mail_smtp()->get_providers()->get_mailer( $mail_mailer, $this );
52
-
53
- if ( ! $mailer ) {
54
- return false;
55
- }
56
-
57
- if ( ! $mailer->is_php_compatible() ) {
58
- return false;
59
- }
60
-
61
- /*
62
- * Send the actual email.
63
- * We reuse everything, that was preprocessed for usage in \PHPMailer.
64
- */
65
- $mailer->send();
66
-
67
- return $mailer->is_email_sent();
68
- }
69
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ // Load PHPMailer class, so we can subclass it.
6
+ if ( ! class_exists( 'PHPMailer', false ) ) {
7
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
8
+ }
9
+
10
+ /**
11
+ * Class MailCatcher replaces the \PHPMailer and modifies the email sending logic.
12
+ * Thus, we can use other mailers API to do what we need, or stop emails completely.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class MailCatcher extends \PHPMailer {
17
+
18
+ /**
19
+ * Modify the default send() behaviour.
20
+ * For those mailers, that relies on PHPMailer class - call it directly.
21
+ * For others - init the correct provider and process it.
22
+ *
23
+ * @since 1.0.0
24
+ *
25
+ * @throws \phpmailerException Throws when sending via PhpMailer fails for some reason.
26
+ *
27
+ * @return bool
28
+ */
29
+ public function send() {
30
+
31
+ $options = new Options();
32
+ $mail_mailer = $options->get( 'mail', 'mailer' );
33
+
34
+ // Define a custom header, that will be used in Gmail/SMTP mailers.
35
+ $this->XMailer = 'WPMailSMTP/Mailer/' . $mail_mailer . ' ' . WPMS_PLUGIN_VER;
36
+
37
+ // Use the default PHPMailer, as we inject our settings there for certain providers.
38
+ if (
39
+ $mail_mailer === 'mail' ||
40
+ $mail_mailer === 'smtp' ||
41
+ $mail_mailer === 'pepipost'
42
+ ) {
43
+ return parent::send();
44
+ }
45
+
46
+ // Prepare everything (including the message) for sending.
47
+ if ( ! $this->preSend() ) {
48
+ return false;
49
+ }
50
+
51
+ $mailer = wp_mail_smtp()->get_providers()->get_mailer( $mail_mailer, $this );
52
+
53
+ if ( ! $mailer ) {
54
+ return false;
55
+ }
56
+
57
+ if ( ! $mailer->is_php_compatible() ) {
58
+ return false;
59
+ }
60
+
61
+ /*
62
+ * Send the actual email.
63
+ * We reuse everything, that was preprocessed for usage in \PHPMailer.
64
+ */
65
+ $mailer->send();
66
+
67
+ return $mailer->is_email_sent();
68
+ }
69
+ }
src/Migration.php CHANGED
@@ -1,245 +1,245 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class Migration helps migrate all plugin options saved into DB to a new storage location.
7
- *
8
- * @since 1.0.0
9
- */
10
- class Migration {
11
-
12
- /**
13
- * All old values for pre 1.0 version of a plugin.
14
- *
15
- * @var array
16
- */
17
- protected $old_keys = array(
18
- 'pepipost_ssl',
19
- 'pepipost_port',
20
- 'pepipost_pass',
21
- 'pepipost_user',
22
- 'smtp_pass',
23
- 'smtp_user',
24
- 'smtp_auth',
25
- 'smtp_ssl',
26
- 'smtp_port',
27
- 'smtp_host',
28
- 'mail_set_return_path',
29
- 'mailer',
30
- 'mail_from_name',
31
- 'mail_from',
32
- 'wp_mail_smtp_am_notifications_hidden',
33
- );
34
-
35
- /**
36
- * Old values, taken from $old_keys options.
37
- *
38
- * @var array
39
- */
40
- protected $old_values = array();
41
-
42
- /**
43
- * Converted array of data from previous option values.
44
- *
45
- * @var array
46
- */
47
- protected $new_values = array();
48
-
49
- /**
50
- * Migration constructor.
51
- *
52
- * @since 1.0.0
53
- */
54
- public function __construct() {
55
-
56
- if ( $this->is_migrated() ) {
57
- return;
58
- }
59
-
60
- $this->old_values = $this->get_old_values();
61
- $this->new_values = $this->get_converted_options();
62
-
63
- Options::init()->set( $this->new_values );
64
-
65
- // Removing all options will be enabled some time in the future.
66
- // $this->clean_deprecated_data();
67
- }
68
-
69
- /**
70
- * Whether we already migrated or not.
71
- *
72
- * @since 1.0.0
73
- *
74
- * @return bool
75
- */
76
- protected function is_migrated() {
77
-
78
- $is_migrated = false;
79
- $new_values = get_option( Options::META_KEY, array() );
80
-
81
- if ( ! empty( $new_values ) ) {
82
- $is_migrated = true;
83
- }
84
-
85
- return $is_migrated;
86
- }
87
-
88
- /**
89
- * Get all old values from DB.
90
- *
91
- * @since 1.0.0
92
- *
93
- * @return array
94
- */
95
- protected function get_old_values() {
96
-
97
- $old_values = array();
98
-
99
- foreach ( $this->old_keys as $old_key ) {
100
- $old_values[ $old_key ] = get_option( $old_key, '' );
101
- }
102
-
103
- return $old_values;
104
- }
105
-
106
- /**
107
- * Convert old values from key=>value to a multidimensional array of data.
108
- *
109
- * @since 1.0.0
110
- */
111
- protected function get_converted_options() {
112
-
113
- $converted = array();
114
-
115
- foreach ( $this->old_keys as $old_key ) {
116
-
117
- switch ( $old_key ) {
118
- case 'pepipost_user':
119
- case 'pepipost_pass':
120
- case 'pepipost_port':
121
- case 'pepipost_ssl':
122
- // Do not migrate pepipost options if it's not activated at the moment.
123
- if ( 'pepipost' === $this->old_values['mailer'] ) {
124
- $shortcut = explode( '_', $old_key );
125
-
126
- if ( $old_key === 'pepipost_ssl' ) {
127
- $converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
128
- } else {
129
- $converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
130
- }
131
- }
132
- break;
133
-
134
- case 'smtp_host':
135
- case 'smtp_port':
136
- case 'smtp_ssl':
137
- case 'smtp_auth':
138
- case 'smtp_user':
139
- case 'smtp_pass':
140
- $shortcut = explode( '_', $old_key );
141
-
142
- if ( $old_key === 'smtp_ssl' ) {
143
- $converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
144
- } elseif ( $old_key === 'smtp_auth' ) {
145
- $converted[ $shortcut[0] ][ $shortcut[1] ] = ( $this->old_values[ $old_key ] === 'true' ? 'yes' : 'no' );
146
- } else {
147
- $converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
148
- }
149
-
150
- break;
151
-
152
- case 'mail_from':
153
- $converted['mail']['from_email'] = $this->old_values[ $old_key ];
154
- break;
155
- case 'mail_from_name':
156
- $converted['mail']['from_name'] = $this->old_values[ $old_key ];
157
- break;
158
- case 'mail_set_return_path':
159
- $converted['mail']['return_path'] = ( $this->old_values[ $old_key ] === 'true' );
160
- break;
161
- case 'mailer':
162
- $converted['mail']['mailer'] = $this->old_values[ $old_key ];
163
- break;
164
- case 'wp_mail_smtp_am_notifications_hidden':
165
- $converted['general']['am_notifications_hidden'] = ( $this->old_values[ $old_key ] === 'true' );
166
- break;
167
- }
168
- }
169
-
170
- $converted = $this->get_converted_constants_options( $converted );
171
-
172
- return $converted;
173
- }
174
-
175
- /**
176
- * Some users use constants in wp-config.php to define values.
177
- * We need to prioritize them and reapply data to options.
178
- * Use only those that are actually defined.
179
- *
180
- * @since 1.0.0
181
- *
182
- * @param array $converted
183
- *
184
- * @return array
185
- */
186
- protected function get_converted_constants_options( $converted ) {
187
-
188
- // Are we configured via constants?
189
- if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) {
190
- return $converted;
191
- }
192
-
193
- /*
194
- * Mail settings.
195
- */
196
- if ( defined( 'WPMS_MAIL_FROM' ) ) {
197
- $converted['mail']['from_email'] = WPMS_MAIL_FROM;
198
- }
199
- if ( defined( 'WPMS_MAIL_FROM_NAME' ) ) {
200
- $converted['mail']['from_name'] = WPMS_MAIL_FROM_NAME;
201
- }
202
- if ( defined( 'WPMS_MAILER' ) ) {
203
- $converted['mail']['return_path'] = WPMS_MAILER;
204
- }
205
- if ( defined( 'WPMS_SET_RETURN_PATH' ) ) {
206
- $converted['mail']['mailer'] = WPMS_SET_RETURN_PATH;
207
- }
208
-
209
- /*
210
- * SMTP settings.
211
- */
212
- if ( defined( 'WPMS_SMTP_HOST' ) ) {
213
- $converted['smtp']['host'] = WPMS_SMTP_HOST;
214
- }
215
- if ( defined( 'WPMS_SMTP_PORT' ) ) {
216
- $converted['smtp']['port'] = WPMS_SMTP_PORT;
217
- }
218
- if ( defined( 'WPMS_SSL' ) ) {
219
- $converted['smtp']['ssl'] = WPMS_SSL;
220
- }
221
- if ( defined( 'WPMS_SMTP_AUTH' ) ) {
222
- $converted['smtp']['auth'] = WPMS_SMTP_AUTH;
223
- }
224
- if ( defined( 'WPMS_SMTP_USER' ) ) {
225
- $converted['smtp']['user'] = WPMS_SMTP_USER;
226
- }
227
- if ( defined( 'WPMS_SMTP_PASS' ) ) {
228
- $converted['smtp']['pass'] = WPMS_SMTP_PASS;
229
- }
230
-
231
- return $converted;
232
- }
233
-
234
- /**
235
- * Delete all old values that are stored separately each.
236
- *
237
- * @since 1.0.0
238
- */
239
- protected function clean_deprecated_data() {
240
-
241
- foreach ( $this->old_keys as $old_key ) {
242
- delete_option( $old_key );
243
- }
244
- }
245
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class Migration helps migrate all plugin options saved into DB to a new storage location.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ class Migration {
11
+
12
+ /**
13
+ * All old values for pre 1.0 version of a plugin.
14
+ *
15
+ * @var array
16
+ */
17
+ protected $old_keys = array(
18
+ 'pepipost_ssl',
19
+ 'pepipost_port',
20
+ 'pepipost_pass',
21
+ 'pepipost_user',
22
+ 'smtp_pass',
23
+ 'smtp_user',
24
+ 'smtp_auth',
25
+ 'smtp_ssl',
26
+ 'smtp_port',
27
+ 'smtp_host',
28
+ 'mail_set_return_path',
29
+ 'mailer',
30
+ 'mail_from_name',
31
+ 'mail_from',
32
+ 'wp_mail_smtp_am_notifications_hidden',
33
+ );
34
+
35
+ /**
36
+ * Old values, taken from $old_keys options.
37
+ *
38
+ * @var array
39
+ */
40
+ protected $old_values = array();
41
+
42
+ /**
43
+ * Converted array of data from previous option values.
44
+ *
45
+ * @var array
46
+ */
47
+ protected $new_values = array();
48
+
49
+ /**
50
+ * Migration constructor.
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ public function __construct() {
55
+
56
+ if ( $this->is_migrated() ) {
57
+ return;
58
+ }
59
+
60
+ $this->old_values = $this->get_old_values();
61
+ $this->new_values = $this->get_converted_options();
62
+
63
+ Options::init()->set( $this->new_values );
64
+
65
+ // Removing all options will be enabled some time in the future.
66
+ // $this->clean_deprecated_data();
67
+ }
68
+
69
+ /**
70
+ * Whether we already migrated or not.
71
+ *
72
+ * @since 1.0.0
73
+ *
74
+ * @return bool
75
+ */
76
+ protected function is_migrated() {
77
+
78
+ $is_migrated = false;
79
+ $new_values = get_option( Options::META_KEY, array() );
80
+
81
+ if ( ! empty( $new_values ) ) {
82
+ $is_migrated = true;
83
+ }
84
+
85
+ return $is_migrated;
86
+ }
87
+
88
+ /**
89
+ * Get all old values from DB.
90
+ *
91
+ * @since 1.0.0
92
+ *
93
+ * @return array
94
+ */
95
+ protected function get_old_values() {
96
+
97
+ $old_values = array();
98
+
99
+ foreach ( $this->old_keys as $old_key ) {
100
+ $old_values[ $old_key ] = get_option( $old_key, '' );
101
+ }
102
+
103
+ return $old_values;
104
+ }
105
+
106
+ /**
107
+ * Convert old values from key=>value to a multidimensional array of data.
108
+ *
109
+ * @since 1.0.0
110
+ */
111
+ protected function get_converted_options() {
112
+
113
+ $converted = array();
114
+
115
+ foreach ( $this->old_keys as $old_key ) {
116
+
117
+ switch ( $old_key ) {
118
+ case 'pepipost_user':
119
+ case 'pepipost_pass':
120
+ case 'pepipost_port':
121
+ case 'pepipost_ssl':
122
+ // Do not migrate pepipost options if it's not activated at the moment.
123
+ if ( 'pepipost' === $this->old_values['mailer'] ) {
124
+ $shortcut = explode( '_', $old_key );
125
+
126
+ if ( $old_key === 'pepipost_ssl' ) {
127
+ $converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
128
+ } else {
129
+ $converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
130
+ }
131
+ }
132
+ break;
133
+
134
+ case 'smtp_host':
135
+ case 'smtp_port':
136
+ case 'smtp_ssl':
137
+ case 'smtp_auth':
138
+ case 'smtp_user':
139
+ case 'smtp_pass':
140
+ $shortcut = explode( '_', $old_key );
141
+
142
+ if ( $old_key === 'smtp_ssl' ) {
143
+ $converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
144
+ } elseif ( $old_key === 'smtp_auth' ) {
145
+ $converted[ $shortcut[0] ][ $shortcut[1] ] = ( $this->old_values[ $old_key ] === 'true' ? 'yes' : 'no' );
146
+ } else {
147
+ $converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
148
+ }
149
+
150
+ break;
151
+
152
+ case 'mail_from':
153
+ $converted['mail']['from_email'] = $this->old_values[ $old_key ];
154
+ break;
155
+ case 'mail_from_name':
156
+ $converted['mail']['from_name'] = $this->old_values[ $old_key ];
157
+ break;
158
+ case 'mail_set_return_path':
159
+ $converted['mail']['return_path'] = ( $this->old_values[ $old_key ] === 'true' );
160
+ break;
161
+ case 'mailer':
162
+ $converted['mail']['mailer'] = $this->old_values[ $old_key ];
163
+ break;
164
+ case 'wp_mail_smtp_am_notifications_hidden':
165
+ $converted['general']['am_notifications_hidden'] = ( $this->old_values[ $old_key ] === 'true' );
166
+ break;
167
+ }
168
+ }
169
+
170
+ $converted = $this->get_converted_constants_options( $converted );
171
+
172
+ return $converted;
173
+ }
174
+
175
+ /**
176
+ * Some users use constants in wp-config.php to define values.
177
+ * We need to prioritize them and reapply data to options.
178
+ * Use only those that are actually defined.
179
+ *
180
+ * @since 1.0.0
181
+ *
182
+ * @param array $converted
183
+ *
184
+ * @return array
185
+ */
186
+ protected function get_converted_constants_options( $converted ) {
187
+
188
+ // Are we configured via constants?
189
+ if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) {
190
+ return $converted;
191
+ }
192
+
193
+ /*
194
+ * Mail settings.
195
+ */
196
+ if ( defined( 'WPMS_MAIL_FROM' ) ) {
197
+ $converted['mail']['from_email'] = WPMS_MAIL_FROM;
198
+ }
199
+ if ( defined( 'WPMS_MAIL_FROM_NAME' ) ) {
200
+ $converted['mail']['from_name'] = WPMS_MAIL_FROM_NAME;
201
+ }
202
+ if ( defined( 'WPMS_MAILER' ) ) {
203
+ $converted['mail']['return_path'] = WPMS_MAILER;
204
+ }
205
+ if ( defined( 'WPMS_SET_RETURN_PATH' ) ) {
206
+ $converted['mail']['mailer'] = WPMS_SET_RETURN_PATH;
207
+ }
208
+
209
+ /*
210
+ * SMTP settings.
211
+ */
212
+ if ( defined( 'WPMS_SMTP_HOST' ) ) {
213
+ $converted['smtp']['host'] = WPMS_SMTP_HOST;
214
+ }
215
+ if ( defined( 'WPMS_SMTP_PORT' ) ) {
216
+ $converted['smtp']['port'] = WPMS_SMTP_PORT;
217
+ }
218
+ if ( defined( 'WPMS_SSL' ) ) {
219
+ $converted['smtp']['ssl'] = WPMS_SSL;
220
+ }
221
+ if ( defined( 'WPMS_SMTP_AUTH' ) ) {
222
+ $converted['smtp']['auth'] = WPMS_SMTP_AUTH;
223
+ }
224
+ if ( defined( 'WPMS_SMTP_USER' ) ) {
225
+ $converted['smtp']['user'] = WPMS_SMTP_USER;
226
+ }
227
+ if ( defined( 'WPMS_SMTP_PASS' ) ) {
228
+ $converted['smtp']['pass'] = WPMS_SMTP_PASS;
229
+ }
230
+
231
+ return $converted;
232
+ }
233
+
234
+ /**
235
+ * Delete all old values that are stored separately each.
236
+ *
237
+ * @since 1.0.0
238
+ */
239
+ protected function clean_deprecated_data() {
240
+
241
+ foreach ( $this->old_keys as $old_key ) {
242
+ delete_option( $old_key );
243
+ }
244
+ }
245
+ }
src/Options.php CHANGED
@@ -1,596 +1,596 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class Options to handle all options management.
7
- * WordPress does all the heavy work for caching get_option() data,
8
- * so we don't have to do that. But we want to minimize cyclomatic complexity
9
- * of calling a bunch of WP functions, thus we will cache them in a class as well.
10
- *
11
- * @since 1.0.0
12
- */
13
- class Options {
14
-
15
- /**
16
- * @var array Map of all the default options of the plugin.
17
- */
18
- private static $map = array(
19
- 'mail' => array(
20
- 'from_name',
21
- 'from_email',
22
- 'mailer',
23
- 'return_path',
24
- ),
25
- 'smtp' => array(
26
- 'host',
27
- 'port',
28
- 'encryption',
29
- 'autotls',
30
- 'auth',
31
- 'user',
32
- 'pass',
33
- ),
34
- 'gmail' => array(
35
- 'client_id',
36
- 'client_secret',
37
- ),
38
- 'mailgun' => array(
39
- 'api_key',
40
- 'domain',
41
- ),
42
- 'sendgrid' => array(
43
- 'api_key',
44
- ),
45
- 'pepipost' => array(
46
- 'host',
47
- 'port',
48
- 'encryption',
49
- 'auth',
50
- 'user',
51
- 'pass',
52
- ),
53
- );
54
-
55
- /**
56
- * That's where plugin options are saved in wp_options table.
57
- *
58
- * @var string
59
- */
60
- const META_KEY = 'wp_mail_smtp';
61
-
62
- /**
63
- * All the plugin options.
64
- *
65
- * @var array
66
- */
67
- private $_options = array();
68
-
69
- /**
70
- * Init the Options class.
71
- *
72
- * @since 1.0.0
73
- */
74
- public function __construct() {
75
- $this->populate_options();
76
- }
77
-
78
- /**
79
- * Initialize all the options, used for chaining.
80
- *
81
- * One-liner:
82
- * Options::init()->get('smtp', 'host');
83
- * Options::init()->is_pepipost_active();
84
- *
85
- * Or multiple-usage:
86
- * $options = new Options();
87
- * $options->get('smtp', 'host');
88
- *
89
- * @since 1.0.0
90
- *
91
- * @return Options
92
- */
93
- public static function init() {
94
-
95
- static $instance;
96
-
97
- if ( ! $instance ) {
98
- $instance = new self();
99
- }
100
-
101
- return $instance;
102
- }
103
-
104
- /**
105
- * Retrieve all options of the plugin.
106
- *
107
- * @since 1.0.0
108
- */
109
- protected function populate_options() {
110
- $this->_options = get_option( self::META_KEY, array() );
111
- }
112
-
113
- /**
114
- * Get all the options.
115
- *
116
- * Options::init()->get_all();
117
- *
118
- * @since 1.0.0
119
- *
120
- * @return array
121
- */
122
- public function get_all() {
123
-
124
- $options = $this->_options;
125
-
126
- foreach ( $options as $group => $g_value ) {
127
- foreach ( $g_value as $key => $value ) {
128
- $options[ $group ][ $key ] = $this->get( $group, $key );
129
- }
130
- }
131
-
132
- return apply_filters( 'wp_mail_smtp_options_get_all', $options );
133
- }
134
-
135
- /**
136
- * Get all the options for a group.
137
- *
138
- * Options::init()->get_group('smtp') - will return only array of options (or empty array if a key doesn't exist).
139
- *
140
- * @since 1.0.0
141
- *
142
- * @param string $group
143
- *
144
- * @return mixed
145
- */
146
- public function get_group( $group ) {
147
-
148
- // Just to feel safe.
149
- $group = sanitize_key( $group );
150
-
151
- if ( isset( $this->_options[ $group ] ) ) {
152
-
153
- foreach ( $this->_options[ $group ] as $g_key => $g_value ) {
154
- $options[ $group ][ $g_key ] = $this->get( $group, $g_key );
155
- }
156
-
157
- return apply_filters( 'wp_mail_smtp_options_get_group', $this->_options[ $group ], $group );
158
- }
159
-
160
- return array();
161
- }
162
-
163
- /**
164
- * Get options by a group and a key.
165
- *
166
- * Options::init()->get( 'smtp', 'host' ) - will return only SMTP 'host' option.
167
- *
168
- * @since 1.0.0
169
- *
170
- * @param string $group
171
- * @param string $key
172
- *
173
- * @return mixed
174
- */
175
- public function get( $group, $key ) {
176
-
177
- // Just to feel safe.
178
- $group = sanitize_key( $group );
179
- $key = sanitize_key( $key );
180
-
181
- // Get the options group.
182
- if ( isset( $this->_options[ $group ] ) ) {
183
-
184
- // Get the options key of a group.
185
- if ( isset( $this->_options[ $group ][ $key ] ) ) {
186
- $value = $this->get_const_value( $group, $key, $this->_options[ $group ][ $key ] );
187
- } else {
188
- $value = $this->postprocess_key_defaults( $group, $key );
189
- }
190
- } else {
191
- $value = $this->postprocess_key_defaults( $group, $key );
192
- }
193
-
194
- return apply_filters( 'wp_mail_smtp_options_get', $value, $group, $key );
195
- }
196
-
197
- /**
198
- * Some options may be non-empty by default,
199
- * so we need to postprocess them to convert.
200
- *
201
- * @since 1.0.0
202
- *
203
- * @param string $group
204
- * @param string $key
205
- *
206
- * @return mixed
207
- */
208
- protected function postprocess_key_defaults( $group, $key ) {
209
-
210
- $value = '';
211
-
212
- switch ( $key ) {
213
- case 'return_path':
214
- $value = $group === 'mail' ? false : true;
215
- break;
216
-
217
- case 'encryption':
218
- $value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? 'none' : $value;
219
- break;
220
-
221
- case 'auth':
222
- case 'autotls':
223
- $value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? false : true;
224
- break;
225
-
226
- case 'pass':
227
- $value = $this->get_const_value( $group, $key, $value );
228
- break;
229
- }
230
-
231
- return apply_filters( 'wp_mail_smtp_options_postprocess_key_defaults', $value, $group, $key );
232
- }
233
-
234
- /**
235
- * Process the options values through the constants check.
236
- * If we have defined associated constant - use it instead of a DB value.
237
- * Backward compatibility is hard.
238
- * General section of options won't have constants, so we are omitting those checks and just return default value.
239
- *
240
- * @since 1.0.0
241
- *
242
- * @param string $group
243
- * @param string $key
244
- * @param mixed $value
245
- *
246
- * @return mixed
247
- */
248
- protected function get_const_value( $group, $key, $value ) {
249
-
250
- if ( ! $this->is_const_enabled() ) {
251
- return $value;
252
- }
253
-
254
- switch ( $group ) {
255
- case 'mail':
256
- switch ( $key ) {
257
- case 'from_name':
258
- /** @noinspection PhpUndefinedConstantInspection */
259
- return $this->is_const_defined( $group, $key ) ? WPMS_MAIL_FROM_NAME : $value;
260
- case 'from_email':
261
- /** @noinspection PhpUndefinedConstantInspection */
262
- return $this->is_const_defined( $group, $key ) ? WPMS_MAIL_FROM : $value;
263
- case 'mailer':
264
- /** @noinspection PhpUndefinedConstantInspection */
265
- return $this->is_const_defined( $group, $key ) ? WPMS_MAILER : $value;
266
- case 'return_path':
267
- return $this->is_const_defined( $group, $key ) ? true : $value;
268
- }
269
-
270
- break;
271
-
272
- case 'smtp':
273
- switch ( $key ) {
274
- case 'host':
275
- /** @noinspection PhpUndefinedConstantInspection */
276
- return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_HOST : $value;
277
- case 'port':
278
- /** @noinspection PhpUndefinedConstantInspection */
279
- return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_PORT : $value;
280
- case 'encryption':
281
- /** @noinspection PhpUndefinedConstantInspection */
282
- return $this->is_const_defined( $group, $key )
283
- ? ( WPMS_SSL === '' ? 'none' : WPMS_SSL )
284
- : $value;
285
- case 'auth':
286
- /** @noinspection PhpUndefinedConstantInspection */
287
- return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTH : $value;
288
- case 'autotls':
289
- /** @noinspection PhpUndefinedConstantInspection */
290
- return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTOTLS : $value;
291
- case 'user':
292
- /** @noinspection PhpUndefinedConstantInspection */
293
- return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_USER : $value;
294
- case 'pass':
295
- /** @noinspection PhpUndefinedConstantInspection */
296
- return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_PASS : $value;
297
- }
298
-
299
- break;
300
-
301
- case 'gmail':
302
- switch ( $key ) {
303
- case 'client_id':
304
- /** @noinspection PhpUndefinedConstantInspection */
305
- return $this->is_const_defined( $group, $key ) ? WPMS_GMAIL_CLIENT_ID : $value;
306
- case 'client_secret':
307
- /** @noinspection PhpUndefinedConstantInspection */
308
- return $this->is_const_defined( $group, $key ) ? WPMS_GMAIL_CLIENT_SECRET : $value;
309
- }
310
-
311
- break;
312
-
313
- case 'mailgun':
314
- switch ( $key ) {
315
- case 'api_key':
316
- /** @noinspection PhpUndefinedConstantInspection */
317
- return $this->is_const_defined( $group, $key ) ? WPMS_MAILGUN_API_KEY : $value;
318
- case 'domain':
319
- /** @noinspection PhpUndefinedConstantInspection */
320
- return $this->is_const_defined( $group, $key ) ? WPMS_MAILGUN_DOMAIN : $value;
321
- }
322
-
323
- break;
324
-
325
- case 'sendgrid':
326
- switch ( $key ) {
327
- case 'api_key':
328
- /** @noinspection PhpUndefinedConstantInspection */
329
- return $this->is_const_defined( $group, $key ) ? WPMS_SENDGRID_API_KEY : $value;
330
- }
331
-
332
- break;
333
- }
334
-
335
- // Always return the default value if nothing from above matches the request.
336
- return $value;
337
- }
338
-
339
- /**
340
- * Whether constants redefinition is enabled or not.
341
- *
342
- * @since 1.0.0
343
- *
344
- * @return bool
345
- */
346
- public function is_const_enabled() {
347
- return defined( 'WPMS_ON' ) && WPMS_ON === true;
348
- }
349
-
350
- /**
351
- * We need this check to reuse later in admin area,
352
- * to distinguish settings fields that were redefined,
353
- * and display them differently.
354
- *
355
- * @since 1.0.0
356
- *
357
- * @param string $group
358
- * @param string $key
359
- *
360
- * @return bool
361
- */
362
- public function is_const_defined( $group, $key ) {
363
-
364
- if ( ! $this->is_const_enabled() ) {
365
- return false;
366
- }
367
-
368
- // Just to feel safe.
369
- $group = sanitize_key( $group );
370
- $key = sanitize_key( $key );
371
-
372
- switch ( $group ) {
373
- case 'mail':
374
- switch ( $key ) {
375
- case 'from_name':
376
- return defined( 'WPMS_MAIL_FROM_NAME' ) && WPMS_MAIL_FROM_NAME;
377
- case 'from_email':
378
- return defined( 'WPMS_MAIL_FROM' ) && WPMS_MAIL_FROM;
379
- case 'mailer':
380
- return defined( 'WPMS_MAILER' ) && WPMS_MAILER;
381
- case 'return_path':
382
- return defined( 'WPMS_SET_RETURN_PATH' ) && ( WPMS_SET_RETURN_PATH === 'true' || WPMS_SET_RETURN_PATH === true );
383
- }
384
-
385
- break;
386
-
387
- case 'smtp':
388
- switch ( $key ) {
389
- case 'host':
390
- return defined( 'WPMS_SMTP_HOST' ) && WPMS_SMTP_HOST;
391
- case 'port':
392
- return defined( 'WPMS_SMTP_PORT' ) && WPMS_SMTP_PORT;
393
- case 'encryption':
394
- return defined( 'WPMS_SSL' );
395
- case 'auth':
396
- return defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH;
397
- case 'autotls':
398
- return defined( 'WPMS_SMTP_AUTOTLS' ) && WPMS_SMTP_AUTOTLS;
399
- case 'user':
400
- return defined( 'WPMS_SMTP_USER' ) && WPMS_SMTP_USER;
401
- case 'pass':
402
- return defined( 'WPMS_SMTP_PASS' ) && WPMS_SMTP_PASS;
403
- }
404
-
405
- break;
406
-
407
- case 'gmail':
408
- switch ( $key ) {
409
- case 'client_id':
410
- return defined( 'WPMS_GMAIL_CLIENT_ID' ) && WPMS_GMAIL_CLIENT_ID;
411
- case 'client_secret':
412
- return defined( 'WPMS_GMAIL_CLIENT_SECRET' ) && WPMS_GMAIL_CLIENT_SECRET;
413
- }
414
-
415
- break;
416
-
417
- case 'mailgun':
418
- switch ( $key ) {
419
- case 'api_key':
420
- return defined( 'WPMS_MAILGUN_API_KEY' ) && WPMS_MAILGUN_API_KEY;
421
- case 'domain':
422
- return defined( 'WPMS_MAILGUN_DOMAIN' ) && WPMS_MAILGUN_DOMAIN;
423
- }
424
-
425
- break;
426
-
427
- case 'sendgrid':
428
- switch ( $key ) {
429
- case 'api_key':
430
- return defined( 'WPMS_SENDGRID_API_KEY' ) && WPMS_SENDGRID_API_KEY;
431
- }
432
-
433
- break;
434
- }
435
-
436
- return false;
437
- }
438
-
439
- /**
440
- * Set plugin options, all at once.
441
- *
442
- * @since 1.0.0
443
- *
444
- * @param array $options Data to save.
445
- */
446
- public function set( $options ) {
447
-
448
- foreach ( (array) $options as $group => $keys ) {
449
- foreach ( $keys as $key_name => $key_value ) {
450
- switch ( $group ) {
451
- case 'mail':
452
- switch ( $key_name ) {
453
- case 'from_name':
454
- case 'mailer':
455
- $options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, sanitize_text_field( $options[ $group ][ $key_name ] ) );
456
- break;
457
- case 'from_email':
458
- if ( filter_var( $options[ $group ][ $key_name ], FILTER_VALIDATE_EMAIL ) ) {
459
- $options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, sanitize_email( $options[ $group ][ $key_name ] ) );
460
- }
461
- break;
462
- case 'return_path':
463
- $options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, (bool) $options[ $group ][ $key_name ] );
464
- break;
465
- }
466
- break;
467
-
468
- case 'general':
469
- switch ( $key_name ) {
470
- case 'am_notifications_hidden':
471
- $options[ $group ][ $key_name ] = (bool) $options[ $group ][ $key_name ];
472
- break;
473
- }
474
- }
475
- }
476
- }
477
-
478
- if (
479
- isset( $options[ $options['mail']['mailer'] ] ) &&
480
- in_array( $options['mail']['mailer'], array( 'pepipost', 'smtp', 'sendgrid', 'mailgun', 'gmail' ), true )
481
- ) {
482
-
483
- $mailer = $options['mail']['mailer'];
484
-
485
- foreach ( $options[ $mailer ] as $key_name => $key_value ) {
486
- switch ( $key_name ) {
487
- case 'host':
488
- case 'user':
489
- $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, sanitize_text_field( $options[ $mailer ][ $key_name ] ) );
490
- break;
491
- case 'port':
492
- $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, intval( $options[ $mailer ][ $key_name ] ) );
493
- break;
494
- case 'encryption':
495
- $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, sanitize_text_field( $options[ $mailer ][ $key_name ] ) );
496
- break;
497
- case 'auth':
498
- case 'autotls':
499
- $value = $options[ $mailer ][ $key_name ] === 'yes' || $options[ $mailer ][ $key_name ] === true ? true : false;
500
-
501
- $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, $value );
502
- break;
503
-
504
- case 'pass':
505
- case 'api_key':
506
- case 'domain':
507
- case 'client_id':
508
- case 'client_secret':
509
- case 'auth_code':
510
- case 'access_token':
511
- // Do not process as they may contain certain special characters, but allow to be overwritten using constants.
512
- $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, $options[ $mailer ][ $key_name ] );
513
- break;
514
- }
515
- }
516
- }
517
-
518
- $options = apply_filters( 'wp_mail_smtp_options_set', $options );
519
-
520
- update_option( self::META_KEY, $options );
521
-
522
- // Now we need to re-cache values.
523
- $this->populate_options();
524
- }
525
-
526
- /**
527
- * Merge recursively, including a proper substitution of values in sub-arrays when keys are the same.
528
- * It's more like array_merge() and array_merge_recursive() combined.
529
- *
530
- * @since 1.0.0
531
- *
532
- * @return array
533
- */
534
- public static function array_merge_recursive() {
535
-
536
- $arrays = func_get_args();
537
-
538
- if ( count( $arrays ) < 2 ) {
539
- return isset( $arrays[0] ) ? $arrays[0] : array();
540
- }
541
-
542
- $merged = array();
543
-
544
- while ( $arrays ) {
545
- $array = array_shift( $arrays );
546
-
547
- if ( ! is_array( $array ) ) {
548
- return array();
549
- }
550
-
551
- if ( empty( $array ) ) {
552
- continue;
553
- }
554
-
555
- foreach ( $array as $key => $value ) {
556
- if ( is_string( $key ) ) {
557
- if (
558
- is_array( $value ) &&
559
- array_key_exists( $key, $merged ) &&
560
- is_array( $merged[ $key ] )
561
- ) {
562
- $merged[ $key ] = call_user_func( __METHOD__, $merged[ $key ], $value );
563
- } else {
564
- $merged[ $key ] = $value;
565
- }
566
- } else {
567
- $merged[] = $value;
568
- }
569
- }
570
- }
571
-
572
- return $merged;
573
- }
574
-
575
- /**
576
- * Check whether the site is using Pepipost or not.
577
- *
578
- * @since 1.0.0
579
- *
580
- * @return bool
581
- */
582
- public function is_pepipost_active() {
583
- return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', $this->get( 'mail', 'mailer' ) === 'pepipost' );
584
- }
585
-
586
- /**
587
- * Check whether the site is using Pepipost/SMTP as a mailer or not.
588
- *
589
- * @since 1.1.0
590
- *
591
- * @return bool
592
- */
593
- public function is_mailer_smtp() {
594
- return apply_filters( 'wp_mail_smtp_options_is_mailer_smtp', in_array( $this->get( 'mail', 'mailer' ), array( 'pepipost', 'smtp' ), true ) );
595
- }
596
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class Options to handle all options management.
7
+ * WordPress does all the heavy work for caching get_option() data,
8
+ * so we don't have to do that. But we want to minimize cyclomatic complexity
9
+ * of calling a bunch of WP functions, thus we will cache them in a class as well.
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Options {
14
+
15
+ /**
16
+ * @var array Map of all the default options of the plugin.
17
+ */
18
+ private static $map = array(
19
+ 'mail' => array(
20
+ 'from_name',
21
+ 'from_email',
22
+ 'mailer',
23
+ 'return_path',
24
+ ),
25
+ 'smtp' => array(
26
+ 'host',
27
+ 'port',
28
+ 'encryption',
29
+ 'autotls',
30
+ 'auth',
31
+ 'user',
32
+ 'pass',
33
+ ),
34
+ 'gmail' => array(
35
+ 'client_id',
36
+ 'client_secret',
37
+ ),
38
+ 'mailgun' => array(
39
+ 'api_key',
40
+ 'domain',
41
+ ),
42
+ 'sendgrid' => array(
43
+ 'api_key',
44
+ ),
45
+ 'pepipost' => array(
46
+ 'host',
47
+ 'port',
48
+ 'encryption',
49
+ 'auth',
50
+ 'user',
51
+ 'pass',
52
+ ),
53
+ );
54
+
55
+ /**
56
+ * That's where plugin options are saved in wp_options table.
57
+ *
58
+ * @var string
59
+ */
60
+ const META_KEY = 'wp_mail_smtp';
61
+
62
+ /**
63
+ * All the plugin options.
64
+ *
65
+ * @var array
66
+ */
67
+ private $_options = array();
68
+
69
+ /**
70
+ * Init the Options class.
71
+ *
72
+ * @since 1.0.0
73
+ */
74
+ public function __construct() {
75
+ $this->populate_options();
76
+ }
77
+
78
+ /**
79
+ * Initialize all the options, used for chaining.
80
+ *
81
+ * One-liner:
82
+ * Options::init()->get('smtp', 'host');
83
+ * Options::init()->is_pepipost_active();
84
+ *
85
+ * Or multiple-usage:
86
+ * $options = new Options();
87
+ * $options->get('smtp', 'host');
88
+ *
89
+ * @since 1.0.0
90
+ *
91
+ * @return Options
92
+ */
93
+ public static function init() {
94
+
95
+ static $instance;
96
+
97
+ if ( ! $instance ) {
98
+ $instance = new self();
99
+ }
100
+
101
+ return $instance;
102
+ }
103
+
104
+ /**
105
+ * Retrieve all options of the plugin.
106
+ *
107
+ * @since 1.0.0
108
+ */
109
+ protected function populate_options() {
110
+ $this->_options = get_option( self::META_KEY, array() );
111
+ }
112
+
113
+ /**
114
+ * Get all the options.
115
+ *
116
+ * Options::init()->get_all();
117
+ *
118
+ * @since 1.0.0
119
+ *
120
+ * @return array
121
+ */
122
+ public function get_all() {
123
+
124
+ $options = $this->_options;
125
+
126
+ foreach ( $options as $group => $g_value ) {
127
+ foreach ( $g_value as $key => $value ) {
128
+ $options[ $group ][ $key ] = $this->get( $group, $key );
129
+ }
130
+ }
131
+
132
+ return apply_filters( 'wp_mail_smtp_options_get_all', $options );
133
+ }
134
+
135
+ /**
136
+ * Get all the options for a group.
137
+ *
138
+ * Options::init()->get_group('smtp') - will return only array of options (or empty array if a key doesn't exist).
139
+ *
140
+ * @since 1.0.0
141
+ *
142
+ * @param string $group
143
+ *
144
+ * @return mixed
145
+ */
146
+ public function get_group( $group ) {
147
+
148
+ // Just to feel safe.
149
+ $group = sanitize_key( $group );
150
+
151
+ if ( isset( $this->_options[ $group ] ) ) {
152
+
153
+ foreach ( $this->_options[ $group ] as $g_key => $g_value ) {
154
+ $options[ $group ][ $g_key ] = $this->get( $group, $g_key );
155
+ }
156
+
157
+ return apply_filters( 'wp_mail_smtp_options_get_group', $this->_options[ $group ], $group );
158
+ }
159
+
160
+ return array();
161
+ }
162
+
163
+ /**
164
+ * Get options by a group and a key.
165
+ *
166
+ * Options::init()->get( 'smtp', 'host' ) - will return only SMTP 'host' option.
167
+ *
168
+ * @since 1.0.0
169
+ *
170
+ * @param string $group
171
+ * @param string $key
172
+ *
173
+ * @return mixed
174
+ */
175
+ public function get( $group, $key ) {
176
+
177
+ // Just to feel safe.
178
+ $group = sanitize_key( $group );
179
+ $key = sanitize_key( $key );
180
+
181
+ // Get the options group.
182
+ if ( isset( $this->_options[ $group ] ) ) {
183
+
184
+ // Get the options key of a group.
185
+ if ( isset( $this->_options[ $group ][ $key ] ) ) {
186
+ $value = $this->get_const_value( $group, $key, $this->_options[ $group ][ $key ] );
187
+ } else {
188
+ $value = $this->postprocess_key_defaults( $group, $key );
189
+ }
190
+ } else {
191
+ $value = $this->postprocess_key_defaults( $group, $key );
192
+ }
193
+
194
+ return apply_filters( 'wp_mail_smtp_options_get', $value, $group, $key );
195
+ }
196
+
197
+ /**
198
+ * Some options may be non-empty by default,
199
+ * so we need to postprocess them to convert.
200
+ *
201
+ * @since 1.0.0
202
+ *
203
+ * @param string $group
204
+ * @param string $key
205
+ *
206
+ * @return mixed
207
+ */
208
+ protected function postprocess_key_defaults( $group, $key ) {
209
+
210
+ $value = '';
211
+
212
+ switch ( $key ) {
213
+ case 'return_path':
214
+ $value = $group === 'mail' ? false : true;
215
+ break;
216
+
217
+ case 'encryption':
218
+ $value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? 'none' : $value;
219
+ break;
220
+
221
+ case 'auth':
222
+ case 'autotls':
223
+ $value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? false : true;
224
+ break;
225
+
226
+ case 'pass':
227
+ $value = $this->get_const_value( $group, $key, $value );
228
+ break;
229
+ }
230
+
231
+ return apply_filters( 'wp_mail_smtp_options_postprocess_key_defaults', $value, $group, $key );
232
+ }
233
+
234
+ /**
235
+ * Process the options values through the constants check.
236
+ * If we have defined associated constant - use it instead of a DB value.
237
+ * Backward compatibility is hard.
238
+ * General section of options won't have constants, so we are omitting those checks and just return default value.
239
+ *
240
+ * @since 1.0.0
241
+ *
242
+ * @param string $group
243
+ * @param string $key
244
+ * @param mixed $value
245
+ *
246
+ * @return mixed
247
+ */
248
+ protected function get_const_value( $group, $key, $value ) {
249
+
250
+ if ( ! $this->is_const_enabled() ) {
251
+ return $value;
252
+ }
253
+
254
+ switch ( $group ) {
255
+ case 'mail':
256
+ switch ( $key ) {
257
+ case 'from_name':
258
+ /** @noinspection PhpUndefinedConstantInspection */
259
+ return $this->is_const_defined( $group, $key ) ? WPMS_MAIL_FROM_NAME : $value;
260
+ case 'from_email':
261
+ /** @noinspection PhpUndefinedConstantInspection */
262
+ return $this->is_const_defined( $group, $key ) ? WPMS_MAIL_FROM : $value;
263
+ case 'mailer':
264
+ /** @noinspection PhpUndefinedConstantInspection */
265
+ return $this->is_const_defined( $group, $key ) ? WPMS_MAILER : $value;
266
+ case 'return_path':
267
+ return $this->is_const_defined( $group, $key ) ? true : $value;
268
+ }
269
+
270
+ break;
271
+
272
+ case 'smtp':
273
+ switch ( $key ) {
274
+ case 'host':
275
+ /** @noinspection PhpUndefinedConstantInspection */
276
+ return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_HOST : $value;
277
+ case 'port':
278
+ /** @noinspection PhpUndefinedConstantInspection */
279
+ return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_PORT : $value;
280
+ case 'encryption':
281
+ /** @noinspection PhpUndefinedConstantInspection */
282
+ return $this->is_const_defined( $group, $key )
283
+ ? ( WPMS_SSL === '' ? 'none' : WPMS_SSL )
284
+ : $value;
285
+ case 'auth':
286
+ /** @noinspection PhpUndefinedConstantInspection */
287
+ return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTH : $value;
288
+ case 'autotls':
289
+ /** @noinspection PhpUndefinedConstantInspection */
290
+ return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTOTLS : $value;
291
+ case 'user':
292
+ /** @noinspection PhpUndefinedConstantInspection */
293
+ return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_USER : $value;
294
+ case 'pass':
295
+ /** @noinspection PhpUndefinedConstantInspection */
296
+ return $this->is_const_defined( $group, $key ) ? WPMS_SMTP_PASS : $value;
297
+ }
298
+
299
+ break;
300
+
301
+ case 'gmail':
302
+ switch ( $key ) {
303
+ case 'client_id':
304
+ /** @noinspection PhpUndefinedConstantInspection */
305
+ return $this->is_const_defined( $group, $key ) ? WPMS_GMAIL_CLIENT_ID : $value;
306
+ case 'client_secret':
307
+ /** @noinspection PhpUndefinedConstantInspection */
308
+ return $this->is_const_defined( $group, $key ) ? WPMS_GMAIL_CLIENT_SECRET : $value;
309
+ }
310
+
311
+ break;
312
+
313
+ case 'mailgun':
314
+ switch ( $key ) {
315
+ case 'api_key':
316
+ /** @noinspection PhpUndefinedConstantInspection */
317
+ return $this->is_const_defined( $group, $key ) ? WPMS_MAILGUN_API_KEY : $value;
318
+ case 'domain':
319
+ /** @noinspection PhpUndefinedConstantInspection */
320
+ return $this->is_const_defined( $group, $key ) ? WPMS_MAILGUN_DOMAIN : $value;
321
+ }
322
+
323
+ break;
324
+
325
+ case 'sendgrid':
326
+ switch ( $key ) {
327
+ case 'api_key':
328
+ /** @noinspection PhpUndefinedConstantInspection */
329
+ return $this->is_const_defined( $group, $key ) ? WPMS_SENDGRID_API_KEY : $value;
330
+ }
331
+
332
+ break;
333
+ }
334
+
335
+ // Always return the default value if nothing from above matches the request.
336
+ return $value;
337
+ }
338
+
339
+ /**
340
+ * Whether constants redefinition is enabled or not.
341
+ *
342
+ * @since 1.0.0
343
+ *
344
+ * @return bool
345
+ */
346
+ public function is_const_enabled() {
347
+ return defined( 'WPMS_ON' ) && WPMS_ON === true;
348
+ }
349
+
350
+ /**
351
+ * We need this check to reuse later in admin area,
352
+ * to distinguish settings fields that were redefined,
353
+ * and display them differently.
354
+ *
355
+ * @since 1.0.0
356
+ *
357
+ * @param string $group
358
+ * @param string $key
359
+ *
360
+ * @return bool
361
+ */
362
+ public function is_const_defined( $group, $key ) {
363
+
364
+ if ( ! $this->is_const_enabled() ) {
365
+ return false;
366
+ }
367
+
368
+ // Just to feel safe.
369
+ $group = sanitize_key( $group );
370
+ $key = sanitize_key( $key );
371
+
372
+ switch ( $group ) {
373
+ case 'mail':
374
+ switch ( $key ) {
375
+ case 'from_name':
376
+ return defined( 'WPMS_MAIL_FROM_NAME' ) && WPMS_MAIL_FROM_NAME;
377
+ case 'from_email':
378
+ return defined( 'WPMS_MAIL_FROM' ) && WPMS_MAIL_FROM;
379
+ case 'mailer':
380
+ return defined( 'WPMS_MAILER' ) && WPMS_MAILER;
381
+ case 'return_path':
382
+ return defined( 'WPMS_SET_RETURN_PATH' ) && ( WPMS_SET_RETURN_PATH === 'true' || WPMS_SET_RETURN_PATH === true );
383
+ }
384
+
385
+ break;
386
+
387
+ case 'smtp':
388
+ switch ( $key ) {
389
+ case 'host':
390
+ return defined( 'WPMS_SMTP_HOST' ) && WPMS_SMTP_HOST;
391
+ case 'port':
392
+ return defined( 'WPMS_SMTP_PORT' ) && WPMS_SMTP_PORT;
393
+ case 'encryption':
394
+ return defined( 'WPMS_SSL' );
395
+ case 'auth':
396
+ return defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH;
397
+ case 'autotls':
398
+ return defined( 'WPMS_SMTP_AUTOTLS' ) && WPMS_SMTP_AUTOTLS;
399
+ case 'user':
400
+ return defined( 'WPMS_SMTP_USER' ) && WPMS_SMTP_USER;
401
+ case 'pass':
402
+ return defined( 'WPMS_SMTP_PASS' ) && WPMS_SMTP_PASS;
403
+ }
404
+
405
+ break;
406
+
407
+ case 'gmail':
408
+ switch ( $key ) {
409
+ case 'client_id':
410
+ return defined( 'WPMS_GMAIL_CLIENT_ID' ) && WPMS_GMAIL_CLIENT_ID;
411
+ case 'client_secret':
412
+ return defined( 'WPMS_GMAIL_CLIENT_SECRET' ) && WPMS_GMAIL_CLIENT_SECRET;
413
+ }
414
+
415
+ break;
416
+
417
+ case 'mailgun':
418
+ switch ( $key ) {
419
+ case 'api_key':
420
+ return defined( 'WPMS_MAILGUN_API_KEY' ) && WPMS_MAILGUN_API_KEY;
421
+ case 'domain':
422
+ return defined( 'WPMS_MAILGUN_DOMAIN' ) && WPMS_MAILGUN_DOMAIN;
423
+ }
424
+
425
+ break;
426
+
427
+ case 'sendgrid':
428
+ switch ( $key ) {
429
+ case 'api_key':
430
+ return defined( 'WPMS_SENDGRID_API_KEY' ) && WPMS_SENDGRID_API_KEY;
431
+ }
432
+
433
+ break;
434
+ }
435
+
436
+ return false;
437
+ }
438
+
439
+ /**
440
+ * Set plugin options, all at once.
441
+ *
442
+ * @since 1.0.0
443
+ *
444
+ * @param array $options Data to save.
445
+ */
446
+ public function set( $options ) {
447
+
448
+ foreach ( (array) $options as $group => $keys ) {
449
+ foreach ( $keys as $key_name => $key_value ) {
450
+ switch ( $group ) {
451
+ case 'mail':
452
+ switch ( $key_name ) {
453
+ case 'from_name':
454
+ case 'mailer':
455
+ $options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, sanitize_text_field( $options[ $group ][ $key_name ] ) );
456
+ break;
457
+ case 'from_email':
458
+ if ( filter_var( $options[ $group ][ $key_name ], FILTER_VALIDATE_EMAIL ) ) {
459
+ $options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, sanitize_email( $options[ $group ][ $key_name ] ) );
460
+ }
461
+ break;
462
+ case 'return_path':
463
+ $options[ $group ][ $key_name ] = $this->get_const_value( $group, $key_name, (bool) $options[ $group ][ $key_name ] );
464
+ break;
465
+ }
466
+ break;
467
+
468
+ case 'general':
469
+ switch ( $key_name ) {
470
+ case 'am_notifications_hidden':
471
+ $options[ $group ][ $key_name ] = (bool) $options[ $group ][ $key_name ];
472
+ break;
473
+ }
474
+ }
475
+ }
476
+ }
477
+
478
+ if (
479
+ isset( $options[ $options['mail']['mailer'] ] ) &&
480
+ in_array( $options['mail']['mailer'], array( 'pepipost', 'smtp', 'sendgrid', 'mailgun', 'gmail' ), true )
481
+ ) {
482
+
483
+ $mailer = $options['mail']['mailer'];
484
+
485
+ foreach ( $options[ $mailer ] as $key_name => $key_value ) {
486
+ switch ( $key_name ) {
487
+ case 'host':
488
+ case 'user':
489
+ $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, sanitize_text_field( $options[ $mailer ][ $key_name ] ) );
490
+ break;
491
+ case 'port':
492
+ $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, intval( $options[ $mailer ][ $key_name ] ) );
493
+ break;
494
+ case 'encryption':
495
+ $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, sanitize_text_field( $options[ $mailer ][ $key_name ] ) );
496
+ break;
497
+ case 'auth':
498
+ case 'autotls':
499
+ $value = $options[ $mailer ][ $key_name ] === 'yes' || $options[ $mailer ][ $key_name ] === true ? true : false;
500
+
501
+ $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, $value );
502
+ break;
503
+
504
+ case 'pass':
505
+ case 'api_key':
506
+ case 'domain':
507
+ case 'client_id':
508
+ case 'client_secret':
509
+ case 'auth_code':
510
+ case 'access_token':
511
+ // Do not process as they may contain certain special characters, but allow to be overwritten using constants.
512
+ $options[ $mailer ][ $key_name ] = $this->get_const_value( $mailer, $key_name, $options[ $mailer ][ $key_name ] );
513
+ break;
514
+ }
515
+ }
516
+ }
517
+
518
+ $options = apply_filters( 'wp_mail_smtp_options_set', $options );
519
+
520
+ update_option( self::META_KEY, $options );
521
+
522
+ // Now we need to re-cache values.
523
+ $this->populate_options();
524
+ }
525
+
526
+ /**
527
+ * Merge recursively, including a proper substitution of values in sub-arrays when keys are the same.
528
+ * It's more like array_merge() and array_merge_recursive() combined.
529
+ *
530
+ * @since 1.0.0
531
+ *
532
+ * @return array
533
+ */
534
+ public static function array_merge_recursive() {
535
+
536
+ $arrays = func_get_args();
537
+
538
+ if ( count( $arrays ) < 2 ) {
539
+ return isset( $arrays[0] ) ? $arrays[0] : array();
540
+ }
541
+
542
+ $merged = array();
543
+
544
+ while ( $arrays ) {
545
+ $array = array_shift( $arrays );
546
+
547
+ if ( ! is_array( $array ) ) {
548
+ return array();
549
+ }
550
+
551
+ if ( empty( $array ) ) {
552
+ continue;
553
+ }
554
+
555
+ foreach ( $array as $key => $value ) {
556
+ if ( is_string( $key ) ) {
557
+ if (
558
+ is_array( $value ) &&
559
+ array_key_exists( $key, $merged ) &&
560
+ is_array( $merged[ $key ] )
561
+ ) {
562
+ $merged[ $key ] = call_user_func( __METHOD__, $merged[ $key ], $value );
563
+ } else {
564
+ $merged[ $key ] = $value;
565
+ }
566
+ } else {
567
+ $merged[] = $value;
568
+ }
569
+ }
570
+ }
571
+
572
+ return $merged;
573
+ }
574
+
575
+ /**
576
+ * Check whether the site is using Pepipost or not.
577
+ *
578
+ * @since 1.0.0
579
+ *
580
+ * @return bool
581
+ */
582
+ public function is_pepipost_active() {
583
+ return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', $this->get( 'mail', 'mailer' ) === 'pepipost' );
584
+ }
585
+
586
+ /**
587
+ * Check whether the site is using Pepipost/SMTP as a mailer or not.
588
+ *
589
+ * @since 1.1.0
590
+ *
591
+ * @return bool
592
+ */
593
+ public function is_mailer_smtp() {
594
+ return apply_filters( 'wp_mail_smtp_options_is_mailer_smtp', in_array( $this->get( 'mail', 'mailer' ), array( 'pepipost', 'smtp' ), true ) );
595
+ }
596
+ }
src/Processor.php CHANGED
@@ -1,175 +1,175 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class Processor modifies the behaviour of wp_mail() function.
7
- *
8
- * @since 1.0.0
9
- */
10
- class Processor {
11
-
12
- /**
13
- * Processor constructor.
14
- *
15
- * @since 1.0.0
16
- */
17
- public function __construct() {
18
- $this->hooks();
19
- }
20
-
21
- /**
22
- * Assign all hooks to proper places.
23
- *
24
- * @since 1.0.0
25
- */
26
- public function hooks() {
27
-
28
- add_action( 'phpmailer_init', array( $this, 'phpmailer_init' ) );
29
-
30
- add_filter( 'wp_mail_from', array( $this, 'filter_mail_from_email' ) );
31
- add_filter( 'wp_mail_from_name', array( $this, 'filter_mail_from_name' ), 11 );
32
- }
33
-
34
- /**
35
- * Redefine certain PHPMailer options with our custom ones.
36
- *
37
- * @since 1.0.0
38
- *
39
- * @param \PHPMailer $phpmailer It's passed by reference, so no need to return anything.
40
- */
41
- public function phpmailer_init( $phpmailer ) {
42
-
43
- $options = new Options();
44
- $mailer = $options->get( 'mail', 'mailer' );
45
-
46
- // Check that mailer is not blank, and if mailer=smtp, host is not blank.
47
- if (
48
- ! $mailer ||
49
- ( 'smtp' === $mailer && ! $options->get( 'smtp', 'host' ) )
50
- ) {
51
- return;
52
- }
53
-
54
- // If the mailer is pepipost, make sure we have a username and password.
55
- if (
56
- 'pepipost' === $mailer &&
57
- ( ! $options->get( 'pepipost', 'user' ) && ! $options->get( 'pepipost', 'pass' ) )
58
- ) {
59
- return;
60
- }
61
-
62
- // Set the mailer type as per config above, this overrides the already called isMail method.
63
- // It's basically always 'smtp'.
64
- $phpmailer->Mailer = $mailer;
65
-
66
- // Set the Sender (return-path) if required.
67
- if ( $options->get( 'mail', 'return_path' ) ) {
68
- $phpmailer->Sender = $phpmailer->From;
69
- }
70
-
71
- // Set the SMTPSecure value, if set to none, leave this blank. Possible values: 'ssl', 'tls', ''.
72
- if ( 'none' === $options->get( $mailer, 'encryption' ) ) {
73
- $phpmailer->SMTPSecure = '';
74
- } else {
75
- $phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' );
76
- }
77
-
78
- // Check if user has disabled SMTPAutoTLS.
79
- if ( $options->get( $mailer, 'encryption' ) !== 'tls' && ! $options->get( $mailer, 'autotls' ) ) {
80
- $phpmailer->SMTPAutoTLS = false;
81
- }
82
-
83
- // If we're sending via SMTP, set the host.
84
- if ( 'smtp' === $mailer ) {
85
- // Set the other options.
86
- $phpmailer->Host = $options->get( $mailer, 'host' );
87
- $phpmailer->Port = $options->get( $mailer, 'port' );
88
-
89
- // If we're using smtp auth, set the username & password.
90
- if ( $options->get( $mailer, 'auth' ) ) {
91
- $phpmailer->SMTPAuth = true;
92
- $phpmailer->Username = $options->get( $mailer, 'user' );
93
- $phpmailer->Password = $options->get( $mailer, 'pass' );
94
- }
95
- } elseif ( 'pepipost' === $mailer ) {
96
- // Set the Pepipost settings for BC.
97
- $phpmailer->Mailer = 'smtp';
98
- $phpmailer->Host = 'smtp.pepipost.com';
99
- $phpmailer->Port = $options->get( $mailer, 'port' );
100
- $phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' ) === 'none' ? '' : $options->get( $mailer, 'encryption' );
101
- $phpmailer->SMTPAuth = true;
102
- $phpmailer->Username = $options->get( $mailer, 'user' );
103
- $phpmailer->Password = $options->get( $mailer, 'pass' );
104
- }
105
-
106
- // You can add your own options here.
107
- // See the phpmailer documentation for more info: https://github.com/PHPMailer/PHPMailer/tree/5.2-stable.
108
- /** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */
109
- $phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer );
110
- }
111
-
112
- /**
113
- * Modify the email address that is used for sending emails.
114
- *
115
- * @since 1.0.0
116
- *
117
- * @param string $email
118
- *
119
- * @return string
120
- */
121
- public function filter_mail_from_email( $email ) {
122
-
123
- // If the from email is not the default, return it unchanged.
124
- if ( $email !== $this->get_default_email() ) {
125
- return $email;
126
- }
127
-
128
- $from_email = Options::init()->get( 'mail', 'from_email' );
129
-
130
- if ( ! empty( $from_email ) ) {
131
- return $from_email;
132
- }
133
-
134
- return $email;
135
- }
136
-
137
- /**
138
- * Modify the sender name that is used for sending emails.
139
- *
140
- * @since 1.0.0
141
- *
142
- * @param string $name
143
- *
144
- * @return string
145
- */
146
- public function filter_mail_from_name( $name ) {
147
-
148
- if ( 'WordPress' === $name ) {
149
- $name = Options::init()->get( 'mail', 'from_name' );
150
- }
151
-
152
- return $name;
153
- }
154
-
155
- /**
156
- * Get the default email address based on domain name.
157
- *
158
- * @since 1.0.0
159
- *
160
- * @return string
161
- */
162
- public function get_default_email() {
163
-
164
- // In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
165
- $server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
166
-
167
- // Get the site domain and get rid of www.
168
- $sitename = strtolower( $server_name );
169
- if ( substr( $sitename, 0, 4 ) === 'www.' ) {
170
- $sitename = substr( $sitename, 4 );
171
- }
172
-
173
- return 'wordpress@' . $sitename;
174
- }
175
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class Processor modifies the behaviour of wp_mail() function.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ class Processor {
11
+
12
+ /**
13
+ * Processor constructor.
14
+ *
15
+ * @since 1.0.0
16
+ */
17
+ public function __construct() {
18
+ $this->hooks();
19
+ }
20
+
21
+ /**
22
+ * Assign all hooks to proper places.
23
+ *
24
+ * @since 1.0.0
25
+ */
26
+ public function hooks() {
27
+
28
+ add_action( 'phpmailer_init', array( $this, 'phpmailer_init' ) );
29
+
30
+ add_filter( 'wp_mail_from', array( $this, 'filter_mail_from_email' ) );
31
+ add_filter( 'wp_mail_from_name', array( $this, 'filter_mail_from_name' ), 11 );
32
+ }
33
+
34
+ /**
35
+ * Redefine certain PHPMailer options with our custom ones.
36
+ *
37
+ * @since 1.0.0
38
+ *
39
+ * @param \PHPMailer $phpmailer It's passed by reference, so no need to return anything.
40
+ */
41
+ public function phpmailer_init( $phpmailer ) {
42
+
43
+ $options = new Options();
44
+ $mailer = $options->get( 'mail', 'mailer' );
45
+
46
+ // Check that mailer is not blank, and if mailer=smtp, host is not blank.
47
+ if (
48
+ ! $mailer ||
49
+ ( 'smtp' === $mailer && ! $options->get( 'smtp', 'host' ) )
50
+ ) {
51
+ return;
52
+ }
53
+
54
+ // If the mailer is pepipost, make sure we have a username and password.
55
+ if (
56
+ 'pepipost' === $mailer &&
57
+ ( ! $options->get( 'pepipost', 'user' ) && ! $options->get( 'pepipost', 'pass' ) )
58
+ ) {
59
+ return;
60
+ }
61
+
62
+ // Set the mailer type as per config above, this overrides the already called isMail method.
63
+ // It's basically always 'smtp'.
64
+ $phpmailer->Mailer = $mailer;
65
+
66
+ // Set the Sender (return-path) if required.
67
+ if ( $options->get( 'mail', 'return_path' ) ) {
68
+ $phpmailer->Sender = $phpmailer->From;
69
+ }
70
+
71
+ // Set the SMTPSecure value, if set to none, leave this blank. Possible values: 'ssl', 'tls', ''.
72
+ if ( 'none' === $options->get( $mailer, 'encryption' ) ) {
73
+ $phpmailer->SMTPSecure = '';
74
+ } else {
75
+ $phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' );
76
+ }
77
+
78
+ // Check if user has disabled SMTPAutoTLS.
79
+ if ( $options->get( $mailer, 'encryption' ) !== 'tls' && ! $options->get( $mailer, 'autotls' ) ) {
80
+ $phpmailer->SMTPAutoTLS = false;
81
+ }
82
+
83
+ // If we're sending via SMTP, set the host.
84
+ if ( 'smtp' === $mailer ) {
85
+ // Set the other options.
86
+ $phpmailer->Host = $options->get( $mailer, 'host' );
87
+ $phpmailer->Port = $options->get( $mailer, 'port' );
88
+
89
+ // If we're using smtp auth, set the username & password.
90
+ if ( $options->get( $mailer, 'auth' ) ) {
91
+ $phpmailer->SMTPAuth = true;
92
+ $phpmailer->Username = $options->get( $mailer, 'user' );
93
+ $phpmailer->Password = $options->get( $mailer, 'pass' );
94
+ }
95
+ } elseif ( 'pepipost' === $mailer ) {
96
+ // Set the Pepipost settings for BC.
97
+ $phpmailer->Mailer = 'smtp';
98
+ $phpmailer->Host = 'smtp.pepipost.com';
99
+ $phpmailer->Port = $options->get( $mailer, 'port' );
100
+ $phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' ) === 'none' ? '' : $options->get( $mailer, 'encryption' );
101
+ $phpmailer->SMTPAuth = true;
102
+ $phpmailer->Username = $options->get( $mailer, 'user' );
103
+ $phpmailer->Password = $options->get( $mailer, 'pass' );
104
+ }
105
+
106
+ // You can add your own options here.
107
+ // See the phpmailer documentation for more info: https://github.com/PHPMailer/PHPMailer/tree/5.2-stable.
108
+ /** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */
109
+ $phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer );
110
+ }
111
+
112
+ /**
113
+ * Modify the email address that is used for sending emails.
114
+ *
115
+ * @since 1.0.0
116
+ *
117
+ * @param string $email
118
+ *
119
+ * @return string
120
+ */
121
+ public function filter_mail_from_email( $email ) {
122
+
123
+ // If the from email is not the default, return it unchanged.
124
+ if ( $email !== $this->get_default_email() ) {
125
+ return $email;
126
+ }
127
+
128
+ $from_email = Options::init()->get( 'mail', 'from_email' );
129
+
130
+ if ( ! empty( $from_email ) ) {
131
+ return $from_email;
132
+ }
133
+
134
+ return $email;
135
+ }
136
+
137
+ /**
138
+ * Modify the sender name that is used for sending emails.
139
+ *
140
+ * @since 1.0.0
141
+ *
142
+ * @param string $name
143
+ *
144
+ * @return string
145
+ */
146
+ public function filter_mail_from_name( $name ) {
147
+
148
+ if ( 'WordPress' === $name ) {
149
+ $name = Options::init()->get( 'mail', 'from_name' );
150
+ }
151
+
152
+ return $name;
153
+ }
154
+
155
+ /**
156
+ * Get the default email address based on domain name.
157
+ *
158
+ * @since 1.0.0
159
+ *
160
+ * @return string
161
+ */
162
+ public function get_default_email() {
163
+
164
+ // In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
165
+ $server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
166
+
167
+ // Get the site domain and get rid of www.
168
+ $sitename = strtolower( $server_name );
169
+ if ( substr( $sitename, 0, 4 ) === 'www.' ) {
170
+ $sitename = substr( $sitename, 4 );
171
+ }
172
+
173
+ return 'wordpress@' . $sitename;
174
+ }
175
+ }
src/Providers/AuthAbstract.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- /**
6
- * Class AuthAbstract.
7
- *
8
- * @since 1.0.0
9
- */
10
- abstract class AuthAbstract implements AuthInterface {
11
-
12
- /**
13
- * Get the url, that users will be redirected back to finish the OAuth process.
14
- *
15
- * @since 1.0.0
16
- *
17
- * @return string
18
- */
19
- public static function get_plugin_auth_url() {
20
- return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
21
- }
22
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ /**
6
+ * Class AuthAbstract.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ abstract class AuthAbstract implements AuthInterface {
11
+
12
+ /**
13
+ * Get the url, that users will be redirected back to finish the OAuth process.
14
+ *
15
+ * @since 1.0.0
16
+ *
17
+ * @return string
18
+ */
19
+ public static function get_plugin_auth_url() {
20
+ return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
21
+ }
22
+ }
src/Providers/AuthInterface.php CHANGED
@@ -1,19 +1,19 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- /**
6
- * Interface AuthInterface.
7
- *
8
- * @since 1.0.0
9
- */
10
- interface AuthInterface {
11
-
12
- /**
13
- * Do something for this Auth implementation.
14
- *
15
- * @since 1.0.0
16
- */
17
- public function process();
18
-
19
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ /**
6
+ * Interface AuthInterface.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ interface AuthInterface {
11
+
12
+ /**
13
+ * Do something for this Auth implementation.
14
+ *
15
+ * @since 1.0.0
16
+ */
17
+ public function process();
18
+
19
+ }
src/Providers/Gmail/Auth.php CHANGED
@@ -1,321 +1,321 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Gmail;
4
-
5
- use WPMailSMTP\Debug;
6
- use WPMailSMTP\Options as PluginOptions;
7
- use WPMailSMTP\Providers\AuthAbstract;
8
-
9
- /**
10
- * Class Auth to request access and refresh tokens.
11
- *
12
- * @since 1.0.0
13
- */
14
- class Auth extends AuthAbstract {
15
-
16
- /**
17
- * Gmail options.
18
- *
19
- * @var array
20
- */
21
- private $gmail;
22
-
23
- /**
24
- * @var \Google_Client
25
- */
26
- private $client;
27
-
28
- /**
29
- * @var string
30
- */
31
- private $mailer;
32
-
33
- /**
34
- * Auth constructor.
35
- *
36
- * @since 1.0.0
37
- */
38
- public function __construct() {
39
-
40
- $options = new PluginOptions();
41
- $this->mailer = $options->get( 'mail', 'mailer' );
42
-
43
- if ( $this->mailer !== 'gmail' ) {
44
- return;
45
- }
46
-
47
- $this->gmail = $options->get_group( $this->mailer );
48
-
49
- if ( $this->is_clients_saved() ) {
50
-
51
- $this->include_google_lib();
52
-
53
- $this->client = $this->get_client();
54
- }
55
- }
56
-
57
- /**
58
- * Use the composer autoloader to include the Google Library and all its dependencies.
59
- *
60
- * @since 1.0.0
61
- */
62
- protected function include_google_lib() {
63
- require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
64
- }
65
-
66
- /**
67
- * Init and get the Google Client object.
68
- *
69
- * @since 1.0.0
70
- */
71
- public function get_client() {
72
-
73
- // Doesn't load client twice + gives ability to overwrite.
74
- if ( ! empty( $this->client ) ) {
75
- return $this->client;
76
- }
77
-
78
- $client = new \Google_Client(
79
- array(
80
- 'client_id' => $this->gmail['client_id'],
81
- 'client_secret' => $this->gmail['client_secret'],
82
- 'redirect_uris' => array(
83
- Auth::get_plugin_auth_url(),
84
- ),
85
- )
86
- );
87
- $client->setAccessType( 'offline' );
88
- $client->setApprovalPrompt( 'force' );
89
- $client->setIncludeGrantedScopes( true );
90
- // We request only the sending capability, as it's what we only need to do.
91
- $client->setScopes( array( \Google_Service_Gmail::GMAIL_SEND ) );
92
- $client->setRedirectUri( self::get_plugin_auth_url() );
93
-
94
- if (
95
- empty( $this->gmail['access_token'] ) &&
96
- ! empty( $this->gmail['auth_code'] )
97
- ) {
98
- try {
99
- $creds = $client->fetchAccessTokenWithAuthCode( $this->gmail['auth_code'] );
100
- } catch ( \Exception $e ) {
101
- $creds['error'] = $e->getMessage();
102
- Debug::set( $e->getMessage() );
103
- }
104
-
105
- // Bail if we have an error.
106
- if ( ! empty( $creds['error'] ) ) {
107
- // TODO: save this error to display to a user later.
108
- return $client;
109
- }
110
-
111
- $this->update_access_token( $client->getAccessToken() );
112
- $this->update_refresh_token( $client->getRefreshToken() );
113
- }
114
-
115
- if ( ! empty( $this->gmail['access_token'] ) ) {
116
- $client->setAccessToken( $this->gmail['access_token'] );
117
- }
118
-
119
- // Refresh the token if it's expired.
120
- if ( $client->isAccessTokenExpired() ) {
121
- $refresh = $client->getRefreshToken();
122
- if ( empty( $refresh ) && isset( $this->gmail['refresh_token'] ) ) {
123
- $refresh = $this->gmail['refresh_token'];
124
- }
125
-
126
- if ( ! empty( $refresh ) ) {
127
- try {
128
- $creds = $client->fetchAccessTokenWithRefreshToken( $refresh );
129
- } catch ( \Exception $e ) {
130
- $creds['error'] = $e->getMessage();
131
- Debug::set( $e->getMessage() );
132
- }
133
-
134
- // Bail if we have an error.
135
- if ( ! empty( $creds['error'] ) ) {
136
- return $client;
137
- }
138
-
139
- $this->update_access_token( $client->getAccessToken() );
140
- $this->update_refresh_token( $client->getRefreshToken() );
141
- }
142
- }
143
-
144
- return $client;
145
- }
146
-
147
- /**
148
- * Get the auth code from the $_GET and save it.
149
- * Redirect user back to settings with an error message, if failed.
150
- *
151
- * @since 1.0.0
152
- */
153
- public function process() {
154
-
155
- // We can't process without saved client_id/secret.
156
- if ( ! $this->is_clients_saved() ) {
157
- Debug::set( 'There was an error while processing the Google authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.' );
158
- wp_redirect(
159
- add_query_arg(
160
- 'error',
161
- 'google_no_clients',
162
- wp_mail_smtp()->get_admin()->get_admin_page_url()
163
- )
164
- );
165
- exit;
166
- }
167
-
168
- $code = '';
169
- $scope = '';
170
- $error = '';
171
-
172
- if ( isset( $_GET['error'] ) ) {
173
- $error = sanitize_key( $_GET['error'] );
174
- }
175
-
176
- // In case of any error: display a message to a user.
177
- if ( ! empty( $error ) ) {
178
- wp_redirect(
179
- add_query_arg(
180
- 'error',
181
- 'google_' . $error,
182
- wp_mail_smtp()->get_admin()->get_admin_page_url()
183
- )
184
- );
185
- exit;
186
- }
187
-
188
- if ( isset( $_GET['code'] ) ) {
189
- $code = $_GET['code'];
190
- }
191
- if ( isset( $_GET['scope'] ) ) {
192
- $scope = urldecode( $_GET['scope'] );
193
- }
194
-
195
- // Let's try to get the access token.
196
- if (
197
- ! empty( $code ) &&
198
- (
199
- $scope === ( \Google_Service_Gmail::GMAIL_SEND . ' ' . \Google_Service_Gmail::MAIL_GOOGLE_COM ) ||
200
- $scope === \Google_Service_Gmail::GMAIL_SEND
201
- )
202
- ) {
203
- // Save the auth code. So \Google_Client can reuse it to retrieve the access token.
204
- $this->update_auth_code( $code );
205
- } else {
206
- wp_redirect(
207
- add_query_arg(
208
- 'error',
209
- 'google_no_code_scope',
210
- wp_mail_smtp()->get_admin()->get_admin_page_url()
211
- )
212
- );
213
- exit;
214
- }
215
-
216
- wp_redirect(
217
- add_query_arg(
218
- 'success',
219
- 'google_site_linked',
220
- wp_mail_smtp()->get_admin()->get_admin_page_url()
221
- )
222
- );
223
- exit;
224
- }
225
-
226
- /**
227
- * Update access token in our DB.
228
- *
229
- * @since 1.0.0
230
- *
231
- * @param array $token
232
- */
233
- protected function update_access_token( $token ) {
234
-
235
- $options = new PluginOptions();
236
- $all = $options->get_all();
237
-
238
- $all[ $this->mailer ]['access_token'] = $token;
239
- $this->gmail['access_token'] = $token;
240
-
241
- $options->set( $all );
242
- }
243
-
244
- /**
245
- * Update refresh token in our DB.
246
- *
247
- * @since 1.0.0
248
- *
249
- * @param array $token
250
- */
251
- protected function update_refresh_token( $token ) {
252
-
253
- $options = new PluginOptions();
254
- $all = $options->get_all();
255
-
256
- $all[ $this->mailer ]['refresh_token'] = $token;
257
- $this->gmail['refresh_token'] = $token;
258
-
259
- $options->set( $all );
260
- }
261
-
262
- /**
263
- * Update auth code in our DB.
264
- *
265
- * @since 1.0.0
266
- *
267
- * @param string $code
268
- */
269
- protected function update_auth_code( $code ) {
270
-
271
- $options = new PluginOptions();
272
- $all = $options->get_all();
273
-
274
- $all[ $this->mailer ]['auth_code'] = $code;
275
- $this->gmail['auth_code'] = $code;
276
-
277
- $options->set( $all );
278
- }
279
-
280
- /**
281
- * Get the auth URL used to proceed to Google to request access to send emails.
282
- *
283
- * @since 1.0.0
284
- *
285
- * @return string
286
- */
287
- public function get_google_auth_url() {
288
- if (
289
- ! empty( $this->client ) &&
290
- class_exists( 'Google_Client', false ) &&
291
- $this->client instanceof \Google_Client
292
- ) {
293
- return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
294
- }
295
-
296
- return '';
297
- }
298
-
299
- /**
300
- * Whether user saved Client ID and Client Secret or not.
301
- * Both options are required.
302
- *
303
- * @since 1.0.0
304
- *
305
- * @return bool
306
- */
307
- public function is_clients_saved() {
308
- return ! empty( $this->gmail['client_id'] ) && ! empty( $this->gmail['client_secret'] );
309
- }
310
-
311
- /**
312
- * Whether we have an access and refresh tokens or not.
313
- *
314
- * @since 1.0.0
315
- *
316
- * @return bool
317
- */
318
- public function is_auth_required() {
319
- return empty( $this->gmail['access_token'] ) || empty( $this->gmail['refresh_token'] );
320
- }
321
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Gmail;
4
+
5
+ use WPMailSMTP\Debug;
6
+ use WPMailSMTP\Options as PluginOptions;
7
+ use WPMailSMTP\Providers\AuthAbstract;
8
+
9
+ /**
10
+ * Class Auth to request access and refresh tokens.
11
+ *
12
+ * @since 1.0.0
13
+ */
14
+ class Auth extends AuthAbstract {
15
+
16
+ /**
17
+ * Gmail options.
18
+ *
19
+ * @var array
20
+ */
21
+ private $gmail;
22
+
23
+ /**
24
+ * @var \Google_Client
25
+ */
26
+ private $client;
27
+
28
+ /**
29
+ * @var string
30
+ */
31
+ private $mailer;
32
+
33
+ /**
34
+ * Auth constructor.
35
+ *
36
+ * @since 1.0.0
37
+ */
38
+ public function __construct() {
39
+
40
+ $options = new PluginOptions();
41
+ $this->mailer = $options->get( 'mail', 'mailer' );
42
+
43
+ if ( $this->mailer !== 'gmail' ) {
44
+ return;
45
+ }
46
+
47
+ $this->gmail = $options->get_group( $this->mailer );
48
+
49
+ if ( $this->is_clients_saved() ) {
50
+
51
+ $this->include_google_lib();
52
+
53
+ $this->client = $this->get_client();
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Use the composer autoloader to include the Google Library and all its dependencies.
59
+ *
60
+ * @since 1.0.0
61
+ */
62
+ protected function include_google_lib() {
63
+ require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
64
+ }
65
+
66
+ /**
67
+ * Init and get the Google Client object.
68
+ *
69
+ * @since 1.0.0
70
+ */
71
+ public function get_client() {
72
+
73
+ // Doesn't load client twice + gives ability to overwrite.
74
+ if ( ! empty( $this->client ) ) {
75
+ return $this->client;
76
+ }
77
+
78
+ $client = new \Google_Client(
79
+ array(
80
+ 'client_id' => $this->gmail['client_id'],
81
+ 'client_secret' => $this->gmail['client_secret'],
82
+ 'redirect_uris' => array(
83
+ Auth::get_plugin_auth_url(),
84
+ ),
85
+ )
86
+ );
87
+ $client->setAccessType( 'offline' );
88
+ $client->setApprovalPrompt( 'force' );
89
+ $client->setIncludeGrantedScopes( true );
90
+ // We request only the sending capability, as it's what we only need to do.
91
+ $client->setScopes( array( \Google_Service_Gmail::GMAIL_SEND ) );
92
+ $client->setRedirectUri( self::get_plugin_auth_url() );
93
+
94
+ if (
95
+ empty( $this->gmail['access_token'] ) &&
96
+ ! empty( $this->gmail['auth_code'] )
97
+ ) {
98
+ try {
99
+ $creds = $client->fetchAccessTokenWithAuthCode( $this->gmail['auth_code'] );
100
+ } catch ( \Exception $e ) {
101
+ $creds['error'] = $e->getMessage();
102
+ Debug::set( $e->getMessage() );
103
+ }
104
+
105
+ // Bail if we have an error.
106
+ if ( ! empty( $creds['error'] ) ) {
107
+ // TODO: save this error to display to a user later.
108
+ return $client;
109
+ }
110
+
111
+ $this->update_access_token( $client->getAccessToken() );
112
+ $this->update_refresh_token( $client->getRefreshToken() );
113
+ }
114
+
115
+ if ( ! empty( $this->gmail['access_token'] ) ) {
116
+ $client->setAccessToken( $this->gmail['access_token'] );
117
+ }
118
+
119
+ // Refresh the token if it's expired.
120
+ if ( $client->isAccessTokenExpired() ) {
121
+ $refresh = $client->getRefreshToken();
122
+ if ( empty( $refresh ) && isset( $this->gmail['refresh_token'] ) ) {
123
+ $refresh = $this->gmail['refresh_token'];
124
+ }
125
+
126
+ if ( ! empty( $refresh ) ) {
127
+ try {
128
+ $creds = $client->fetchAccessTokenWithRefreshToken( $refresh );
129
+ } catch ( \Exception $e ) {
130
+ $creds['error'] = $e->getMessage();
131
+ Debug::set( $e->getMessage() );
132
+ }
133
+
134
+ // Bail if we have an error.
135
+ if ( ! empty( $creds['error'] ) ) {
136
+ return $client;
137
+ }
138
+
139
+ $this->update_access_token( $client->getAccessToken() );
140
+ $this->update_refresh_token( $client->getRefreshToken() );
141
+ }
142
+ }
143
+
144
+ return $client;
145
+ }
146
+
147
+ /**
148
+ * Get the auth code from the $_GET and save it.
149
+ * Redirect user back to settings with an error message, if failed.
150
+ *
151
+ * @since 1.0.0
152
+ */
153
+ public function process() {
154
+
155
+ // We can't process without saved client_id/secret.
156
+ if ( ! $this->is_clients_saved() ) {
157
+ Debug::set( 'There was an error while processing the Google authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.' );
158
+ wp_redirect(
159
+ add_query_arg(
160
+ 'error',
161
+ 'google_no_clients',
162
+ wp_mail_smtp()->get_admin()->get_admin_page_url()
163
+ )
164
+ );
165
+ exit;
166
+ }
167
+
168
+ $code = '';
169
+ $scope = '';
170
+ $error = '';
171
+
172
+ if ( isset( $_GET['error'] ) ) {
173
+ $error = sanitize_key( $_GET['error'] );
174
+ }
175
+
176
+ // In case of any error: display a message to a user.
177
+ if ( ! empty( $error ) ) {
178
+ wp_redirect(
179
+ add_query_arg(
180
+ 'error',
181
+ 'google_' . $error,
182
+ wp_mail_smtp()->get_admin()->get_admin_page_url()
183
+ )
184
+ );
185
+ exit;
186
+ }
187
+
188
+ if ( isset( $_GET['code'] ) ) {
189
+ $code = $_GET['code'];
190
+ }
191
+ if ( isset( $_GET['scope'] ) ) {
192
+ $scope = urldecode( $_GET['scope'] );
193
+ }
194
+
195
+ // Let's try to get the access token.
196
+ if (
197
+ ! empty( $code ) &&
198
+ (
199
+ $scope === ( \Google_Service_Gmail::GMAIL_SEND . ' ' . \Google_Service_Gmail::MAIL_GOOGLE_COM ) ||
200
+ $scope === \Google_Service_Gmail::GMAIL_SEND
201
+ )
202
+ ) {
203
+ // Save the auth code. So \Google_Client can reuse it to retrieve the access token.
204
+ $this->update_auth_code( $code );
205
+ } else {
206
+ wp_redirect(
207
+ add_query_arg(
208
+ 'error',
209
+ 'google_no_code_scope',
210
+ wp_mail_smtp()->get_admin()->get_admin_page_url()
211
+ )
212
+ );
213
+ exit;
214
+ }
215
+
216
+ wp_redirect(
217
+ add_query_arg(
218
+ 'success',
219
+ 'google_site_linked',
220
+ wp_mail_smtp()->get_admin()->get_admin_page_url()
221
+ )
222
+ );
223
+ exit;
224
+ }
225
+
226
+ /**
227
+ * Update access token in our DB.
228
+ *
229
+ * @since 1.0.0
230
+ *
231
+ * @param array $token
232
+ */
233
+ protected function update_access_token( $token ) {
234
+
235
+ $options = new PluginOptions();
236
+ $all = $options->get_all();
237
+
238
+ $all[ $this->mailer ]['access_token'] = $token;
239
+ $this->gmail['access_token'] = $token;
240
+
241
+ $options->set( $all );
242
+ }
243
+
244
+ /**
245
+ * Update refresh token in our DB.
246
+ *
247
+ * @since 1.0.0
248
+ *
249
+ * @param array $token
250
+ */
251
+ protected function update_refresh_token( $token ) {
252
+
253
+ $options = new PluginOptions();
254
+ $all = $options->get_all();
255
+
256
+ $all[ $this->mailer ]['refresh_token'] = $token;
257
+ $this->gmail['refresh_token'] = $token;
258
+
259
+ $options->set( $all );
260
+ }
261
+
262
+ /**
263
+ * Update auth code in our DB.
264
+ *
265
+ * @since 1.0.0
266
+ *
267
+ * @param string $code
268
+ */
269
+ protected function update_auth_code( $code ) {
270
+
271
+ $options = new PluginOptions();
272
+ $all = $options->get_all();
273
+
274
+ $all[ $this->mailer ]['auth_code'] = $code;
275
+ $this->gmail['auth_code'] = $code;
276
+
277
+ $options->set( $all );
278
+ }
279
+
280
+ /**
281
+ * Get the auth URL used to proceed to Google to request access to send emails.
282
+ *
283
+ * @since 1.0.0
284
+ *
285
+ * @return string
286
+ */
287
+ public function get_google_auth_url() {
288
+ if (
289
+ ! empty( $this->client ) &&
290
+ class_exists( 'Google_Client', false ) &&
291
+ $this->client instanceof \Google_Client
292
+ ) {
293
+ return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
294
+ }
295
+
296
+ return '';
297
+ }
298
+
299
+ /**
300
+ * Whether user saved Client ID and Client Secret or not.
301
+ * Both options are required.
302
+ *
303
+ * @since 1.0.0
304
+ *
305
+ * @return bool
306
+ */
307
+ public function is_clients_saved() {
308
+ return ! empty( $this->gmail['client_id'] ) && ! empty( $this->gmail['client_secret'] );
309
+ }
310
+
311
+ /**
312
+ * Whether we have an access and refresh tokens or not.
313
+ *
314
+ * @since 1.0.0
315
+ *
316
+ * @return bool
317
+ */
318
+ public function is_auth_required() {
319
+ return empty( $this->gmail['access_token'] ) || empty( $this->gmail['refresh_token'] );
320
+ }
321
+ }
src/Providers/Gmail/Mailer.php CHANGED
@@ -1,162 +1,162 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Gmail;
4
-
5
- use WPMailSMTP\Debug;
6
- use WPMailSMTP\MailCatcher;
7
- use WPMailSMTP\Providers\MailerAbstract;
8
-
9
- /**
10
- * Class Mailer.
11
- *
12
- * @since 1.0.0
13
- */
14
- class Mailer extends MailerAbstract {
15
-
16
- /**
17
- * URL to make an API request to.
18
- * Not used for Gmail, as we are using its API.
19
- *
20
- * @var string
21
- */
22
- protected $url = 'https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send';
23
-
24
- /**
25
- * Gmail custom Auth library.
26
- *
27
- * @var Auth
28
- */
29
- protected $auth;
30
-
31
- /**
32
- * Gmail message.
33
- *
34
- * @var \Google_Service_Gmail_Message
35
- */
36
- protected $message;
37
-
38
- /**
39
- * Mailer constructor.
40
- *
41
- * @since 1.0.0
42
- *
43
- * @param \WPMailSMTP\MailCatcher $phpmailer
44
- */
45
- public function __construct( $phpmailer ) {
46
- parent::__construct( $phpmailer );
47
-
48
- if ( ! $this->is_php_compatible() ) {
49
- return;
50
- }
51
-
52
- // Include the Google library.
53
- require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
54
-
55
- $this->auth = new Auth();
56
- $this->message = new \Google_Service_Gmail_Message();
57
- }
58
-
59
- /**
60
- * Re-use the MailCatcher class methods and properties.
61
- *
62
- * @since 1.2.0
63
- *
64
- * @param \WPMailSMTP\MailCatcher $phpmailer
65
- */
66
- public function process_phpmailer( $phpmailer ) {
67
- // Make sure that we have access to MailCatcher class methods.
68
- if (
69
- ! $phpmailer instanceof MailCatcher &&
70
- ! $phpmailer instanceof \PHPMailer
71
- ) {
72
- return;
73
- }
74
-
75
- $this->phpmailer = $phpmailer;
76
- }
77
-
78
- /**
79
- * Use Google API Services to send emails.
80
- *
81
- * @since 1.0.0
82
- */
83
- public function send() {
84
-
85
- // Get the raw MIME email using \MailCatcher data.
86
- $base64 = base64_encode( $this->phpmailer->getSentMIMEMessage() );
87
- $base64 = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $base64 ); // url safe.
88
- $this->message->setRaw( $base64 );
89
-
90
- $service = new \Google_Service_Gmail( $this->auth->get_client() );
91
-
92
- try {
93
- $response = $service->users_messages->send( 'me', $this->message );
94
-
95
- $this->process_response( $response );
96
- } catch ( \Exception $e ) {
97
- Debug::set( 'Error while sending via Gmail mailer: ' . $e->getMessage() );
98
-
99
- return;
100
- }
101
- }
102
-
103
- /**
104
- * Save response from the API to use it later.
105
- *
106
- * @since 1.0.0
107
- *
108
- * @param \Google_Service_Gmail_Message $response
109
- */
110
- protected function process_response( $response ) {
111
- $this->response = $response;
112
- }
113
-
114
- /**
115
- * Check whether the email was sent.
116
- *
117
- * @since 1.0.0
118
- *
119
- * @return bool
120
- */
121
- public function is_email_sent() {
122
- $is_sent = false;
123
-
124
- if ( method_exists( $this->response, 'getId' ) ) {
125
- $message_id = $this->response->getId();
126
- if ( ! empty( $message_id ) ) {
127
- return true;
128
- }
129
- }
130
-
131
- return $is_sent;
132
- }
133
-
134
- /**
135
- * @inheritdoc
136
- */
137
- public function get_debug_info() {
138
-
139
- $gmail_text = array();
140
-
141
- $options = new \WPMailSMTP\Options();
142
- $gmail = $options->get_group( 'gmail' );
143
-
144
- $gmail_text[] = '<strong>Client ID/Secret:</strong> ' . ( ! empty( $gmail['client_id'] ) && ! empty( $gmail['client_secret'] ) ? 'Yes' : 'No' );
145
- $gmail_text[] = '<strong>Auth Code:</strong> ' . ( ! empty( $gmail['auth_code'] ) ? 'Yes' : 'No' );
146
- $gmail_text[] = '<strong>Access Token:</strong> ' . ( ! empty( $gmail['access_token'] ) ? 'Yes' : 'No' );
147
-
148
- $gmail_text[] = '<br><strong>Server:</strong>';
149
-
150
- $gmail_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
151
- $gmail_text[] = '<strong>PHP.allow_url_fopen:</strong> ' . ( ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No' );
152
- $gmail_text[] = '<strong>PHP.stream_socket_client():</strong> ' . ( function_exists( 'stream_socket_client' ) ? 'Yes' : 'No' );
153
- $gmail_text[] = '<strong>PHP.fsockopen():</strong> ' . ( function_exists( 'fsockopen' ) ? 'Yes' : 'No' );
154
- $gmail_text[] = '<strong>PHP.curl_version():</strong> ' . ( function_exists( 'curl_version' ) ? 'Yes' : 'No' );
155
- if ( function_exists( 'apache_get_modules' ) ) {
156
- $modules = apache_get_modules();
157
- $gmail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
158
- }
159
-
160
- return implode( '<br>', $gmail_text );
161
- }
162
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Gmail;
4
+
5
+ use WPMailSMTP\Debug;
6
+ use WPMailSMTP\MailCatcher;
7
+ use WPMailSMTP\Providers\MailerAbstract;
8
+
9
+ /**
10
+ * Class Mailer.
11
+ *
12
+ * @since 1.0.0
13
+ */
14
+ class Mailer extends MailerAbstract {
15
+
16
+ /**
17
+ * URL to make an API request to.
18
+ * Not used for Gmail, as we are using its API.
19
+ *
20
+ * @var string
21
+ */
22
+ protected $url = 'https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send';
23
+
24
+ /**
25
+ * Gmail custom Auth library.
26
+ *
27
+ * @var Auth
28
+ */
29
+ protected $auth;
30
+
31
+ /**
32
+ * Gmail message.
33
+ *
34
+ * @var \Google_Service_Gmail_Message
35
+ */
36
+ protected $message;
37
+
38
+ /**
39
+ * Mailer constructor.
40
+ *
41
+ * @since 1.0.0
42
+ *
43
+ * @param \WPMailSMTP\MailCatcher $phpmailer
44
+ */
45
+ public function __construct( $phpmailer ) {
46
+ parent::__construct( $phpmailer );
47
+
48
+ if ( ! $this->is_php_compatible() ) {
49
+ return;
50
+ }
51
+
52
+ // Include the Google library.
53
+ require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
54
+
55
+ $this->auth = new Auth();
56
+ $this->message = new \Google_Service_Gmail_Message();
57
+ }
58
+
59
+ /**
60
+ * Re-use the MailCatcher class methods and properties.
61
+ *
62
+ * @since 1.2.0
63
+ *
64
+ * @param \WPMailSMTP\MailCatcher $phpmailer
65
+ */
66
+ public function process_phpmailer( $phpmailer ) {
67
+ // Make sure that we have access to MailCatcher class methods.
68
+ if (
69
+ ! $phpmailer instanceof MailCatcher &&
70
+ ! $phpmailer instanceof \PHPMailer
71
+ ) {
72
+ return;
73
+ }
74
+
75
+ $this->phpmailer = $phpmailer;
76
+ }
77
+
78
+ /**
79
+ * Use Google API Services to send emails.
80
+ *
81
+ * @since 1.0.0
82
+ */
83
+ public function send() {
84
+
85
+ // Get the raw MIME email using \MailCatcher data.
86
+ $base64 = base64_encode( $this->phpmailer->getSentMIMEMessage() );
87
+ $base64 = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $base64 ); // url safe.
88
+ $this->message->setRaw( $base64 );
89
+
90
+ $service = new \Google_Service_Gmail( $this->auth->get_client() );
91
+
92
+ try {
93
+ $response = $service->users_messages->send( 'me', $this->message );
94
+
95
+ $this->process_response( $response );
96
+ } catch ( \Exception $e ) {
97
+ Debug::set( 'Error while sending via Gmail mailer: ' . $e->getMessage() );
98
+
99
+ return;
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Save response from the API to use it later.
105
+ *
106
+ * @since 1.0.0
107
+ *
108
+ * @param \Google_Service_Gmail_Message $response
109
+ */
110
+ protected function process_response( $response ) {
111
+ $this->response = $response;
112
+ }
113
+
114
+ /**
115
+ * Check whether the email was sent.
116
+ *
117
+ * @since 1.0.0
118
+ *
119
+ * @return bool
120
+ */
121
+ public function is_email_sent() {
122
+ $is_sent = false;
123
+
124
+ if ( method_exists( $this->response, 'getId' ) ) {
125
+ $message_id = $this->response->getId();
126
+ if ( ! empty( $message_id ) ) {
127
+ return true;
128
+ }
129
+ }
130
+
131
+ return $is_sent;
132
+ }
133
+
134
+ /**
135
+ * @inheritdoc
136
+ */
137
+ public function get_debug_info() {
138
+
139
+ $gmail_text = array();
140
+
141
+ $options = new \WPMailSMTP\Options();
142
+ $gmail = $options->get_group( 'gmail' );
143
+
144
+ $gmail_text[] = '<strong>Client ID/Secret:</strong> ' . ( ! empty( $gmail['client_id'] ) && ! empty( $gmail['client_secret'] ) ? 'Yes' : 'No' );
145
+ $gmail_text[] = '<strong>Auth Code:</strong> ' . ( ! empty( $gmail['auth_code'] ) ? 'Yes' : 'No' );
146
+ $gmail_text[] = '<strong>Access Token:</strong> ' . ( ! empty( $gmail['access_token'] ) ? 'Yes' : 'No' );
147
+
148
+ $gmail_text[] = '<br><strong>Server:</strong>';
149
+
150
+ $gmail_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
151
+ $gmail_text[] = '<strong>PHP.allow_url_fopen:</strong> ' . ( ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No' );
152
+ $gmail_text[] = '<strong>PHP.stream_socket_client():</strong> ' . ( function_exists( 'stream_socket_client' ) ? 'Yes' : 'No' );
153
+ $gmail_text[] = '<strong>PHP.fsockopen():</strong> ' . ( function_exists( 'fsockopen' ) ? 'Yes' : 'No' );
154
+ $gmail_text[] = '<strong>PHP.curl_version():</strong> ' . ( function_exists( 'curl_version' ) ? 'Yes' : 'No' );
155
+ if ( function_exists( 'apache_get_modules' ) ) {
156
+ $modules = apache_get_modules();
157
+ $gmail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
158
+ }
159
+
160
+ return implode( '<br>', $gmail_text );
161
+ }
162
+ }
src/Providers/Gmail/Options.php CHANGED
@@ -1,131 +1,131 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Gmail;
4
-
5
- use WPMailSMTP\Providers\OptionsAbstract;
6
-
7
- /**
8
- * Class Option.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Options extends OptionsAbstract {
13
-
14
- /**
15
- * Mailgun constructor.
16
- *
17
- * @since 1.0.0
18
- */
19
- public function __construct() {
20
-
21
- parent::__construct(
22
- array(
23
- 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/gmail.png',
24
- 'slug' => 'gmail',
25
- 'title' => esc_html__( 'Gmail', 'wp-mail-smtp' ),
26
- 'description' => sprintf(
27
- wp_kses(
28
- /* translators: %1$s - opening link tag; %2$s - closing link tag. */
29
- __( 'Send emails using your Gmail or G Suite (formerly Google Apps) account, all while keeping your login credentials safe. Other Google SMTP methods require enabling less secure apps in your account and entering your password. However, this integration uses the Google API to improve email delivery issues while keeping your site secure.<br><br>Read our %1$sGmail documentation%2$s to learn how to configure Gmail or G Suite.', 'wp-mail-smtp' ),
30
- array(
31
- 'br' => array(),
32
- 'a' => array(
33
- 'href' => array(),
34
- 'rel' => array(),
35
- 'target' => array(),
36
- ),
37
- )
38
- ),
39
- '<a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" target="_blank" rel="noopener noreferrer">',
40
- '</a>'
41
- ),
42
- 'php' => '5.5',
43
- )
44
- );
45
- }
46
-
47
- /**
48
- * @inheritdoc
49
- */
50
- public function display_options() {
51
-
52
- // Do not display options if PHP version is not correct.
53
- if ( ! $this->is_php_correct() ) {
54
- $this->display_php_warning();
55
-
56
- return;
57
- }
58
- ?>
59
-
60
- <!-- Client ID -->
61
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
62
- <div class="wp-mail-smtp-setting-label">
63
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"><?php esc_html_e( 'Client ID', 'wp-mail-smtp' ); ?></label>
64
- </div>
65
- <div class="wp-mail-smtp-setting-field">
66
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_id]" type="text"
67
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_id' ) ); ?>"
68
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'client_id' ) ? 'disabled' : ''; ?>
69
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" spellcheck="false"
70
- />
71
- </div>
72
- </div>
73
-
74
- <!-- Client Secret -->
75
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
76
- <div class="wp-mail-smtp-setting-label">
77
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"><?php esc_html_e( 'Client Secret', 'wp-mail-smtp' ); ?></label>
78
- </div>
79
- <div class="wp-mail-smtp-setting-field">
80
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]" type="text"
81
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_secret' ) ); ?>"
82
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'client_secret' ) ? 'disabled' : ''; ?>
83
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" spellcheck="false"
84
- />
85
- </div>
86
- </div>
87
-
88
- <!-- Authorized redirect URI -->
89
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
90
- <div class="wp-mail-smtp-setting-label">
91
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"><?php esc_html_e( 'Authorized redirect URI', 'wp-mail-smtp' ); ?></label>
92
- </div>
93
- <div class="wp-mail-smtp-setting-field">
94
- <input type="text" readonly="readonly"
95
- value="<?php echo esc_attr( Auth::get_plugin_auth_url() ); ?>"
96
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
97
- />
98
- <button type="button" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-light-grey wp-mail-smtp-setting-copy"
99
- title="<?php esc_attr_e( 'Copy URL to clipboard', 'wp-mail-smtp' ); ?>"
100
- data-source_id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect">
101
- <span class="dashicons dashicons-admin-page"></span>
102
- </button>
103
- <p class="desc">
104
- <?php esc_html_e( 'This is the path on your site that you will be redirected to after you have authenticated with Google.', 'wp-mail-smtp' ); ?>
105
- <br>
106
- <?php esc_html_e( 'You need to copy this URL into "Authorized redirect URIs" field for you web application on Google APIs site for your project there.', 'wp-mail-smtp' ); ?>
107
- </p>
108
- </div>
109
- </div>
110
-
111
- <!-- Auth users button -->
112
- <?php $auth = new Auth(); ?>
113
- <?php if ( $auth->is_clients_saved() && $auth->is_auth_required() ) : ?>
114
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
115
- <div class="wp-mail-smtp-setting-label">
116
- <label><?php esc_html_e( 'Authorize', 'wp-mail-smtp' ); ?></label>
117
- </div>
118
- <div class="wp-mail-smtp-setting-field">
119
- <a href="<?php echo esc_url( $auth->get_google_auth_url() ); ?>" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange">
120
- <?php esc_html_e( 'Allow plugin to send emails using your Google account', 'wp-mail-smtp' ); ?>
121
- </a>
122
- <p class="desc">
123
- <?php esc_html_e( 'Click the button above to confirm authorization.', 'wp-mail-smtp' ); ?>
124
- </p>
125
- </div>
126
- </div>
127
- <?php endif; ?>
128
-
129
- <?php
130
- }
131
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Gmail;
4
+
5
+ use WPMailSMTP\Providers\OptionsAbstract;
6
+
7
+ /**
8
+ * Class Option.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Options extends OptionsAbstract {
13
+
14
+ /**
15
+ * Mailgun constructor.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ public function __construct() {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/gmail.png',
24
+ 'slug' => 'gmail',
25
+ 'title' => esc_html__( 'Gmail', 'wp-mail-smtp' ),
26
+ 'description' => sprintf(
27
+ wp_kses(
28
+ /* translators: %1$s - opening link tag; %2$s - closing link tag. */
29
+ __( 'Send emails using your Gmail or G Suite (formerly Google Apps) account, all while keeping your login credentials safe. Other Google SMTP methods require enabling less secure apps in your account and entering your password. However, this integration uses the Google API to improve email delivery issues while keeping your site secure.<br><br>Read our %1$sGmail documentation%2$s to learn how to configure Gmail or G Suite.', 'wp-mail-smtp' ),
30
+ array(
31
+ 'br' => array(),
32
+ 'a' => array(
33
+ 'href' => array(),
34
+ 'rel' => array(),
35
+ 'target' => array(),
36
+ ),
37
+ )
38
+ ),
39
+ '<a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" target="_blank" rel="noopener noreferrer">',
40
+ '</a>'
41
+ ),
42
+ 'php' => '5.5',
43
+ )
44
+ );
45
+ }
46
+
47
+ /**
48
+ * @inheritdoc
49
+ */
50
+ public function display_options() {
51
+
52
+ // Do not display options if PHP version is not correct.
53
+ if ( ! $this->is_php_correct() ) {
54
+ $this->display_php_warning();
55
+
56
+ return;
57
+ }
58
+ ?>
59
+
60
+ <!-- Client ID -->
61
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
62
+ <div class="wp-mail-smtp-setting-label">
63
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"><?php esc_html_e( 'Client ID', 'wp-mail-smtp' ); ?></label>
64
+ </div>
65
+ <div class="wp-mail-smtp-setting-field">
66
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_id]" type="text"
67
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_id' ) ); ?>"
68
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'client_id' ) ? 'disabled' : ''; ?>
69
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" spellcheck="false"
70
+ />
71
+ </div>
72
+ </div>
73
+
74
+ <!-- Client Secret -->
75
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
76
+ <div class="wp-mail-smtp-setting-label">
77
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"><?php esc_html_e( 'Client Secret', 'wp-mail-smtp' ); ?></label>
78
+ </div>
79
+ <div class="wp-mail-smtp-setting-field">
80
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]" type="text"
81
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_secret' ) ); ?>"
82
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'client_secret' ) ? 'disabled' : ''; ?>
83
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" spellcheck="false"
84
+ />
85
+ </div>
86
+ </div>
87
+
88
+ <!-- Authorized redirect URI -->
89
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
90
+ <div class="wp-mail-smtp-setting-label">
91
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"><?php esc_html_e( 'Authorized redirect URI', 'wp-mail-smtp' ); ?></label>
92
+ </div>
93
+ <div class="wp-mail-smtp-setting-field">
94
+ <input type="text" readonly="readonly"
95
+ value="<?php echo esc_attr( Auth::get_plugin_auth_url() ); ?>"
96
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
97
+ />
98
+ <button type="button" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-light-grey wp-mail-smtp-setting-copy"
99
+ title="<?php esc_attr_e( 'Copy URL to clipboard', 'wp-mail-smtp' ); ?>"
100
+ data-source_id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect">
101
+ <span class="dashicons dashicons-admin-page"></span>
102
+ </button>
103
+ <p class="desc">
104
+ <?php esc_html_e( 'This is the path on your site that you will be redirected to after you have authenticated with Google.', 'wp-mail-smtp' ); ?>
105
+ <br>
106
+ <?php esc_html_e( 'You need to copy this URL into "Authorized redirect URIs" field for you web application on Google APIs site for your project there.', 'wp-mail-smtp' ); ?>
107
+ </p>
108
+ </div>
109
+ </div>
110
+
111
+ <!-- Auth users button -->
112
+ <?php $auth = new Auth(); ?>
113
+ <?php if ( $auth->is_clients_saved() && $auth->is_auth_required() ) : ?>
114
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
115
+ <div class="wp-mail-smtp-setting-label">
116
+ <label><?php esc_html_e( 'Authorize', 'wp-mail-smtp' ); ?></label>
117
+ </div>
118
+ <div class="wp-mail-smtp-setting-field">
119
+ <a href="<?php echo esc_url( $auth->get_google_auth_url() ); ?>" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange">
120
+ <?php esc_html_e( 'Allow plugin to send emails using your Google account', 'wp-mail-smtp' ); ?>
121
+ </a>
122
+ <p class="desc">
123
+ <?php esc_html_e( 'Click the button above to confirm authorization.', 'wp-mail-smtp' ); ?>
124
+ </p>
125
+ </div>
126
+ </div>
127
+ <?php endif; ?>
128
+
129
+ <?php
130
+ }
131
+ }
src/Providers/Loader.php CHANGED
@@ -1,182 +1,182 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- use WPMailSMTP\Debug;
6
- use WPMailSMTP\MailCatcher;
7
-
8
- /**
9
- * Class Loader.
10
- *
11
- * @since 1.0.0
12
- */
13
- class Loader {
14
-
15
- /**
16
- * Key is the mailer option, value is the path to its classes.
17
- *
18
- * @var array
19
- */
20
- protected $providers = array(
21
- 'mail' => '\WPMailSMTP\Providers\Mail\\',
22
- 'gmail' => '\WPMailSMTP\Providers\Gmail\\',
23
- 'mailgun' => '\WPMailSMTP\Providers\Mailgun\\',
24
- 'sendgrid' => '\WPMailSMTP\Providers\Sendgrid\\',
25
- 'pepipost' => '\WPMailSMTP\Providers\Pepipost\\',
26
- 'smtp' => '\WPMailSMTP\Providers\SMTP\\',
27
- );
28
-
29
- /**
30
- * @var \WPMailSMTP\MailCatcher
31
- */
32
- private $phpmailer;
33
-
34
- /**
35
- * Get all the supported providers.
36
- *
37
- * @since 1.0.0
38
- *
39
- * @return array
40
- */
41
- public function get_providers() {
42
- return apply_filters( 'wp_mail_smtp_providers_loader_get_providers', $this->providers );
43
- }
44
-
45
- /**
46
- * Get a single provider FQN-path based on its name.
47
- *
48
- * @since 1.0.0
49
- *
50
- * @param string $provider
51
- *
52
- * @return array
53
- */
54
- public function get_provider_path( $provider ) {
55
- $provider = sanitize_key( $provider );
56
-
57
- return apply_filters(
58
- 'wp_mail_smtp_providers_loader_get_provider_path',
59
- isset( $this->providers[ $provider ] ) ? $this->providers[ $provider ] : null,
60
- $provider
61
- );
62
- }
63
-
64
- /**
65
- * Get the provider options, if exists.
66
- *
67
- * @since 1.0.0
68
- *
69
- * @param string $provider
70
- *
71
- * @return \WPMailSMTP\Providers\OptionsAbstract|null
72
- */
73
- public function get_options( $provider ) {
74
- return $this->get_entity( $provider, 'Options' );
75
- }
76
-
77
- /**
78
- * Get all options of all providers.
79
- *
80
- * @since 1.0.0
81
- *
82
- * @return \WPMailSMTP\Providers\OptionsAbstract[]
83
- */
84
- public function get_options_all() {
85
- $options = array();
86
-
87
- foreach ( $this->get_providers() as $provider => $path ) {
88
-
89
- $option = $this->get_options( $provider );
90
-
91
- if ( ! $option instanceof OptionsAbstract ) {
92
- continue;
93
- }
94
-
95
- $slug = $option->get_slug();
96
- $title = $option->get_title();
97
-
98
- if ( empty( $title ) || empty( $slug ) ) {
99
- continue;
100
- }
101
-
102
- $options[] = $option;
103
- }
104
-
105
- return apply_filters( 'wp_mail_smtp_providers_loader_get_providers_all', $options );
106
- }
107
-
108
- /**
109
- * Get the provider mailer, if exists.
110
- *
111
- * @since 1.0.0
112
- *
113
- * @param string $provider
114
- * @param MailCatcher $phpmailer
115
- *
116
- * @return \WPMailSMTP\Providers\MailerAbstract|null
117
- */
118
- public function get_mailer( $provider, $phpmailer ) {
119
-
120
- if (
121
- $phpmailer instanceof MailCatcher ||
122
- $phpmailer instanceof \PHPMailer
123
- ) {
124
- $this->phpmailer = $phpmailer;
125
- }
126
-
127
- return $this->get_entity( $provider, 'Mailer' );
128
- }
129
-
130
- /**
131
- * Get the provider auth, if exists.
132
- *
133
- * @param string $provider
134
- *
135
- * @return \WPMailSMTP\Providers\AuthAbstract|null
136
- */
137
- public function get_auth( $provider ) {
138
- return $this->get_entity( $provider, 'Auth' );
139
- }
140
-
141
- /**
142
- * Get a generic entity based on the request.
143
- *
144
- * @uses ReflectionClass
145
- *
146
- * @since 1.0.0
147
- *
148
- * @param string $provider
149
- * @param string $request
150
- *
151
- * @return null
152
- */
153
- protected function get_entity( $provider, $request ) {
154
-
155
- $provider = sanitize_key( $provider );
156
- $request = sanitize_text_field( $request );
157
- $path = $this->get_provider_path( $provider );
158
- $entity = null;
159
-
160
- if ( empty( $path ) ) {
161
- return $entity;
162
- }
163
-
164
- try {
165
- $reflection = new \ReflectionClass( $path . $request );
166
-
167
- if ( file_exists( $reflection->getFileName() ) ) {
168
- $class = $path . $request;
169
- if ( $this->phpmailer ) {
170
- $entity = new $class( $this->phpmailer );
171
- } else {
172
- $entity = new $class();
173
- }
174
- }
175
- } catch ( \Exception $e ) {
176
- Debug::set( "There was a problem while retrieving {$request} for {$provider}: {$e->getMessage()}" );
177
- $entity = null;
178
- }
179
-
180
- return apply_filters( 'wp_mail_smtp_providers_loader_get_entity', $entity, $provider, $request );
181
- }
182
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ use WPMailSMTP\Debug;
6
+ use WPMailSMTP\MailCatcher;
7
+
8
+ /**
9
+ * Class Loader.
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Loader {
14
+
15
+ /**
16
+ * Key is the mailer option, value is the path to its classes.
17
+ *
18
+ * @var array
19
+ */
20
+ protected $providers = array(
21
+ 'mail' => '\WPMailSMTP\Providers\Mail\\',
22
+ 'gmail' => '\WPMailSMTP\Providers\Gmail\\',
23
+ 'mailgun' => '\WPMailSMTP\Providers\Mailgun\\',
24
+ 'sendgrid' => '\WPMailSMTP\Providers\Sendgrid\\',
25
+ 'pepipost' => '\WPMailSMTP\Providers\Pepipost\\',
26
+ 'smtp' => '\WPMailSMTP\Providers\SMTP\\',
27
+ );
28
+
29
+ /**
30
+ * @var \WPMailSMTP\MailCatcher
31
+ */
32
+ private $phpmailer;
33
+
34
+ /**
35
+ * Get all the supported providers.
36
+ *
37
+ * @since 1.0.0
38
+ *
39
+ * @return array
40
+ */
41
+ public function get_providers() {
42
+ return apply_filters( 'wp_mail_smtp_providers_loader_get_providers', $this->providers );
43
+ }
44
+
45
+ /**
46
+ * Get a single provider FQN-path based on its name.
47
+ *
48
+ * @since 1.0.0
49
+ *
50
+ * @param string $provider
51
+ *
52
+ * @return array
53
+ */
54
+ public function get_provider_path( $provider ) {
55
+ $provider = sanitize_key( $provider );
56
+
57
+ return apply_filters(
58
+ 'wp_mail_smtp_providers_loader_get_provider_path',
59
+ isset( $this->providers[ $provider ] ) ? $this->providers[ $provider ] : null,
60
+ $provider
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Get the provider options, if exists.
66
+ *
67
+ * @since 1.0.0
68
+ *
69
+ * @param string $provider
70
+ *
71
+ * @return \WPMailSMTP\Providers\OptionsAbstract|null
72
+ */
73
+ public function get_options( $provider ) {
74
+ return $this->get_entity( $provider, 'Options' );
75
+ }
76
+
77
+ /**
78
+ * Get all options of all providers.
79
+ *
80
+ * @since 1.0.0
81
+ *
82
+ * @return \WPMailSMTP\Providers\OptionsAbstract[]
83
+ */
84
+ public function get_options_all() {
85
+ $options = array();
86
+
87
+ foreach ( $this->get_providers() as $provider => $path ) {
88
+
89
+ $option = $this->get_options( $provider );
90
+
91
+ if ( ! $option instanceof OptionsAbstract ) {
92
+ continue;
93
+ }
94
+
95
+ $slug = $option->get_slug();
96
+ $title = $option->get_title();
97
+
98
+ if ( empty( $title ) || empty( $slug ) ) {
99
+ continue;
100
+ }
101
+
102
+ $options[] = $option;
103
+ }
104
+
105
+ return apply_filters( 'wp_mail_smtp_providers_loader_get_providers_all', $options );
106
+ }
107
+
108
+ /**
109
+ * Get the provider mailer, if exists.
110
+ *
111
+ * @since 1.0.0
112
+ *
113
+ * @param string $provider
114
+ * @param MailCatcher $phpmailer
115
+ *
116
+ * @return \WPMailSMTP\Providers\MailerAbstract|null
117
+ */
118
+ public function get_mailer( $provider, $phpmailer ) {
119
+
120
+ if (
121
+ $phpmailer instanceof MailCatcher ||
122
+ $phpmailer instanceof \PHPMailer
123
+ ) {
124
+ $this->phpmailer = $phpmailer;
125
+ }
126
+
127
+ return $this->get_entity( $provider, 'Mailer' );
128
+ }
129
+
130
+ /**
131
+ * Get the provider auth, if exists.
132
+ *
133
+ * @param string $provider
134
+ *
135
+ * @return \WPMailSMTP\Providers\AuthAbstract|null
136
+ */
137
+ public function get_auth( $provider ) {
138
+ return $this->get_entity( $provider, 'Auth' );
139
+ }
140
+
141
+ /**
142
+ * Get a generic entity based on the request.
143
+ *
144
+ * @uses ReflectionClass
145
+ *
146
+ * @since 1.0.0
147
+ *
148
+ * @param string $provider
149
+ * @param string $request
150
+ *
151
+ * @return null
152
+ */
153
+ protected function get_entity( $provider, $request ) {
154
+
155
+ $provider = sanitize_key( $provider );
156
+ $request = sanitize_text_field( $request );
157
+ $path = $this->get_provider_path( $provider );
158
+ $entity = null;
159
+
160
+ if ( empty( $path ) ) {
161
+ return $entity;
162
+ }
163
+
164
+ try {
165
+ $reflection = new \ReflectionClass( $path . $request );
166
+
167
+ if ( file_exists( $reflection->getFileName() ) ) {
168
+ $class = $path . $request;
169
+ if ( $this->phpmailer ) {
170
+ $entity = new $class( $this->phpmailer );
171
+ } else {
172
+ $entity = new $class();
173
+ }
174
+ }
175
+ } catch ( \Exception $e ) {
176
+ Debug::set( "There was a problem while retrieving {$request} for {$provider}: {$e->getMessage()}" );
177
+ $entity = null;
178
+ }
179
+
180
+ return apply_filters( 'wp_mail_smtp_providers_loader_get_entity', $entity, $provider, $request );
181
+ }
182
+ }
src/Providers/Mail/Mailer.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Mail;
4
-
5
- use WPMailSMTP\Providers\MailerAbstract;
6
-
7
- /**
8
- * Class Mailer inherits everything from parent abstract class.
9
- * This file is required for a proper work of Loader and \ReflectionClass.
10
- *
11
- * @package WPMailSMTP\Providers\Mail
12
- */
13
- class Mailer extends MailerAbstract {
14
-
15
- /**
16
- * @inheritdoc
17
- */
18
- public function get_debug_info() {
19
-
20
- $mail_text = array();
21
-
22
- $mail_text[] = '<br><strong>Server:</strong>';
23
-
24
- $disabled_functions = ini_get( 'disable_functions' );
25
- $disabled = (array) explode( ',', trim( $disabled_functions ) );
26
-
27
- $mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
28
- if ( function_exists( 'apache_get_modules' ) ) {
29
- $modules = apache_get_modules();
30
- $mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
31
- }
32
-
33
- return implode( '<br>', $mail_text );
34
- }
35
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Mail;
4
+
5
+ use WPMailSMTP\Providers\MailerAbstract;
6
+
7
+ /**
8
+ * Class Mailer inherits everything from parent abstract class.
9
+ * This file is required for a proper work of Loader and \ReflectionClass.
10
+ *
11
+ * @package WPMailSMTP\Providers\Mail
12
+ */
13
+ class Mailer extends MailerAbstract {
14
+
15
+ /**
16
+ * @inheritdoc
17
+ */
18
+ public function get_debug_info() {
19
+
20
+ $mail_text = array();
21
+
22
+ $mail_text[] = '<br><strong>Server:</strong>';
23
+
24
+ $disabled_functions = ini_get( 'disable_functions' );
25
+ $disabled = (array) explode( ',', trim( $disabled_functions ) );
26
+
27
+ $mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
28
+ if ( function_exists( 'apache_get_modules' ) ) {
29
+ $modules = apache_get_modules();
30
+ $mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
31
+ }
32
+
33
+ return implode( '<br>', $mail_text );
34
+ }
35
+ }
src/Providers/Mail/Options.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Mail;
4
-
5
- use WPMailSMTP\Providers\OptionsAbstract;
6
-
7
- /**
8
- * Class Option.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Options extends OptionsAbstract {
13
-
14
- /**
15
- * Mail constructor.
16
- *
17
- * @since 1.0.0
18
- */
19
- public function __construct() {
20
-
21
- parent::__construct(
22
- array(
23
- 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/php.png',
24
- 'slug' => 'mail',
25
- 'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
26
- )
27
- );
28
- }
29
-
30
- /**
31
- * @inheritdoc
32
- */
33
- public function display_options() {
34
- ?>
35
-
36
- <blockquote>
37
- <?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
38
- </blockquote>
39
-
40
- <?php
41
- }
42
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Mail;
4
+
5
+ use WPMailSMTP\Providers\OptionsAbstract;
6
+
7
+ /**
8
+ * Class Option.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Options extends OptionsAbstract {
13
+
14
+ /**
15
+ * Mail constructor.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ public function __construct() {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/php.png',
24
+ 'slug' => 'mail',
25
+ 'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
26
+ )
27
+ );
28
+ }
29
+
30
+ /**
31
+ * @inheritdoc
32
+ */
33
+ public function display_options() {
34
+ ?>
35
+
36
+ <blockquote>
37
+ <?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
38
+ </blockquote>
39
+
40
+ <?php
41
+ }
42
+ }
src/Providers/MailerAbstract.php CHANGED
@@ -1,366 +1,366 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- use WPMailSMTP\Debug;
6
- use WPMailSMTP\MailCatcher;
7
- use WPMailSMTP\Options;
8
-
9
- /**
10
- * Class MailerAbstract.
11
- *
12
- * @since 1.0.0
13
- */
14
- abstract class MailerAbstract implements MailerInterface {
15
-
16
- /**
17
- * Which response code from HTTP provider is considered to be successful?
18
- *
19
- * @var int
20
- */
21
- protected $email_sent_code = 200;
22
- /**
23
- * @var Options
24
- */
25
- protected $options;
26
- /**
27
- * @var MailCatcher
28
- */
29
- protected $phpmailer;
30
- /**
31
- * @var string
32
- */
33
- protected $mailer = '';
34
-
35
- /**
36
- * URL to make an API request to.
37
- *
38
- * @var string
39
- */
40
- protected $url = '';
41
- /**
42
- * @var array
43
- */
44
- protected $headers = array();
45
- /**
46
- * @var array
47
- */
48
- protected $body = array();
49
- /**
50
- * @var mixed
51
- */
52
- protected $response = array();
53
-
54
- /**
55
- * Mailer constructor.
56
- *
57
- * @since 1.0.0
58
- *
59
- * @param MailCatcher $phpmailer
60
- */
61
- public function __construct( MailCatcher $phpmailer ) {
62
-
63
- $this->options = new Options();
64
- $this->mailer = $this->options->get( 'mail', 'mailer' );
65
-
66
- // Only non-SMTP mailers need URL.
67
- if ( ! $this->options->is_mailer_smtp() && empty( $this->url ) ) {
68
- return;
69
- }
70
-
71
- $this->process_phpmailer( $phpmailer );
72
- }
73
-
74
- /**
75
- * Re-use the MailCatcher class methods and properties.
76
- *
77
- * @since 1.0.0
78
- *
79
- * @param MailCatcher $phpmailer
80
- */
81
- public function process_phpmailer( $phpmailer ) {
82
-
83
- // Make sure that we have access to MailCatcher class methods.
84
- if (
85
- ! $phpmailer instanceof MailCatcher &&
86
- ! $phpmailer instanceof \PHPMailer
87
- ) {
88
- return;
89
- }
90
-
91
- $this->phpmailer = $phpmailer;
92
-
93
- // Prevent working with those methods, as they are not needed for SMTP-like mailers.
94
- if ( $this->options->is_mailer_smtp() ) {
95
- return;
96
- }
97
-
98
- $this->set_headers( $this->phpmailer->getCustomHeaders() );
99
- $this->set_from( $this->phpmailer->From, $this->phpmailer->FromName );
100
- $this->set_recipients(
101
- array(
102
- 'to' => $this->phpmailer->getToAddresses(),
103
- 'cc' => $this->phpmailer->getCcAddresses(),
104
- 'bcc' => $this->phpmailer->getBccAddresses(),
105
- )
106
- );
107
- $this->set_subject( $this->phpmailer->Subject );
108
- $this->set_content(
109
- array(
110
- 'html' => $this->phpmailer->Body,
111
- 'text' => $this->phpmailer->AltBody,
112
- )
113
- );
114
- $this->set_return_path( $this->phpmailer->From );
115
- $this->set_reply_to( $this->phpmailer->getReplyToAddresses() );
116
-
117
- /*
118
- * In some cases we will need to modify the internal structure
119
- * of the body content, if attachments are present.
120
- * So lets make this call the last one.
121
- */
122
- $this->set_attachments( $this->phpmailer->getAttachments() );
123
- }
124
-
125
- /**
126
- * @inheritdoc
127
- */
128
- public function set_subject( $subject ) {
129
-
130
- $this->set_body_param(
131
- array(
132
- 'subject' => $subject,
133
- )
134
- );
135
- }
136
-
137
- /**
138
- * Set the request params, that goes to the body of the HTTP request.
139
- *
140
- * @since 1.0.0
141
- *
142
- * @param array $param Key=>value of what should be sent to a 3rd party API.
143
- *
144
- * @internal param array $params
145
- */
146
- protected function set_body_param( $param ) {
147
- $this->body = Options::array_merge_recursive( $this->body, $param );
148
- }
149
-
150
- /**
151
- * @inheritdoc
152
- */
153
- public function set_headers( $headers ) {
154
-
155
- foreach ( $headers as $header ) {
156
- $name = isset( $header[0] ) ? $header[0] : false;
157
- $value = isset( $header[1] ) ? $header[1] : false;
158
-
159
- if ( empty( $name ) || empty( $value ) ) {
160
- continue;
161
- }
162
-
163
- $this->set_header( $name, $value );
164
- }
165
- }
166
-
167
- /**
168
- * @inheritdoc
169
- */
170
- public function set_header( $name, $value ) {
171
-
172
- $process_value = function ( $value ) {
173
- // Remove HTML tags.
174
- $filtered = wp_strip_all_tags( $value, false );
175
- // Remove multi-lines/tabs.
176
- $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
177
- // Remove whitespaces.
178
- $filtered = trim( $filtered );
179
-
180
- // Remove octets.
181
- $found = false;
182
- while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
183
- $filtered = str_replace( $match[0], '', $filtered );
184
- $found = true;
185
- }
186
-
187
- if ( $found ) {
188
- // Strip out the whitespace that may now exist after removing the octets.
189
- $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
190
- }
191
-
192
- return $filtered;
193
- };
194
-
195
- $name = sanitize_text_field( $name );
196
- if ( empty( $name ) ) {
197
- return;
198
- }
199
-
200
- $value = $process_value( $value );
201
-
202
- $this->headers[ $name ] = $value;
203
- }
204
-
205
- /**
206
- * @inheritdoc
207
- */
208
- public function get_body() {
209
- return apply_filters( 'wp_mail_smtp_providers_mailer_get_body', $this->body );
210
- }
211
-
212
- /**
213
- * @inheritdoc
214
- */
215
- public function get_headers() {
216
- return apply_filters( 'wp_mail_smtp_providers_mailer_get_headers', $this->headers );
217
- }
218
-
219
- /**
220
- * @inheritdoc
221
- */
222
- public function send() {
223
-
224
- $params = Options::array_merge_recursive( $this->get_default_params(), array(
225
- 'headers' => $this->get_headers(),
226
- 'body' => $this->get_body(),
227
- ) );
228
-
229
- $response = wp_safe_remote_post( $this->url, $params );
230
-
231
- $this->process_response( $response );
232
- }
233
-
234
- /**
235
- * We might need to do something after the email was sent to the API.
236
- * In this method we preprocess the response from the API.
237
- *
238
- * @since 1.0.0
239
- *
240
- * @param array|\WP_Error $response
241
- */
242
- protected function process_response( $response ) {
243
-
244
- if ( is_wp_error( $response ) ) {
245
- // Save the error text.
246
- $errors = $response->get_error_messages();
247
- foreach ( $errors as $error ) {
248
- Debug::set( $error );
249
- }
250
-
251
- return;
252
- }
253
-
254
- if ( isset( $response['body'] ) && $this->is_json( $response['body'] ) ) {
255
- $response['body'] = \json_decode( $response['body'] );
256
- }
257
-
258
- $this->response = $response;
259
- }
260
-
261
- /**
262
- * Get the default params, required for wp_safe_remote_post().
263
- *
264
- * @since 1.0.0
265
- *
266
- * @return array
267
- */
268
- protected function get_default_params() {
269
-
270
- return apply_filters( 'wp_mail_smtp_providers_mailer_get_default_params', array(
271
- 'timeout' => 15,
272
- 'httpversion' => '1.1',
273
- 'blocking' => true,
274
- ) );
275
- }
276
-
277
- /**
278
- * @inheritdoc
279
- */
280
- public function is_email_sent() {
281
-
282
- $is_sent = false;
283
-
284
- if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
285
- $is_sent = true;
286
- } else {
287
- $error = $this->get_response_error();
288
-
289
- if ( ! empty( $error ) ) {
290
- Debug::set( $error );
291
- }
292
- }
293
-
294
- return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent );
295
- }
296
-
297
- /**
298
- * Should be overwritten when appropriate.
299
- *
300
- * @since 1.2.0
301
- *
302
- * @return string
303
- */
304
- protected function get_response_error() {
305
- return '';
306
- }
307
-
308
- /**
309
- * @inheritdoc
310
- */
311
- public function is_php_compatible() {
312
-
313
- $options = wp_mail_smtp()->get_providers()->get_options( $this->mailer );
314
-
315
- return version_compare( phpversion(), $options->get_php_version(), '>=' );
316
- }
317
-
318
- /**
319
- * Check whether the string is a JSON or not.
320
- *
321
- * @since 1.0.0
322
- *
323
- * @param string $string
324
- *
325
- * @return bool
326
- */
327
- protected function is_json( $string ) {
328
- return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( json_last_error() === JSON_ERROR_NONE ) ? true : false;
329
- }
330
-
331
- /**
332
- * This method is relevant to SMTP, Pepipost and Mail.
333
- * All other custom mailers should override it with own information.
334
- *
335
- * @since 1.2.0
336
- *
337
- * @return string
338
- */
339
- public function get_debug_info() {
340
- global $phpmailer;
341
-
342
- $smtp_text = array();
343
-
344
- // Mail mailer has nothing to return.
345
- if ( $this->options->is_mailer_smtp() ) {
346
- $smtp_text[] = '<strong>ErrorInfo:</strong> ' . make_clickable( $phpmailer->ErrorInfo );
347
- $smtp_text[] = '<strong>Host:</strong> ' . $phpmailer->Host;
348
- $smtp_text[] = '<strong>Port:</strong> ' . $phpmailer->Port;
349
- $smtp_text[] = '<strong>SMTPSecure:</strong> ' . Debug::pvar( $phpmailer->SMTPSecure );
350
- $smtp_text[] = '<strong>SMTPAutoTLS:</strong> ' . Debug::pvar( $phpmailer->SMTPAutoTLS );
351
- $smtp_text[] = '<strong>SMTPAuth:</strong> ' . Debug::pvar( $phpmailer->SMTPAuth );
352
- if ( ! empty( $phpmailer->SMTPOptions ) ) {
353
- $smtp_text[] = '<strong>SMTPOptions:</strong> <code>' . json_encode( $phpmailer->SMTPOptions ) . '</code>';
354
- }
355
- }
356
-
357
- $smtp_text[] = '<br><strong>Server:</strong>';
358
- $smtp_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
359
- if ( function_exists( 'apache_get_modules' ) ) {
360
- $modules = apache_get_modules();
361
- $smtp_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
362
- }
363
-
364
- return implode( '<br>', $smtp_text );
365
- }
366
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ use WPMailSMTP\Debug;
6
+ use WPMailSMTP\MailCatcher;
7
+ use WPMailSMTP\Options;
8
+
9
+ /**
10
+ * Class MailerAbstract.
11
+ *
12
+ * @since 1.0.0
13
+ */
14
+ abstract class MailerAbstract implements MailerInterface {
15
+
16
+ /**
17
+ * Which response code from HTTP provider is considered to be successful?
18
+ *
19
+ * @var int
20
+ */
21
+ protected $email_sent_code = 200;
22
+ /**
23
+ * @var Options
24
+ */
25
+ protected $options;
26
+ /**
27
+ * @var MailCatcher
28
+ */
29
+ protected $phpmailer;
30
+ /**
31
+ * @var string
32
+ */
33
+ protected $mailer = '';
34
+
35
+ /**
36
+ * URL to make an API request to.
37
+ *
38
+ * @var string
39
+ */
40
+ protected $url = '';
41
+ /**
42
+ * @var array
43
+ */
44
+ protected $headers = array();
45
+ /**
46
+ * @var array
47
+ */
48
+ protected $body = array();
49
+ /**
50
+ * @var mixed
51
+ */
52
+ protected $response = array();
53
+
54
+ /**
55
+ * Mailer constructor.
56
+ *
57
+ * @since 1.0.0
58
+ *
59
+ * @param MailCatcher $phpmailer
60
+ */
61
+ public function __construct( MailCatcher $phpmailer ) {
62
+
63
+ $this->options = new Options();
64
+ $this->mailer = $this->options->get( 'mail', 'mailer' );
65
+
66
+ // Only non-SMTP mailers need URL.
67
+ if ( ! $this->options->is_mailer_smtp() && empty( $this->url ) ) {
68
+ return;
69
+ }
70
+
71
+ $this->process_phpmailer( $phpmailer );
72
+ }
73
+
74
+ /**
75
+ * Re-use the MailCatcher class methods and properties.
76
+ *
77
+ * @since 1.0.0
78
+ *
79
+ * @param MailCatcher $phpmailer
80
+ */
81
+ public function process_phpmailer( $phpmailer ) {
82
+
83
+ // Make sure that we have access to MailCatcher class methods.
84
+ if (
85
+ ! $phpmailer instanceof MailCatcher &&
86
+ ! $phpmailer instanceof \PHPMailer
87
+ ) {
88
+ return;
89
+ }
90
+
91
+ $this->phpmailer = $phpmailer;
92
+
93
+ // Prevent working with those methods, as they are not needed for SMTP-like mailers.
94
+ if ( $this->options->is_mailer_smtp() ) {
95
+ return;
96
+ }
97
+
98
+ $this->set_headers( $this->phpmailer->getCustomHeaders() );
99
+ $this->set_from( $this->phpmailer->From, $this->phpmailer->FromName );
100
+ $this->set_recipients(
101
+ array(
102
+ 'to' => $this->phpmailer->getToAddresses(),
103
+ 'cc' => $this->phpmailer->getCcAddresses(),
104
+ 'bcc' => $this->phpmailer->getBccAddresses(),
105
+ )
106
+ );
107
+ $this->set_subject( $this->phpmailer->Subject );
108
+ $this->set_content(
109
+ array(
110
+ 'html' => $this->phpmailer->Body,
111
+ 'text' => $this->phpmailer->AltBody,
112
+ )
113
+ );
114
+ $this->set_return_path( $this->phpmailer->From );
115
+ $this->set_reply_to( $this->phpmailer->getReplyToAddresses() );
116
+
117
+ /*
118
+ * In some cases we will need to modify the internal structure
119
+ * of the body content, if attachments are present.
120
+ * So lets make this call the last one.
121
+ */
122
+ $this->set_attachments( $this->phpmailer->getAttachments() );
123
+ }
124
+
125
+ /**
126
+ * @inheritdoc
127
+ */
128
+ public function set_subject( $subject ) {
129
+
130
+ $this->set_body_param(
131
+ array(
132
+ 'subject' => $subject,
133
+ )
134
+ );
135
+ }
136
+
137
+ /**
138
+ * Set the request params, that goes to the body of the HTTP request.
139
+ *
140
+ * @since 1.0.0
141
+ *
142
+ * @param array $param Key=>value of what should be sent to a 3rd party API.
143
+ *
144
+ * @internal param array $params
145
+ */
146
+ protected function set_body_param( $param ) {
147
+ $this->body = Options::array_merge_recursive( $this->body, $param );
148
+ }
149
+
150
+ /**
151
+ * @inheritdoc
152
+ */
153
+ public function set_headers( $headers ) {
154
+
155
+ foreach ( $headers as $header ) {
156
+ $name = isset( $header[0] ) ? $header[0] : false;
157
+ $value = isset( $header[1] ) ? $header[1] : false;
158
+
159
+ if ( empty( $name ) || empty( $value ) ) {
160
+ continue;
161
+ }
162
+
163
+ $this->set_header( $name, $value );
164
+ }
165
+ }
166
+
167
+ /**
168
+ * @inheritdoc
169
+ */
170
+ public function set_header( $name, $value ) {
171
+
172
+ $process_value = function ( $value ) {
173
+ // Remove HTML tags.
174
+ $filtered = wp_strip_all_tags( $value, false );
175
+ // Remove multi-lines/tabs.
176
+ $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
177
+ // Remove whitespaces.
178
+ $filtered = trim( $filtered );
179
+
180
+ // Remove octets.
181
+ $found = false;
182
+ while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
183
+ $filtered = str_replace( $match[0], '', $filtered );
184
+ $found = true;
185
+ }
186
+
187
+ if ( $found ) {
188
+ // Strip out the whitespace that may now exist after removing the octets.
189
+ $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
190
+ }
191
+
192
+ return $filtered;
193
+ };
194
+
195
+ $name = sanitize_text_field( $name );
196
+ if ( empty( $name ) ) {
197
+ return;
198
+ }
199
+
200
+ $value = $process_value( $value );
201
+
202
+ $this->headers[ $name ] = $value;
203
+ }
204
+
205
+ /**
206
+ * @inheritdoc
207
+ */
208
+ public function get_body() {
209
+ return apply_filters( 'wp_mail_smtp_providers_mailer_get_body', $this->body );
210
+ }
211
+
212
+ /**
213
+ * @inheritdoc
214
+ */
215
+ public function get_headers() {
216
+ return apply_filters( 'wp_mail_smtp_providers_mailer_get_headers', $this->headers );
217
+ }
218
+
219
+ /**
220
+ * @inheritdoc
221
+ */
222
+ public function send() {
223
+
224
+ $params = Options::array_merge_recursive( $this->get_default_params(), array(
225
+ 'headers' => $this->get_headers(),
226
+ 'body' => $this->get_body(),
227
+ ) );
228
+
229
+ $response = wp_safe_remote_post( $this->url, $params );
230
+
231
+ $this->process_response( $response );
232
+ }
233
+
234
+ /**
235
+ * We might need to do something after the email was sent to the API.
236
+ * In this method we preprocess the response from the API.
237
+ *
238
+ * @since 1.0.0
239
+ *
240
+ * @param array|\WP_Error $response
241
+ */
242
+ protected function process_response( $response ) {
243
+
244
+ if ( is_wp_error( $response ) ) {
245
+ // Save the error text.
246
+ $errors = $response->get_error_messages();
247
+ foreach ( $errors as $error ) {
248
+ Debug::set( $error );
249
+ }
250
+
251
+ return;
252
+ }
253
+
254
+ if ( isset( $response['body'] ) && $this->is_json( $response['body'] ) ) {
255
+ $response['body'] = \json_decode( $response['body'] );
256
+ }
257
+
258
+ $this->response = $response;
259
+ }
260
+
261
+ /**
262
+ * Get the default params, required for wp_safe_remote_post().
263
+ *
264
+ * @since 1.0.0
265
+ *
266
+ * @return array
267
+ */
268
+ protected function get_default_params() {
269
+
270
+ return apply_filters( 'wp_mail_smtp_providers_mailer_get_default_params', array(
271
+ 'timeout' => 15,
272
+ 'httpversion' => '1.1',
273
+ 'blocking' => true,
274
+ ) );
275
+ }
276
+
277
+ /**
278
+ * @inheritdoc
279
+ */
280
+ public function is_email_sent() {
281
+
282
+ $is_sent = false;
283
+
284
+ if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
285
+ $is_sent = true;
286
+ } else {
287
+ $error = $this->get_response_error();
288
+
289
+ if ( ! empty( $error ) ) {
290
+ Debug::set( $error );
291
+ }
292
+ }
293
+
294
+ return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent );
295
+ }
296
+
297
+ /**
298
+ * Should be overwritten when appropriate.
299
+ *
300
+ * @since 1.2.0
301
+ *
302
+ * @return string
303
+ */
304
+ protected function get_response_error() {
305
+ return '';
306
+ }
307
+
308
+ /**
309
+ * @inheritdoc
310
+ */
311
+ public function is_php_compatible() {
312
+
313
+ $options = wp_mail_smtp()->get_providers()->get_options( $this->mailer );
314
+
315
+ return version_compare( phpversion(), $options->get_php_version(), '>=' );
316
+ }
317
+
318
+ /**
319
+ * Check whether the string is a JSON or not.
320
+ *
321
+ * @since 1.0.0
322
+ *
323
+ * @param string $string
324
+ *
325
+ * @return bool
326
+ */
327
+ protected function is_json( $string ) {
328
+ return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( json_last_error() === JSON_ERROR_NONE ) ? true : false;
329
+ }
330
+
331
+ /**
332
+ * This method is relevant to SMTP, Pepipost and Mail.
333
+ * All other custom mailers should override it with own information.
334
+ *
335
+ * @since 1.2.0
336
+ *
337
+ * @return string
338
+ */
339
+ public function get_debug_info() {
340
+ global $phpmailer;
341
+
342
+ $smtp_text = array();
343
+
344
+ // Mail mailer has nothing to return.
345
+ if ( $this->options->is_mailer_smtp() ) {
346
+ $smtp_text[] = '<strong>ErrorInfo:</strong> ' . make_clickable( wp_strip_all_tags( $phpmailer->ErrorInfo ) );
347
+ $smtp_text[] = '<strong>Host:</strong> ' . $phpmailer->Host;
348
+ $smtp_text[] = '<strong>Port:</strong> ' . $phpmailer->Port;
349
+ $smtp_text[] = '<strong>SMTPSecure:</strong> ' . Debug::pvar( $phpmailer->SMTPSecure );
350
+ $smtp_text[] = '<strong>SMTPAutoTLS:</strong> ' . Debug::pvar( $phpmailer->SMTPAutoTLS );
351
+ $smtp_text[] = '<strong>SMTPAuth:</strong> ' . Debug::pvar( $phpmailer->SMTPAuth );
352
+ if ( ! empty( $phpmailer->SMTPOptions ) ) {
353
+ $smtp_text[] = '<strong>SMTPOptions:</strong> <code>' . json_encode( $phpmailer->SMTPOptions ) . '</code>';
354
+ }
355
+ }
356
+
357
+ $smtp_text[] = '<br><strong>Server:</strong>';
358
+ $smtp_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
359
+ if ( function_exists( 'apache_get_modules' ) ) {
360
+ $modules = apache_get_modules();
361
+ $smtp_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
362
+ }
363
+
364
+ return implode( '<br>', $smtp_text );
365
+ }
366
+ }
src/Providers/MailerInterface.php CHANGED
@@ -1,74 +1,74 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- /**
6
- * Interface MailerInterface.
7
- *
8
- * @since 1.0.0
9
- */
10
- interface MailerInterface {
11
-
12
- /**
13
- * Send the email.
14
- *
15
- * @since 1.0.0
16
- */
17
- public function send();
18
-
19
- /**
20
- * Whether the email is sent or not.
21
- * We basically check the response code from a request to provider.
22
- * Might not be 100% correct, not guarantees that email is delivered.
23
- *
24
- * @since 1.0.0
25
- *
26
- * @return bool
27
- */
28
- public function is_email_sent();
29
-
30
- /**
31
- * Whether the mailer supports the current PHP version or not.
32
- *
33
- * @since 1.0.0
34
- *
35
- * @return bool
36
- */
37
- public function is_php_compatible();
38
-
39
- /**
40
- * Get the email body.
41
- *
42
- * @since 1.0.0
43
- *
44
- * @return string|array
45
- */
46
- public function get_body();
47
-
48
- /**
49
- * Get the email headers.
50
- *
51
- * @since 1.0.0
52
- *
53
- * @return array
54
- */
55
- public function get_headers();
56
-
57
- /**
58
- * Get an array of all debug information relevant to the mailer.
59
- *
60
- * @since 1.2.0
61
- *
62
- * @return array
63
- */
64
- public function get_debug_info();
65
-
66
- /**
67
- * Re-use the MailCatcher class methods and properties.
68
- *
69
- * @since 1.2.0
70
- *
71
- * @param \WPMailSMTP\MailCatcher $phpmailer
72
- */
73
- public function process_phpmailer( $phpmailer );
74
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ /**
6
+ * Interface MailerInterface.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ interface MailerInterface {
11
+
12
+ /**
13
+ * Send the email.
14
+ *
15
+ * @since 1.0.0
16
+ */
17
+ public function send();
18
+
19
+ /**
20
+ * Whether the email is sent or not.
21
+ * We basically check the response code from a request to provider.
22
+ * Might not be 100% correct, not guarantees that email is delivered.
23
+ *
24
+ * @since 1.0.0
25
+ *
26
+ * @return bool
27
+ */
28
+ public function is_email_sent();
29
+
30
+ /**
31
+ * Whether the mailer supports the current PHP version or not.
32
+ *
33
+ * @since 1.0.0
34
+ *
35
+ * @return bool
36
+ */
37
+ public function is_php_compatible();
38
+
39
+ /**
40
+ * Get the email body.
41
+ *
42
+ * @since 1.0.0
43
+ *
44
+ * @return string|array
45
+ */
46
+ public function get_body();
47
+
48
+ /**
49
+ * Get the email headers.
50
+ *
51
+ * @since 1.0.0
52
+ *
53
+ * @return array
54
+ */
55
+ public function get_headers();
56
+
57
+ /**
58
+ * Get an array of all debug information relevant to the mailer.
59
+ *
60
+ * @since 1.2.0
61
+ *
62
+ * @return array
63
+ */
64
+ public function get_debug_info();
65
+
66
+ /**
67
+ * Re-use the MailCatcher class methods and properties.
68
+ *
69
+ * @since 1.2.0
70
+ *
71
+ * @param \WPMailSMTP\MailCatcher $phpmailer
72
+ */
73
+ public function process_phpmailer( $phpmailer );
74
+ }
src/Providers/Mailgun/Mailer.php CHANGED
@@ -1,344 +1,344 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Mailgun;
4
-
5
- use WPMailSMTP\Providers\MailerAbstract;
6
-
7
- /**
8
- * Class Mailer.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Mailer extends MailerAbstract {
13
-
14
- /**
15
- * Which response code from HTTP provider is considered to be successful?
16
- *
17
- * @var int
18
- */
19
- protected $email_sent_code = 200;
20
-
21
- /**
22
- * URL to make an API request to.
23
- *
24
- * @var string
25
- */
26
- protected $url = 'https://api.mailgun.net/v3/';
27
-
28
- /**
29
- * @inheritdoc
30
- */
31
- public function __construct( $phpmailer ) {
32
-
33
- // We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
34
- parent::__construct( $phpmailer );
35
-
36
- /*
37
- * Append the url with a domain,
38
- * to avoid passing the domain name as a query parameter with all requests.
39
- */
40
- $this->url .= sanitize_text_field( $this->options->get( $this->mailer, 'domain' ) . '/messages' );
41
-
42
- $this->set_header( 'Authorization', 'Basic ' . base64_encode( 'api:' . $this->options->get( $this->mailer, 'api_key' ) ) );
43
- }
44
-
45
- /**
46
- * @inheritdoc
47
- */
48
- public function set_from( $email, $name = '' ) {
49
-
50
- if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
51
- return;
52
- }
53
-
54
- if ( ! empty( $name ) ) {
55
- $this->set_body_param(
56
- array(
57
- 'from' => $name . ' <' . $email . '>',
58
- )
59
- );
60
- } else {
61
- $this->set_body_param(
62
- array(
63
- 'from' => $email,
64
- )
65
- );
66
- }
67
- }
68
-
69
- /**
70
- * @inheritdoc
71
- */
72
- public function set_recipients( $recipients ) {
73
-
74
- if ( empty( $recipients ) ) {
75
- return;
76
- }
77
-
78
- $default = array( 'to', 'cc', 'bcc' );
79
-
80
- foreach ( $recipients as $kind => $emails ) {
81
- if (
82
- ! in_array( $kind, $default, true ) ||
83
- empty( $emails ) ||
84
- ! is_array( $emails )
85
- ) {
86
- continue;
87
- }
88
-
89
- $data = array();
90
-
91
- foreach ( $emails as $email ) {
92
- $addr = isset( $email[0] ) ? $email[0] : false;
93
- $name = isset( $email[1] ) ? $email[1] : false;
94
-
95
- if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
96
- continue;
97
- }
98
-
99
- if ( ! empty( $name ) ) {
100
- $data[] = $name . ' <' . $addr . '>';
101
- } else {
102
- $data[] = $addr;
103
- }
104
- }
105
-
106
- if ( ! empty( $data ) ) {
107
- $this->set_body_param(
108
- array(
109
- $kind => implode( ', ', $data ),
110
- )
111
- );
112
- }
113
- }
114
- }
115
-
116
- /**
117
- * @inheritdoc
118
- */
119
- public function set_content( $content ) {
120
-
121
- if ( is_array( $content ) ) {
122
-
123
- $default = array( 'text', 'html' );
124
-
125
- foreach ( $content as $type => $mail ) {
126
- if (
127
- ! in_array( $type, $default, true ) ||
128
- empty( $mail )
129
- ) {
130
- continue;
131
- }
132
-
133
- $this->set_body_param(
134
- array(
135
- $type => $mail,
136
- )
137
- );
138
- }
139
- } else {
140
- $type = 'text';
141
-
142
- if ( $this->phpmailer->ContentType === 'text/html' ) {
143
- $type = 'html';
144
- }
145
-
146
- if ( ! empty( $content ) ) {
147
- $this->set_body_param(
148
- array(
149
- $type => $content,
150
- )
151
- );
152
- }
153
- }
154
- }
155
-
156
- /**
157
- * It's the last one, so we can modify the whole body.
158
- *
159
- * @since 1.0.0
160
- *
161
- * @param array $attachments
162
- */
163
- public function set_attachments( $attachments ) {
164
-
165
- if ( empty( $attachments ) ) {
166
- return;
167
- }
168
-
169
- $payload = '';
170
- $data = array();
171
-
172
- foreach ( $attachments as $attachment ) {
173
- $file = false;
174
-
175
- /*
176
- * We are not using WP_Filesystem API as we can't reliably work with it.
177
- * It is not always available, same as credentials for FTP.
178
- */
179
- try {
180
- if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
181
- $file = file_get_contents( $attachment[0] );
182
- }
183
- } catch ( \Exception $e ) {
184
- $file = false;
185
- }
186
-
187
- if ( $file === false ) {
188
- continue;
189
- }
190
-
191
- $data[] = array(
192
- 'content' => $file,
193
- 'name' => $attachment[1],
194
- );
195
- }
196
-
197
- if ( ! empty( $data ) ) {
198
-
199
- // First, generate a boundary for the multipart message.
200
- $boundary = base_convert( uniqid( 'boundary', true ), 10, 36 );
201
-
202
- // Iterate through pre-built params and build a payload.
203
- foreach ( $this->body as $key => $value ) {
204
- if ( is_array( $value ) ) {
205
- foreach ( $value as $child_key => $child_value ) {
206
- $payload .= '--' . $boundary;
207
- $payload .= "\r\n";
208
- $payload .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
209
- $payload .= $child_value;
210
- $payload .= "\r\n";
211
- }
212
- } else {
213
- $payload .= '--' . $boundary;
214
- $payload .= "\r\n";
215
- $payload .= 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n";
216
- $payload .= $value;
217
- $payload .= "\r\n";
218
- }
219
- }
220
-
221
- // Now iterate through our attachments, and add them too.
222
- foreach ( $data as $key => $attachment ) {
223
- $payload .= '--' . $boundary;
224
- $payload .= "\r\n";
225
- $payload .= 'Content-Disposition: form-data; name="attachment[' . $key . ']"; filename="' . $attachment['name'] . '"' . "\r\n\r\n";
226
- $payload .= $attachment['content'];
227
- $payload .= "\r\n";
228
- }
229
-
230
- $payload .= '--' . $boundary . '--';
231
-
232
- // Redefine the body the "dirty way".
233
- $this->body = $payload;
234
-
235
- $this->set_header( 'Content-Type', 'multipart/form-data; boundary=' . $boundary );
236
- }
237
- }
238
-
239
- /**
240
- * @inheritdoc
241
- */
242
- public function set_reply_to( $reply_to ) {
243
-
244
- if ( empty( $reply_to ) ) {
245
- return;
246
- }
247
-
248
- $data = array();
249
-
250
- foreach ( $reply_to as $key => $emails ) {
251
- if (
252
- empty( $emails ) ||
253
- ! is_array( $emails )
254
- ) {
255
- continue;
256
- }
257
-
258
- $addr = isset( $emails[0] ) ? $emails[0] : false;
259
- $name = isset( $emails[1] ) ? $emails[1] : false;
260
-
261
- if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
262
- continue;
263
- }
264
-
265
- if ( ! empty( $name ) ) {
266
- $data[] = $name . ' <' . $addr . '>';
267
- } else {
268
- $data[] = $addr;
269
- }
270
- }
271
-
272
- if ( ! empty( $data ) ) {
273
- $this->set_body_param(
274
- array(
275
- 'h:Reply-To' => implode( ',', $data ),
276
- )
277
- );
278
- }
279
- }
280
-
281
- /**
282
- * @inheritdoc
283
- */
284
- public function set_return_path( $email ) {
285
-
286
- if (
287
- $this->options->get( 'mail', 'return_path' ) !== true ||
288
- ! filter_var( $email, FILTER_VALIDATE_EMAIL )
289
- ) {
290
- return;
291
- }
292
-
293
- $this->set_body_param(
294
- array(
295
- 'sender' => $email,
296
- )
297
- );
298
- }
299
-
300
- /**
301
- * Get a Mailgun-specific response with a helpful error.
302
- *
303
- * @since 1.2.0
304
- *
305
- * @return string
306
- */
307
- protected function get_response_error() {
308
-
309
- $body = (array) wp_remote_retrieve_body( $this->response );
310
-
311
- $error_text = array();
312
-
313
- if ( ! empty( $body['message'] ) ) {
314
- if ( is_string( $body['message'] ) ) {
315
- $error_text[] = $body['message'];
316
- } else {
317
- $error_text[] = \json_encode( $body['message'] );
318
- }
319
- } elseif ( ! empty( $body[0] ) ) {
320
- if ( is_string( $body[0] ) ) {
321
- $error_text[] = $body[0];
322
- } else {
323
- $error_text[] = \json_encode( $body[0] );
324
- }
325
- }
326
-
327
- return implode( '<br>', $error_text );
328
- }
329
-
330
- /**
331
- * @inheritdoc
332
- */
333
- public function get_debug_info() {
334
-
335
- $mg_text = array();
336
-
337
- $options = new \WPMailSMTP\Options();
338
- $mailgun = $options->get_group( 'mailgun' );
339
-
340
- $mg_text[] = '<strong>Api Key / Domain:</strong> ' . ( ! empty( $mailgun['api_key'] ) && ! empty( $mailgun['domain'] ) ? 'Yes' : 'No' );
341
-
342
- return implode( '<br>', $mg_text );
343
- }
344
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Mailgun;
4
+
5
+ use WPMailSMTP\Providers\MailerAbstract;
6
+
7
+ /**
8
+ * Class Mailer.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Mailer extends MailerAbstract {
13
+
14
+ /**
15
+ * Which response code from HTTP provider is considered to be successful?
16
+ *
17
+ * @var int
18
+ */
19
+ protected $email_sent_code = 200;
20
+
21
+ /**
22
+ * URL to make an API request to.
23
+ *
24
+ * @var string
25
+ */
26
+ protected $url = 'https://api.mailgun.net/v3/';
27
+
28
+ /**
29
+ * @inheritdoc
30
+ */
31
+ public function __construct( $phpmailer ) {
32
+
33
+ // We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
34
+ parent::__construct( $phpmailer );
35
+
36
+ /*
37
+ * Append the url with a domain,
38
+ * to avoid passing the domain name as a query parameter with all requests.
39
+ */
40
+ $this->url .= sanitize_text_field( $this->options->get( $this->mailer, 'domain' ) . '/messages' );
41
+
42
+ $this->set_header( 'Authorization', 'Basic ' . base64_encode( 'api:' . $this->options->get( $this->mailer, 'api_key' ) ) );
43
+ }
44
+
45
+ /**
46
+ * @inheritdoc
47
+ */
48
+ public function set_from( $email, $name = '' ) {
49
+
50
+ if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
51
+ return;
52
+ }
53
+
54
+ if ( ! empty( $name ) ) {
55
+ $this->set_body_param(
56
+ array(
57
+ 'from' => $name . ' <' . $email . '>',
58
+ )
59
+ );
60
+ } else {
61
+ $this->set_body_param(
62
+ array(
63
+ 'from' => $email,
64
+ )
65
+ );
66
+ }
67
+ }
68
+
69
+ /**
70
+ * @inheritdoc
71
+ */
72
+ public function set_recipients( $recipients ) {
73
+
74
+ if ( empty( $recipients ) ) {
75
+ return;
76
+ }
77
+
78
+ $default = array( 'to', 'cc', 'bcc' );
79
+
80
+ foreach ( $recipients as $kind => $emails ) {
81
+ if (
82
+ ! in_array( $kind, $default, true ) ||
83
+ empty( $emails ) ||
84
+ ! is_array( $emails )
85
+ ) {
86
+ continue;
87
+ }
88
+
89
+ $data = array();
90
+
91
+ foreach ( $emails as $email ) {
92
+ $addr = isset( $email[0] ) ? $email[0] : false;
93
+ $name = isset( $email[1] ) ? $email[1] : false;
94
+
95
+ if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
96
+ continue;
97
+ }
98
+
99
+ if ( ! empty( $name ) ) {
100
+ $data[] = $name . ' <' . $addr . '>';
101
+ } else {
102
+ $data[] = $addr;
103
+ }
104
+ }
105
+
106
+ if ( ! empty( $data ) ) {
107
+ $this->set_body_param(
108
+ array(
109
+ $kind => implode( ', ', $data ),
110
+ )
111
+ );
112
+ }
113
+ }
114
+ }
115
+
116
+ /**
117
+ * @inheritdoc
118
+ */
119
+ public function set_content( $content ) {
120
+
121
+ if ( is_array( $content ) ) {
122
+
123
+ $default = array( 'text', 'html' );
124
+
125
+ foreach ( $content as $type => $mail ) {
126
+ if (
127
+ ! in_array( $type, $default, true ) ||
128
+ empty( $mail )
129
+ ) {
130
+ continue;
131
+ }
132
+
133
+ $this->set_body_param(
134
+ array(
135
+ $type => $mail,
136
+ )
137
+ );
138
+ }
139
+ } else {
140
+ $type = 'text';
141
+
142
+ if ( $this->phpmailer->ContentType === 'text/html' ) {
143
+ $type = 'html';
144
+ }
145
+
146
+ if ( ! empty( $content ) ) {
147
+ $this->set_body_param(
148
+ array(
149
+ $type => $content,
150
+ )
151
+ );
152
+ }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * It's the last one, so we can modify the whole body.
158
+ *
159
+ * @since 1.0.0
160
+ *
161
+ * @param array $attachments
162
+ */
163
+ public function set_attachments( $attachments ) {
164
+
165
+ if ( empty( $attachments ) ) {
166
+ return;
167
+ }
168
+
169
+ $payload = '';
170
+ $data = array();
171
+
172
+ foreach ( $attachments as $attachment ) {
173
+ $file = false;
174
+
175
+ /*
176
+ * We are not using WP_Filesystem API as we can't reliably work with it.
177
+ * It is not always available, same as credentials for FTP.
178
+ */
179
+ try {
180
+ if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
181
+ $file = file_get_contents( $attachment[0] );
182
+ }
183
+ } catch ( \Exception $e ) {
184
+ $file = false;
185
+ }
186
+
187
+ if ( $file === false ) {
188
+ continue;
189
+ }
190
+
191
+ $data[] = array(
192
+ 'content' => $file,
193
+ 'name' => $attachment[1],
194
+ );
195
+ }
196
+
197
+ if ( ! empty( $data ) ) {
198
+
199
+ // First, generate a boundary for the multipart message.
200
+ $boundary = base_convert( uniqid( 'boundary', true ), 10, 36 );
201
+
202
+ // Iterate through pre-built params and build a payload.
203
+ foreach ( $this->body as $key => $value ) {
204
+ if ( is_array( $value ) ) {
205
+ foreach ( $value as $child_key => $child_value ) {
206
+ $payload .= '--' . $boundary;
207
+ $payload .= "\r\n";
208
+ $payload .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
209
+ $payload .= $child_value;
210
+ $payload .= "\r\n";
211
+ }
212
+ } else {
213
+ $payload .= '--' . $boundary;
214
+ $payload .= "\r\n";
215
+ $payload .= 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n";
216
+ $payload .= $value;
217
+ $payload .= "\r\n";
218
+ }
219
+ }
220
+
221
+ // Now iterate through our attachments, and add them too.
222
+ foreach ( $data as $key => $attachment ) {
223
+ $payload .= '--' . $boundary;
224
+ $payload .= "\r\n";
225
+ $payload .= 'Content-Disposition: form-data; name="attachment[' . $key . ']"; filename="' . $attachment['name'] . '"' . "\r\n\r\n";
226
+ $payload .= $attachment['content'];
227
+ $payload .= "\r\n";
228
+ }
229
+
230
+ $payload .= '--' . $boundary . '--';
231
+
232
+ // Redefine the body the "dirty way".
233
+ $this->body = $payload;
234
+
235
+ $this->set_header( 'Content-Type', 'multipart/form-data; boundary=' . $boundary );
236
+ }
237
+ }
238
+
239
+ /**
240
+ * @inheritdoc
241
+ */
242
+ public function set_reply_to( $reply_to ) {
243
+
244
+ if ( empty( $reply_to ) ) {
245
+ return;
246
+ }
247
+
248
+ $data = array();
249
+
250
+ foreach ( $reply_to as $key => $emails ) {
251
+ if (
252
+ empty( $emails ) ||
253
+ ! is_array( $emails )
254
+ ) {
255
+ continue;
256
+ }
257
+
258
+ $addr = isset( $emails[0] ) ? $emails[0] : false;
259
+ $name = isset( $emails[1] ) ? $emails[1] : false;
260
+
261
+ if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
262
+ continue;
263
+ }
264
+
265
+ if ( ! empty( $name ) ) {
266
+ $data[] = $name . ' <' . $addr . '>';
267
+ } else {
268
+ $data[] = $addr;
269
+ }
270
+ }
271
+
272
+ if ( ! empty( $data ) ) {
273
+ $this->set_body_param(
274
+ array(
275
+ 'h:Reply-To' => implode( ',', $data ),
276
+ )
277
+ );
278
+ }
279
+ }
280
+
281
+ /**
282
+ * @inheritdoc
283
+ */
284
+ public function set_return_path( $email ) {
285
+
286
+ if (
287
+ $this->options->get( 'mail', 'return_path' ) !== true ||
288
+ ! filter_var( $email, FILTER_VALIDATE_EMAIL )
289
+ ) {
290
+ return;
291
+ }
292
+
293
+ $this->set_body_param(
294
+ array(
295
+ 'sender' => $email,
296
+ )
297
+ );
298
+ }
299
+
300
+ /**
301
+ * Get a Mailgun-specific response with a helpful error.
302
+ *
303
+ * @since 1.2.0
304
+ *
305
+ * @return string
306
+ */
307
+ protected function get_response_error() {
308
+
309
+ $body = (array) wp_remote_retrieve_body( $this->response );
310
+
311
+ $error_text = array();
312
+
313
+ if ( ! empty( $body['message'] ) ) {
314
+ if ( is_string( $body['message'] ) ) {
315
+ $error_text[] = $body['message'];
316
+ } else {
317
+ $error_text[] = \json_encode( $body['message'] );
318
+ }
319
+ } elseif ( ! empty( $body[0] ) ) {
320
+ if ( is_string( $body[0] ) ) {
321
+ $error_text[] = $body[0];
322
+ } else {
323
+ $error_text[] = \json_encode( $body[0] );
324
+ }
325
+ }
326
+
327
+ return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
328
+ }
329
+
330
+ /**
331
+ * @inheritdoc
332
+ */
333
+ public function get_debug_info() {
334
+
335
+ $mg_text = array();
336
+
337
+ $options = new \WPMailSMTP\Options();
338
+ $mailgun = $options->get_group( 'mailgun' );
339
+
340
+ $mg_text[] = '<strong>Api Key / Domain:</strong> ' . ( ! empty( $mailgun['api_key'] ) && ! empty( $mailgun['domain'] ) ? 'Yes' : 'No' );
341
+
342
+ return implode( '<br>', $mg_text );
343
+ }
344
+ }
src/Providers/Mailgun/Options.php CHANGED
@@ -1,106 +1,106 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Mailgun;
4
-
5
- use WPMailSMTP\Providers\OptionsAbstract;
6
-
7
- /**
8
- * Class Option.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Options extends OptionsAbstract {
13
-
14
- /**
15
- * Mailgun constructor.
16
- *
17
- * @since 1.0.0
18
- */
19
- public function __construct() {
20
-
21
- parent::__construct(
22
- array(
23
- 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/mailgun.png',
24
- 'slug' => 'mailgun',
25
- 'title' => esc_html__( 'Mailgun', 'wp-mail-smtp' ),
26
- 'description' => sprintf(
27
- wp_kses(
28
- /* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
29
- __( '%1$sMailgun%2$s is one of the leading transactional email services trusted by over 10,000 website and application developers. They provide users 10,000 free emails per month.<br><br>Read our %3$sMailgun documentation%4$s to learn how to configure Mailgun and improve your email deliverability.', 'wp-mail-smtp' ),
30
- array(
31
- 'br' => array(),
32
- 'a' => array(
33
- 'href' => array(),
34
- 'rel' => array(),
35
- 'target' => array(),
36
- ),
37
- )
38
- ),
39
- '<a href="https://www.mailgun.com" target="_blank" rel="noopener noreferrer">',
40
- '</a>',
41
- '<a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" target="_blank" rel="noopener noreferrer">',
42
- '</a>'
43
- ),
44
- )
45
- );
46
- }
47
-
48
- /**
49
- * @inheritdoc
50
- */
51
- public function display_options() {
52
- ?>
53
-
54
- <!-- API Key -->
55
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
56
- <div class="wp-mail-smtp-setting-label">
57
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'Private API Key', 'wp-mail-smtp' ); ?></label>
58
- </div>
59
- <div class="wp-mail-smtp-setting-field">
60
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
61
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
62
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
63
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
64
- />
65
- <p class="desc">
66
- <?php
67
- printf(
68
- /* translators: %s - API key link. */
69
- esc_html__( 'Follow this link to get an API Key from Mailgun: %s.', 'wp-mail-smtp' ),
70
- '<a href="https://app.mailgun.com/app/account/security" target="_blank" rel="noopener noreferrer">' .
71
- esc_html__( 'Get a Private API Key', 'wp-mail-smtp' ) .
72
- '</a>'
73
- );
74
- ?>
75
- </p>
76
- </div>
77
- </div>
78
-
79
- <!-- Domain -->
80
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-domain" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
81
- <div class="wp-mail-smtp-setting-label">
82
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain"><?php esc_html_e( 'Domain Name', 'wp-mail-smtp' ); ?></label>
83
- </div>
84
- <div class="wp-mail-smtp-setting-field">
85
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][domain]" type="text"
86
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'domain' ) ); ?>"
87
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'domain' ) ? 'disabled' : ''; ?>
88
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain" spellcheck="false"
89
- />
90
- <p class="desc">
91
- <?php
92
- printf(
93
- /* translators: %s - Domain Name link. */
94
- esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
95
- '<a href="https://app.mailgun.com/app/domains" target="_blank" rel="noopener noreferrer">' .
96
- esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
97
- '</a>'
98
- );
99
- ?>
100
- </p>
101
- </div>
102
- </div>
103
-
104
- <?php
105
- }
106
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Mailgun;
4
+
5
+ use WPMailSMTP\Providers\OptionsAbstract;
6
+
7
+ /**
8
+ * Class Option.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Options extends OptionsAbstract {
13
+
14
+ /**
15
+ * Mailgun constructor.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ public function __construct() {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/mailgun.png',
24
+ 'slug' => 'mailgun',
25
+ 'title' => esc_html__( 'Mailgun', 'wp-mail-smtp' ),
26
+ 'description' => sprintf(
27
+ wp_kses(
28
+ /* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
29
+ __( '%1$sMailgun%2$s is one of the leading transactional email services trusted by over 10,000 website and application developers. They provide users 10,000 free emails per month.<br><br>Read our %3$sMailgun documentation%4$s to learn how to configure Mailgun and improve your email deliverability.', 'wp-mail-smtp' ),
30
+ array(
31
+ 'br' => array(),
32
+ 'a' => array(
33
+ 'href' => array(),
34
+ 'rel' => array(),
35
+ 'target' => array(),
36
+ ),
37
+ )
38
+ ),
39
+ '<a href="https://www.mailgun.com" target="_blank" rel="noopener noreferrer">',
40
+ '</a>',
41
+ '<a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" target="_blank" rel="noopener noreferrer">',
42
+ '</a>'
43
+ ),
44
+ )
45
+ );
46
+ }
47
+
48
+ /**
49
+ * @inheritdoc
50
+ */
51
+ public function display_options() {
52
+ ?>
53
+
54
+ <!-- API Key -->
55
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
56
+ <div class="wp-mail-smtp-setting-label">
57
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'Private API Key', 'wp-mail-smtp' ); ?></label>
58
+ </div>
59
+ <div class="wp-mail-smtp-setting-field">
60
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
61
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
62
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
63
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
64
+ />
65
+ <p class="desc">
66
+ <?php
67
+ printf(
68
+ /* translators: %s - API key link. */
69
+ esc_html__( 'Follow this link to get an API Key from Mailgun: %s.', 'wp-mail-smtp' ),
70
+ '<a href="https://app.mailgun.com/app/account/security" target="_blank" rel="noopener noreferrer">' .
71
+ esc_html__( 'Get a Private API Key', 'wp-mail-smtp' ) .
72
+ '</a>'
73
+ );
74
+ ?>
75
+ </p>
76
+ </div>
77
+ </div>
78
+
79
+ <!-- Domain -->
80
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-domain" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
81
+ <div class="wp-mail-smtp-setting-label">
82
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain"><?php esc_html_e( 'Domain Name', 'wp-mail-smtp' ); ?></label>
83
+ </div>
84
+ <div class="wp-mail-smtp-setting-field">
85
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][domain]" type="text"
86
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'domain' ) ); ?>"
87
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'domain' ) ? 'disabled' : ''; ?>
88
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain" spellcheck="false"
89
+ />
90
+ <p class="desc">
91
+ <?php
92
+ printf(
93
+ /* translators: %s - Domain Name link. */
94
+ esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
95
+ '<a href="https://app.mailgun.com/app/domains" target="_blank" rel="noopener noreferrer">' .
96
+ esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
97
+ '</a>'
98
+ );
99
+ ?>
100
+ </p>
101
+ </div>
102
+ </div>
103
+
104
+ <?php
105
+ }
106
+ }
src/Providers/OptionsAbstract.php CHANGED
@@ -1,312 +1,312 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- use WPMailSMTP\Options;
6
-
7
- /**
8
- * Abstract Class ProviderAbstract to contain common providers functionality.
9
- *
10
- * @since 1.0.0
11
- */
12
- abstract class OptionsAbstract implements OptionsInterface {
13
-
14
- /**
15
- * @var string
16
- */
17
- private $logo_url = '';
18
- /**
19
- * @var string
20
- */
21
- private $slug = '';
22
- /**
23
- * @var string
24
- */
25
- private $title = '';
26
- /**
27
- * @var string
28
- */
29
- private $description = '';
30
- /**
31
- * @var string
32
- */
33
- private $php = WPMS_PHP_VER;
34
- /**
35
- * @var Options
36
- */
37
- protected $options;
38
-
39
- /**
40
- * ProviderAbstract constructor.
41
- *
42
- * @since 1.0.0
43
- *
44
- * @param array $params
45
- */
46
- public function __construct( $params ) {
47
-
48
- if (
49
- empty( $params['slug'] ) ||
50
- empty( $params['title'] )
51
- ) {
52
- return;
53
- }
54
-
55
- $this->slug = sanitize_key( $params['slug'] );
56
- $this->title = sanitize_text_field( $params['title'] );
57
-
58
- if ( ! empty( $params['description'] ) ) {
59
- $this->description = wp_kses( $params['description'],
60
- array(
61
- 'br' => array(),
62
- 'a' => array(
63
- 'href' => array(),
64
- 'rel' => array(),
65
- 'target' => array(),
66
- ),
67
- )
68
- );
69
- }
70
-
71
- if ( ! empty( $params['php'] ) ) {
72
- $this->php = sanitize_text_field( $params['php'] );
73
- }
74
-
75
- if ( ! empty( $params['logo_url'] ) ) {
76
- $this->logo_url = esc_url_raw( $params['logo_url'] );
77
- }
78
-
79
- $this->options = new Options();
80
- }
81
-
82
- /**
83
- * @inheritdoc
84
- */
85
- public function get_logo_url() {
86
- return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
87
- }
88
-
89
- /**
90
- * @inheritdoc
91
- */
92
- public function get_slug() {
93
- return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
94
- }
95
-
96
- /**
97
- * @inheritdoc
98
- */
99
- public function get_title() {
100
- return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
101
- }
102
-
103
- /**
104
- * @inheritdoc
105
- */
106
- public function get_description() {
107
- return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
108
- }
109
-
110
- /**
111
- * @inheritdoc
112
- */
113
- public function get_php_version() {
114
- return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
115
- }
116
-
117
- /**
118
- * @inheritdoc
119
- */
120
- public function display_options() {
121
- ?>
122
-
123
- <!-- SMTP Host -->
124
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
125
- <div class="wp-mail-smtp-setting-label">
126
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
127
- </div>
128
- <div class="wp-mail-smtp-setting-field">
129
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
130
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'host' ) ); ?>"
131
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
132
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
133
- />
134
- </div>
135
- </div>
136
-
137
- <!-- SMTP Port -->
138
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
139
- <div class="wp-mail-smtp-setting-label">
140
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
141
- </div>
142
- <div class="wp-mail-smtp-setting-field">
143
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
144
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'port' ) ); ?>"
145
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
146
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
147
- />
148
- </div>
149
- </div>
150
-
151
- <!-- SMTP Encryption -->
152
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
153
- <div class="wp-mail-smtp-setting-label">
154
- <label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
155
- </div>
156
- <div class="wp-mail-smtp-setting-field">
157
-
158
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
159
- <input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
160
- name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
161
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
162
- <?php checked( 'none', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
163
- />
164
- <?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
165
- </label>
166
-
167
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
168
- <input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
169
- name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
170
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
171
- <?php checked( 'ssl', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
172
- />
173
- <?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
174
- </label>
175
-
176
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
177
- <input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
178
- name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
179
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
180
- <?php checked( 'tls', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
181
- />
182
- <?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
183
- </label>
184
-
185
- <p class="desc">
186
- <?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
187
- </p>
188
- </div>
189
- </div>
190
-
191
- <!-- PHPMailer SMTPAutoTLS -->
192
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
193
- <div class="wp-mail-smtp-setting-label">
194
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
195
- </div>
196
- <div class="wp-mail-smtp-setting-field">
197
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls">
198
- <input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"
199
- name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][autotls]" value="yes"
200
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'autotls' ) ? 'disabled' : ''; ?>
201
- <?php checked( true, $this->options->get( $this->get_slug(), 'autotls' ) ); ?>
202
- />
203
- <span class="wp-mail-smtp-setting-toggle-switch"></span>
204
- <span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
205
- <span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
206
- </label>
207
- <p class="desc">
208
- <?php esc_html_e( 'By default TLS encryption is automatically used if the server supports it, which is recommended. In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
209
- </p>
210
- </div>
211
- </div>
212
-
213
- <!-- SMTP Authentication -->
214
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
215
- <div class="wp-mail-smtp-setting-label">
216
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
217
- </div>
218
- <div class="wp-mail-smtp-setting-field">
219
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth">
220
- <input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"
221
- name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][auth]" value="yes"
222
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'auth' ) ? 'disabled' : ''; ?>
223
- <?php checked( true, $this->options->get( $this->get_slug(), 'auth' ) ); ?>
224
- />
225
- <span class="wp-mail-smtp-setting-toggle-switch"></span>
226
- <span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
227
- <span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
228
- </label>
229
- </div>
230
- </div>
231
-
232
- <!-- SMTP Username -->
233
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
234
- <div class="wp-mail-smtp-setting-label">
235
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
236
- </div>
237
- <div class="wp-mail-smtp-setting-field">
238
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
239
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'user' ) ); ?>"
240
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
241
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="off"
242
- />
243
- </div>
244
- </div>
245
-
246
- <!-- SMTP Password -->
247
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
248
- <div class="wp-mail-smtp-setting-label">
249
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
250
- </div>
251
- <div class="wp-mail-smtp-setting-field">
252
- <?php if ( $this->options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
253
- <input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
254
- <?php else : ?>
255
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
256
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'pass' ) ); ?>"
257
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="off"
258
- />
259
- <p class="desc">
260
- <?php
261
- printf(
262
- /* translators: %s - wp-config.php. */
263
- esc_html__( 'The password is stored in plain text. We highly recommend you setup your password in your WordPress configuration file for improved security; to do this add the lines below to your %s file.', 'wp-mail-smtp' ),
264
- '<code>wp-config.php</code>'
265
- );
266
- ?>
267
- </p>
268
- <pre>
269
- define( 'WPMS_ON', true );
270
- define( 'WPMS_SMTP_PASS', 'your_password' );
271
- </pre>
272
- <?php endif; ?>
273
- </div>
274
- </div>
275
-
276
- <?php
277
- }
278
-
279
- /**
280
- * Check whether we can use this provider based on the PHP version.
281
- * Valid for those, that use SDK.
282
- *
283
- * @return bool
284
- */
285
- protected function is_php_correct() {
286
- return version_compare( phpversion(), $this->php, '>=' );
287
- }
288
-
289
- /**
290
- * Display a helpful message to those users, that are using an outdated version of PHP,
291
- * which is not supported by the currently selected Provider.
292
- */
293
- protected function display_php_warning() {
294
- ?>
295
-
296
- <blockquote>
297
- <?php
298
- printf(
299
- /* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
300
- esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
301
- $this->title,
302
- $this->php,
303
- phpversion()
304
- )
305
- ?>
306
- <br>
307
- <?php esc_html_e( 'Meanwhile you can switch to the "Other SMTP" Mailer option.', 'wp-mail-smtp' ); ?>
308
- </blockquote>
309
-
310
- <?php
311
- }
312
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ use WPMailSMTP\Options;
6
+
7
+ /**
8
+ * Abstract Class ProviderAbstract to contain common providers functionality.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ abstract class OptionsAbstract implements OptionsInterface {
13
+
14
+ /**
15
+ * @var string
16
+ */
17
+ private $logo_url = '';
18
+ /**
19
+ * @var string
20
+ */
21
+ private $slug = '';
22
+ /**
23
+ * @var string
24
+ */
25
+ private $title = '';
26
+ /**
27
+ * @var string
28
+ */
29
+ private $description = '';
30
+ /**
31
+ * @var string
32
+ */
33
+ private $php = WPMS_PHP_VER;
34
+ /**
35
+ * @var Options
36
+ */
37
+ protected $options;
38
+
39
+ /**
40
+ * ProviderAbstract constructor.
41
+ *
42
+ * @since 1.0.0
43
+ *
44
+ * @param array $params
45
+ */
46
+ public function __construct( $params ) {
47
+
48
+ if (
49
+ empty( $params['slug'] ) ||
50
+ empty( $params['title'] )
51
+ ) {
52
+ return;
53
+ }
54
+
55
+ $this->slug = sanitize_key( $params['slug'] );
56
+ $this->title = sanitize_text_field( $params['title'] );
57
+
58
+ if ( ! empty( $params['description'] ) ) {
59
+ $this->description = wp_kses( $params['description'],
60
+ array(
61
+ 'br' => array(),
62
+ 'a' => array(
63
+ 'href' => array(),
64
+ 'rel' => array(),
65
+ 'target' => array(),
66
+ ),
67
+ )
68
+ );
69
+ }
70
+
71
+ if ( ! empty( $params['php'] ) ) {
72
+ $this->php = sanitize_text_field( $params['php'] );
73
+ }
74
+
75
+ if ( ! empty( $params['logo_url'] ) ) {
76
+ $this->logo_url = esc_url_raw( $params['logo_url'] );
77
+ }
78
+
79
+ $this->options = new Options();
80
+ }
81
+
82
+ /**
83
+ * @inheritdoc
84
+ */
85
+ public function get_logo_url() {
86
+ return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
87
+ }
88
+
89
+ /**
90
+ * @inheritdoc
91
+ */
92
+ public function get_slug() {
93
+ return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
94
+ }
95
+
96
+ /**
97
+ * @inheritdoc
98
+ */
99
+ public function get_title() {
100
+ return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
101
+ }
102
+
103
+ /**
104
+ * @inheritdoc
105
+ */
106
+ public function get_description() {
107
+ return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
108
+ }
109
+
110
+ /**
111
+ * @inheritdoc
112
+ */
113
+ public function get_php_version() {
114
+ return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
115
+ }
116
+
117
+ /**
118
+ * @inheritdoc
119
+ */
120
+ public function display_options() {
121
+ ?>
122
+
123
+ <!-- SMTP Host -->
124
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
125
+ <div class="wp-mail-smtp-setting-label">
126
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
127
+ </div>
128
+ <div class="wp-mail-smtp-setting-field">
129
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
130
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'host' ) ); ?>"
131
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
132
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
133
+ />
134
+ </div>
135
+ </div>
136
+
137
+ <!-- SMTP Port -->
138
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
139
+ <div class="wp-mail-smtp-setting-label">
140
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
141
+ </div>
142
+ <div class="wp-mail-smtp-setting-field">
143
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
144
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'port' ) ); ?>"
145
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
146
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
147
+ />
148
+ </div>
149
+ </div>
150
+
151
+ <!-- SMTP Encryption -->
152
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
153
+ <div class="wp-mail-smtp-setting-label">
154
+ <label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
155
+ </div>
156
+ <div class="wp-mail-smtp-setting-field">
157
+
158
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
159
+ <input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
160
+ name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
161
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
162
+ <?php checked( 'none', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
163
+ />
164
+ <?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
165
+ </label>
166
+
167
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
168
+ <input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
169
+ name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
170
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
171
+ <?php checked( 'ssl', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
172
+ />
173
+ <?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
174
+ </label>
175
+
176
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
177
+ <input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
178
+ name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
179
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
180
+ <?php checked( 'tls', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
181
+ />
182
+ <?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
183
+ </label>
184
+
185
+ <p class="desc">
186
+ <?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
187
+ </p>
188
+ </div>
189
+ </div>
190
+
191
+ <!-- PHPMailer SMTPAutoTLS -->
192
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
193
+ <div class="wp-mail-smtp-setting-label">
194
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
195
+ </div>
196
+ <div class="wp-mail-smtp-setting-field">
197
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls">
198
+ <input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"
199
+ name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][autotls]" value="yes"
200
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'autotls' ) ? 'disabled' : ''; ?>
201
+ <?php checked( true, $this->options->get( $this->get_slug(), 'autotls' ) ); ?>
202
+ />
203
+ <span class="wp-mail-smtp-setting-toggle-switch"></span>
204
+ <span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
205
+ <span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
206
+ </label>
207
+ <p class="desc">
208
+ <?php esc_html_e( 'By default TLS encryption is automatically used if the server supports it, which is recommended. In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
209
+ </p>
210
+ </div>
211
+ </div>
212
+
213
+ <!-- SMTP Authentication -->
214
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
215
+ <div class="wp-mail-smtp-setting-label">
216
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
217
+ </div>
218
+ <div class="wp-mail-smtp-setting-field">
219
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth">
220
+ <input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"
221
+ name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][auth]" value="yes"
222
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'auth' ) ? 'disabled' : ''; ?>
223
+ <?php checked( true, $this->options->get( $this->get_slug(), 'auth' ) ); ?>
224
+ />
225
+ <span class="wp-mail-smtp-setting-toggle-switch"></span>
226
+ <span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
227
+ <span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
228
+ </label>
229
+ </div>
230
+ </div>
231
+
232
+ <!-- SMTP Username -->
233
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
234
+ <div class="wp-mail-smtp-setting-label">
235
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
236
+ </div>
237
+ <div class="wp-mail-smtp-setting-field">
238
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
239
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'user' ) ); ?>"
240
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
241
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="off"
242
+ />
243
+ </div>
244
+ </div>
245
+
246
+ <!-- SMTP Password -->
247
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
248
+ <div class="wp-mail-smtp-setting-label">
249
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
250
+ </div>
251
+ <div class="wp-mail-smtp-setting-field">
252
+ <?php if ( $this->options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
253
+ <input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
254
+ <?php else : ?>
255
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
256
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'pass' ) ); ?>"
257
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="off"
258
+ />
259
+ <p class="desc">
260
+ <?php
261
+ printf(
262
+ /* translators: %s - wp-config.php. */
263
+ esc_html__( 'The password is stored in plain text. We highly recommend you setup your password in your WordPress configuration file for improved security; to do this add the lines below to your %s file.', 'wp-mail-smtp' ),
264
+ '<code>wp-config.php</code>'
265
+ );
266
+ ?>
267
+ </p>
268
+ <pre>
269
+ define( 'WPMS_ON', true );
270
+ define( 'WPMS_SMTP_PASS', 'your_password' );
271
+ </pre>
272
+ <?php endif; ?>
273
+ </div>
274
+ </div>
275
+
276
+ <?php
277
+ }
278
+
279
+ /**
280
+ * Check whether we can use this provider based on the PHP version.
281
+ * Valid for those, that use SDK.
282
+ *
283
+ * @return bool
284
+ */
285
+ protected function is_php_correct() {
286
+ return version_compare( phpversion(), $this->php, '>=' );
287
+ }
288
+
289
+ /**
290
+ * Display a helpful message to those users, that are using an outdated version of PHP,
291
+ * which is not supported by the currently selected Provider.
292
+ */
293
+ protected function display_php_warning() {
294
+ ?>
295
+
296
+ <blockquote>
297
+ <?php
298
+ printf(
299
+ /* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
300
+ esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
301
+ $this->title,
302
+ $this->php,
303
+ phpversion()
304
+ )
305
+ ?>
306
+ <br>
307
+ <?php esc_html_e( 'Meanwhile you can switch to the "Other SMTP" Mailer option.', 'wp-mail-smtp' ); ?>
308
+ </blockquote>
309
+
310
+ <?php
311
+ }
312
+ }
src/Providers/OptionsInterface.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers;
4
-
5
- /**
6
- * Interface ProviderInterface, shared between all current and future providers.
7
- * Defines required methods across all providers.
8
- *
9
- * @since 1.0.0
10
- */
11
- interface OptionsInterface {
12
-
13
- /**
14
- * Get the mailer provider slug.
15
- *
16
- * @since 1.0.0
17
- *
18
- * @return string
19
- */
20
- public function get_slug();
21
-
22
- /**
23
- * Get the mailer provider title (or name).
24
- *
25
- * @since 1.0.0
26
- *
27
- * @return string
28
- */
29
- public function get_title();
30
-
31
- /**
32
- * Get the mailer provider description.
33
- *
34
- * @since 1.0.0
35
- *
36
- * @return string
37
- */
38
- public function get_description();
39
-
40
- /**
41
- * Get the mailer provider minimum PHP version.
42
- *
43
- * @since 1.0.0
44
- *
45
- * @return string
46
- */
47
- public function get_php_version();
48
-
49
- /**
50
- * Get the mailer provider logo URL.
51
- *
52
- * @since 1.0.0
53
- *
54
- * @return string
55
- */
56
- public function get_logo_url();
57
-
58
- /**
59
- * Output the mailer provider options.
60
- *
61
- * @since 1.0.0
62
- */
63
- public function display_options();
64
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers;
4
+
5
+ /**
6
+ * Interface ProviderInterface, shared between all current and future providers.
7
+ * Defines required methods across all providers.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ interface OptionsInterface {
12
+
13
+ /**
14
+ * Get the mailer provider slug.
15
+ *
16
+ * @since 1.0.0
17
+ *
18
+ * @return string
19
+ */
20
+ public function get_slug();
21
+
22
+ /**
23
+ * Get the mailer provider title (or name).
24
+ *
25
+ * @since 1.0.0
26
+ *
27
+ * @return string
28
+ */
29
+ public function get_title();
30
+
31
+ /**
32
+ * Get the mailer provider description.
33
+ *
34
+ * @since 1.0.0
35
+ *
36
+ * @return string
37
+ */
38
+ public function get_description();
39
+
40
+ /**
41
+ * Get the mailer provider minimum PHP version.
42
+ *
43
+ * @since 1.0.0
44
+ *
45
+ * @return string
46
+ */
47
+ public function get_php_version();
48
+
49
+ /**
50
+ * Get the mailer provider logo URL.
51
+ *
52
+ * @since 1.0.0
53
+ *
54
+ * @return string
55
+ */
56
+ public function get_logo_url();
57
+
58
+ /**
59
+ * Output the mailer provider options.
60
+ *
61
+ * @since 1.0.0
62
+ */
63
+ public function display_options();
64
+ }
src/Providers/Pepipost/Mailer.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Pepipost;
4
-
5
- use WPMailSMTP\Providers\MailerAbstract;
6
-
7
- /**
8
- * Class Mailer inherits everything from parent abstract class.
9
- * This file is required for a proper work of Loader and \ReflectionClass.
10
- *
11
- * @package WPMailSMTP\Providers\Pepipost
12
- */
13
- class Mailer extends MailerAbstract {
14
-
15
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Pepipost;
4
+
5
+ use WPMailSMTP\Providers\MailerAbstract;
6
+
7
+ /**
8
+ * Class Mailer inherits everything from parent abstract class.
9
+ * This file is required for a proper work of Loader and \ReflectionClass.
10
+ *
11
+ * @package WPMailSMTP\Providers\Pepipost
12
+ */
13
+ class Mailer extends MailerAbstract {
14
+
15
+ }
src/Providers/Pepipost/Options.php CHANGED
@@ -1,29 +1,29 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Pepipost;
4
-
5
- use WPMailSMTP\Providers\OptionsAbstract;
6
-
7
- /**
8
- * Class Options.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Options extends OptionsAbstract {
13
-
14
- /**
15
- * Pepipost constructor.
16
- *
17
- * @since 1.0.0
18
- */
19
- public function __construct() {
20
-
21
- parent::__construct(
22
- array(
23
- 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/pepipost.png',
24
- 'slug' => 'pepipost',
25
- 'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
26
- )
27
- );
28
- }
29
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Pepipost;
4
+
5
+ use WPMailSMTP\Providers\OptionsAbstract;
6
+
7
+ /**
8
+ * Class Options.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Options extends OptionsAbstract {
13
+
14
+ /**
15
+ * Pepipost constructor.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ public function __construct() {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/pepipost.png',
24
+ 'slug' => 'pepipost',
25
+ 'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
26
+ )
27
+ );
28
+ }
29
+ }
src/Providers/SMTP/Mailer.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\SMTP;
4
-
5
- use WPMailSMTP\Providers\MailerAbstract;
6
-
7
- /**
8
- * Class Mailer inherits everything from parent abstract class.
9
- * This file is required for a proper work of Loader and \ReflectionClass.
10
- *
11
- * @package WPMailSMTP\Providers\SMTP
12
- */
13
- class Mailer extends MailerAbstract {
14
-
15
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\SMTP;
4
+
5
+ use WPMailSMTP\Providers\MailerAbstract;
6
+
7
+ /**
8
+ * Class Mailer inherits everything from parent abstract class.
9
+ * This file is required for a proper work of Loader and \ReflectionClass.
10
+ *
11
+ * @package WPMailSMTP\Providers\SMTP
12
+ */
13
+ class Mailer extends MailerAbstract {
14
+
15
+ }
src/Providers/SMTP/Options.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\SMTP;
4
-
5
- use WPMailSMTP\Providers\OptionsAbstract;
6
-
7
- /**
8
- * Class SMTP.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Options extends OptionsAbstract {
13
-
14
- /**
15
- * SMTP constructor.
16
- *
17
- * @since 1.0.0
18
- */
19
- public function __construct() {
20
-
21
- parent::__construct(
22
- array(
23
- 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/smtp.png',
24
- 'slug' => 'smtp',
25
- 'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
26
- /* translators: %1$s - opening link tag; %2$s - closing link tag. */
27
- 'description' => sprintf(
28
- wp_kses(
29
- __( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our %1$sSMTP documentation%2$s.', 'wp-mail-smtp' ),
30
- array(
31
- 'br' => array(),
32
- 'a' => array(
33
- 'href' => array(),
34
- 'rel' => array(),
35
- 'target' => array(),
36
- ),
37
- )
38
- ),
39
- '<a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" target="_blank" rel="noopener noreferrer">',
40
- '</a>'
41
- ),
42
- )
43
- );
44
- }
45
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\SMTP;
4
+
5
+ use WPMailSMTP\Providers\OptionsAbstract;
6
+
7
+ /**
8
+ * Class SMTP.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Options extends OptionsAbstract {
13
+
14
+ /**
15
+ * SMTP constructor.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ public function __construct() {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/smtp.png',
24
+ 'slug' => 'smtp',
25
+ 'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
26
+ /* translators: %1$s - opening link tag; %2$s - closing link tag. */
27
+ 'description' => sprintf(
28
+ wp_kses(
29
+ __( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our %1$sSMTP documentation%2$s.', 'wp-mail-smtp' ),
30
+ array(
31
+ 'br' => array(),
32
+ 'a' => array(
33
+ 'href' => array(),
34
+ 'rel' => array(),
35
+ 'target' => array(),
36
+ ),
37
+ )
38
+ ),
39
+ '<a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" target="_blank" rel="noopener noreferrer">',
40
+ '</a>'
41
+ ),
42
+ )
43
+ );
44
+ }
45
+ }
src/Providers/Sendgrid/Mailer.php CHANGED
@@ -1,344 +1,344 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Sendgrid;
4
-
5
- use WPMailSMTP\Providers\MailerAbstract;
6
-
7
- /**
8
- * Class Mailer.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Mailer extends MailerAbstract {
13
-
14
- /**
15
- * Which response code from HTTP provider is considered to be successful?
16
- *
17
- * @var int
18
- */
19
- protected $email_sent_code = 202;
20
-
21
- /**
22
- * URL to make an API request to.
23
- *
24
- * @var string
25
- */
26
- protected $url = 'https://api.sendgrid.com/v3/mail/send';
27
-
28
- /**
29
- * Mailer constructor.
30
- *
31
- * @since 1.0.0
32
- *
33
- * @param \WPMailSMTP\MailCatcher $phpmailer
34
- */
35
- public function __construct( $phpmailer ) {
36
-
37
- // We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
38
- parent::__construct( $phpmailer );
39
-
40
- $this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
41
- $this->set_header( 'content-type', 'application/json' );
42
- }
43
-
44
- /**
45
- * Redefine the way email body is returned.
46
- * By default we are sending an array of data.
47
- * SendGrid requires a JSON, so we encode the body.
48
- *
49
- * @since 1.0.0
50
- */
51
- public function get_body() {
52
-
53
- $body = parent::get_body();
54
-
55
- return wp_json_encode( $body );
56
- }
57
-
58
- /**
59
- * @inheritdoc
60
- */
61
- public function set_from( $email, $name = '' ) {
62
-
63
- if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
64
- return;
65
- }
66
-
67
- $from['email'] = $email;
68
-
69
- if ( ! empty( $name ) ) {
70
- $from['name'] = $name;
71
- }
72
-
73
- $this->set_body_param(
74
- array(
75
- 'from' => $from,
76
- )
77
- );
78
- }
79
-
80
- /**
81
- * @inheritdoc
82
- */
83
- public function set_recipients( $recipients ) {
84
-
85
- if ( empty( $recipients ) ) {
86
- return;
87
- }
88
-
89
- // Allow for now only these recipient types.
90
- $default = array( 'to', 'cc', 'bcc' );
91
- $data = array();
92
-
93
- foreach ( $recipients as $type => $emails ) {
94
- if (
95
- ! in_array( $type, $default, true ) ||
96
- empty( $emails ) ||
97
- ! is_array( $emails )
98
- ) {
99
- continue;
100
- }
101
-
102
- $data[ $type ] = array();
103
-
104
- // Iterate over all emails for each type.
105
- // There might be multiple cc/to/bcc emails.
106
- foreach ( $emails as $email ) {
107
- $holder = array();
108
- $addr = isset( $email[0] ) ? $email[0] : false;
109
- $name = isset( $email[1] ) ? $email[1] : false;
110
-
111
- if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
112
- continue;
113
- }
114
-
115
- $holder['email'] = $addr;
116
- if ( ! empty( $name ) ) {
117
- $holder['name'] = $name;
118
- }
119
-
120
- array_push( $data[ $type ], $holder );
121
- }
122
- }
123
-
124
- if ( ! empty( $data ) ) {
125
- $this->set_body_param(
126
- array(
127
- 'personalizations' => array( $data ),
128
- )
129
- );
130
- }
131
- }
132
-
133
- /**
134
- * @inheritdoc
135
- */
136
- public function set_content( $content ) {
137
-
138
- if ( empty( $content ) ) {
139
- return;
140
- }
141
-
142
- if ( is_array( $content ) ) {
143
-
144
- $default = array( 'text', 'html' );
145
- $data = array();
146
-
147
- foreach ( $content as $type => $body ) {
148
- if (
149
- ! in_array( $type, $default, true ) ||
150
- empty( $body )
151
- ) {
152
- continue;
153
- }
154
-
155
- $content_type = 'text/plain';
156
- $content_value = $body;
157
-
158
- if ( $type === 'html' ) {
159
- $content_type = 'text/html';
160
- }
161
-
162
- $data[] = array(
163
- 'type' => $content_type,
164
- 'value' => $content_value,
165
- );
166
- }
167
-
168
- $this->set_body_param(
169
- array(
170
- 'content' => $data,
171
- )
172
- );
173
- } else {
174
- $data['type'] = 'text/plain';
175
- $data['value'] = $content;
176
-
177
- if ( $this->phpmailer->ContentType === 'text/html' ) {
178
- $data['type'] = 'text/html';
179
- }
180
-
181
- $this->set_body_param(
182
- array(
183
- 'content' => array( $data ),
184
- )
185
- );
186
- }
187
- }
188
-
189
- /**
190
- * SendGrid accepts an array of files content in body, so we will include all files and send.
191
- * Doesn't handle exceeding the limits etc, as this is done and reported be SendGrid API.
192
- *
193
- * @since 1.0.0
194
- *
195
- * @param array $attachments
196
- */
197
- public function set_attachments( $attachments ) {
198
-
199
- if ( empty( $attachments ) ) {
200
- return;
201
- }
202
-
203
- $data = array();
204
-
205
- foreach ( $attachments as $attachment ) {
206
- $file = false;
207
-
208
- /*
209
- * We are not using WP_Filesystem API as we can't reliably work with it.
210
- * It is not always available, same as credentials for FTP.
211
- */
212
- try {
213
- if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
214
- $file = file_get_contents( $attachment[0] );
215
- }
216
- }
217
- catch ( \Exception $e ) {
218
- $file = false;
219
- }
220
-
221
- if ( $file === false ) {
222
- continue;
223
- }
224
-
225
- $data[] = array(
226
- 'content' => base64_encode( $file ),
227
- 'type' => $attachment[4],
228
- 'filename' => $attachment[1],
229
- 'disposition' => $attachment[6],
230
- );
231
- }
232
-
233
- if ( ! empty( $data ) ) {
234
- $this->set_body_param(
235
- array(
236
- 'attachments' => $data,
237
- )
238
- );
239
- }
240
- }
241
-
242
- /**
243
- * @inheritdoc
244
- */
245
- public function set_reply_to( $reply_to ) {
246
-
247
- if ( empty( $reply_to ) ) {
248
- return;
249
- }
250
-
251
- $data = array();
252
-
253
- foreach ( $reply_to as $key => $emails ) {
254
- if (
255
- empty( $emails ) ||
256
- ! is_array( $emails )
257
- ) {
258
- continue;
259
- }
260
-
261
- $addr = isset( $emails[0] ) ? $emails[0] : false;
262
- $name = isset( $emails[1] ) ? $emails[1] : false;
263
-
264
- if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
265
- continue;
266
- }
267
-
268
- $data['email'] = $addr;
269
- if ( ! empty( $name ) ) {
270
- $data['name'] = $name;
271
- }
272
-
273
- break;
274
- }
275
-
276
- if ( ! empty( $data ) ) {
277
- $this->set_body_param(
278
- array(
279
- 'reply_to' => $data,
280
- )
281
- );
282
- }
283
- }
284
-
285
- /**
286
- * SendGrid doesn't support sender or return_path params.
287
- * So we do nothing.
288
- *
289
- * @since 1.0.0
290
- *
291
- * @param string $email
292
- */
293
- public function set_return_path( $email ) {
294
- }
295
-
296
- /**
297
- * Get a SendGrid-specific response with a helpful error.
298
- *
299
- * @since 1.2.0
300
- *
301
- * @return string
302
- */
303
- protected function get_response_error() {
304
-
305
- $body = (array) wp_remote_retrieve_body( $this->response );
306
-
307
- $error_text = array();
308
-
309
- if ( ! empty( $body['errors'] ) ) {
310
- foreach ( $body['errors'] as $error ) {
311
- if ( property_exists( $error, 'message' ) ) {
312
- // Prepare additional information from SendGrid API.
313
- $extra = '';
314
- if ( property_exists( $error, 'field' ) && ! empty( $error->field ) ) {
315
- $extra .= $error->field . '; ';
316
- }
317
- if ( property_exists( $error, 'help' ) && ! empty( $error->help ) ) {
318
- $extra .= $error->help;
319
- }
320
-
321
- // Assign both the main message and perhaps extra information, if exists.
322
- $error_text[] = $error->message . ( ! empty( $extra ) ? ' - ' . $extra : '' );
323
- }
324
- }
325
- }
326
-
327
- return implode( '<br>', $error_text );
328
- }
329
-
330
- /**
331
- * @inheritdoc
332
- */
333
- public function get_debug_info() {
334
-
335
- $mg_text = array();
336
-
337
- $options = new \WPMailSMTP\Options();
338
- $mailgun = $options->get_group( 'sendgrid' );
339
-
340
- $mg_text[] = '<strong>Api Key:</strong> ' . ( ! empty( $mailgun['api_key'] ) ? 'Yes' : 'No' );
341
-
342
- return implode( '<br>', $mg_text );
343
- }
344
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Sendgrid;
4
+
5
+ use WPMailSMTP\Providers\MailerAbstract;
6
+
7
+ /**
8
+ * Class Mailer.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Mailer extends MailerAbstract {
13
+
14
+ /**
15
+ * Which response code from HTTP provider is considered to be successful?
16
+ *
17
+ * @var int
18
+ */
19
+ protected $email_sent_code = 202;
20
+
21
+ /**
22
+ * URL to make an API request to.
23
+ *
24
+ * @var string
25
+ */
26
+ protected $url = 'https://api.sendgrid.com/v3/mail/send';
27
+
28
+ /**
29
+ * Mailer constructor.
30
+ *
31
+ * @since 1.0.0
32
+ *
33
+ * @param \WPMailSMTP\MailCatcher $phpmailer
34
+ */
35
+ public function __construct( $phpmailer ) {
36
+
37
+ // We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
38
+ parent::__construct( $phpmailer );
39
+
40
+ $this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
41
+ $this->set_header( 'content-type', 'application/json' );
42
+ }
43
+
44
+ /**
45
+ * Redefine the way email body is returned.
46
+ * By default we are sending an array of data.
47
+ * SendGrid requires a JSON, so we encode the body.
48
+ *
49
+ * @since 1.0.0
50
+ */
51
+ public function get_body() {
52
+
53
+ $body = parent::get_body();
54
+
55
+ return wp_json_encode( $body );
56
+ }
57
+
58
+ /**
59
+ * @inheritdoc
60
+ */
61
+ public function set_from( $email, $name = '' ) {
62
+
63
+ if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
64
+ return;
65
+ }
66
+
67
+ $from['email'] = $email;
68
+
69
+ if ( ! empty( $name ) ) {
70
+ $from['name'] = $name;
71
+ }
72
+
73
+ $this->set_body_param(
74
+ array(
75
+ 'from' => $from,
76
+ )
77
+ );
78
+ }
79
+
80
+ /**
81
+ * @inheritdoc
82
+ */
83
+ public function set_recipients( $recipients ) {
84
+
85
+ if ( empty( $recipients ) ) {
86
+ return;
87
+ }
88
+
89
+ // Allow for now only these recipient types.
90
+ $default = array( 'to', 'cc', 'bcc' );
91
+ $data = array();
92
+
93
+ foreach ( $recipients as $type => $emails ) {
94
+ if (
95
+ ! in_array( $type, $default, true ) ||
96
+ empty( $emails ) ||
97
+ ! is_array( $emails )
98
+ ) {
99
+ continue;
100
+ }
101
+
102
+ $data[ $type ] = array();
103
+
104
+ // Iterate over all emails for each type.
105
+ // There might be multiple cc/to/bcc emails.
106
+ foreach ( $emails as $email ) {
107
+ $holder = array();
108
+ $addr = isset( $email[0] ) ? $email[0] : false;
109
+ $name = isset( $email[1] ) ? $email[1] : false;
110
+
111
+ if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
112
+ continue;
113
+ }
114
+
115
+ $holder['email'] = $addr;
116
+ if ( ! empty( $name ) ) {
117
+ $holder['name'] = $name;
118
+ }
119
+
120
+ array_push( $data[ $type ], $holder );
121
+ }
122
+ }
123
+
124
+ if ( ! empty( $data ) ) {
125
+ $this->set_body_param(
126
+ array(
127
+ 'personalizations' => array( $data ),
128
+ )
129
+ );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * @inheritdoc
135
+ */
136
+ public function set_content( $content ) {
137
+
138
+ if ( empty( $content ) ) {
139
+ return;
140
+ }
141
+
142
+ if ( is_array( $content ) ) {
143
+
144
+ $default = array( 'text', 'html' );
145
+ $data = array();
146
+
147
+ foreach ( $content as $type => $body ) {
148
+ if (
149
+ ! in_array( $type, $default, true ) ||
150
+ empty( $body )
151
+ ) {
152
+ continue;
153
+ }
154
+
155
+ $content_type = 'text/plain';
156
+ $content_value = $body;
157
+
158
+ if ( $type === 'html' ) {
159
+ $content_type = 'text/html';
160
+ }
161
+
162
+ $data[] = array(
163
+ 'type' => $content_type,
164
+ 'value' => $content_value,
165
+ );
166
+ }
167
+
168
+ $this->set_body_param(
169
+ array(
170
+ 'content' => $data,
171
+ )
172
+ );
173
+ } else {
174
+ $data['type'] = 'text/plain';
175
+ $data['value'] = $content;
176
+
177
+ if ( $this->phpmailer->ContentType === 'text/html' ) {
178
+ $data['type'] = 'text/html';
179
+ }
180
+
181
+ $this->set_body_param(
182
+ array(
183
+ 'content' => array( $data ),
184
+ )
185
+ );
186
+ }
187
+ }
188
+
189
+ /**
190
+ * SendGrid accepts an array of files content in body, so we will include all files and send.
191
+ * Doesn't handle exceeding the limits etc, as this is done and reported be SendGrid API.
192
+ *
193
+ * @since 1.0.0
194
+ *
195
+ * @param array $attachments
196
+ */
197
+ public function set_attachments( $attachments ) {
198
+
199
+ if ( empty( $attachments ) ) {
200
+ return;
201
+ }
202
+
203
+ $data = array();
204
+
205
+ foreach ( $attachments as $attachment ) {
206
+ $file = false;
207
+
208
+ /*
209
+ * We are not using WP_Filesystem API as we can't reliably work with it.
210
+ * It is not always available, same as credentials for FTP.
211
+ */
212
+ try {
213
+ if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
214
+ $file = file_get_contents( $attachment[0] );
215
+ }
216
+ }
217
+ catch ( \Exception $e ) {
218
+ $file = false;
219
+ }
220
+
221
+ if ( $file === false ) {
222
+ continue;
223
+ }
224
+
225
+ $data[] = array(
226
+ 'content' => base64_encode( $file ),
227
+ 'type' => $attachment[4],
228
+ 'filename' => $attachment[1],
229
+ 'disposition' => $attachment[6],
230
+ );
231
+ }
232
+
233
+ if ( ! empty( $data ) ) {
234
+ $this->set_body_param(
235
+ array(
236
+ 'attachments' => $data,
237
+ )
238
+ );
239
+ }
240
+ }
241
+
242
+ /**
243
+ * @inheritdoc
244
+ */
245
+ public function set_reply_to( $reply_to ) {
246
+
247
+ if ( empty( $reply_to ) ) {
248
+ return;
249
+ }
250
+
251
+ $data = array();
252
+
253
+ foreach ( $reply_to as $key => $emails ) {
254
+ if (
255
+ empty( $emails ) ||
256
+ ! is_array( $emails )
257
+ ) {
258
+ continue;
259
+ }
260
+
261
+ $addr = isset( $emails[0] ) ? $emails[0] : false;
262
+ $name = isset( $emails[1] ) ? $emails[1] : false;
263
+
264
+ if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
265
+ continue;
266
+ }
267
+
268
+ $data['email'] = $addr;
269
+ if ( ! empty( $name ) ) {
270
+ $data['name'] = $name;
271
+ }
272
+
273
+ break;
274
+ }
275
+
276
+ if ( ! empty( $data ) ) {
277
+ $this->set_body_param(
278
+ array(
279
+ 'reply_to' => $data,
280
+ )
281
+ );
282
+ }
283
+ }
284
+
285
+ /**
286
+ * SendGrid doesn't support sender or return_path params.
287
+ * So we do nothing.
288
+ *
289
+ * @since 1.0.0
290
+ *
291
+ * @param string $email
292
+ */
293
+ public function set_return_path( $email ) {
294
+ }
295
+
296
+ /**
297
+ * Get a SendGrid-specific response with a helpful error.
298
+ *
299
+ * @since 1.2.0
300
+ *
301
+ * @return string
302
+ */
303
+ protected function get_response_error() {
304
+
305
+ $body = (array) wp_remote_retrieve_body( $this->response );
306
+
307
+ $error_text = array();
308
+
309
+ if ( ! empty( $body['errors'] ) ) {
310
+ foreach ( $body['errors'] as $error ) {
311
+ if ( property_exists( $error, 'message' ) ) {
312
+ // Prepare additional information from SendGrid API.
313
+ $extra = '';
314
+ if ( property_exists( $error, 'field' ) && ! empty( $error->field ) ) {
315
+ $extra .= $error->field . '; ';
316
+ }
317
+ if ( property_exists( $error, 'help' ) && ! empty( $error->help ) ) {
318
+ $extra .= $error->help;
319
+ }
320
+
321
+ // Assign both the main message and perhaps extra information, if exists.
322
+ $error_text[] = $error->message . ( ! empty( $extra ) ? ' - ' . $extra : '' );
323
+ }
324
+ }
325
+ }
326
+
327
+ return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
328
+ }
329
+
330
+ /**
331
+ * @inheritdoc
332
+ */
333
+ public function get_debug_info() {
334
+
335
+ $mg_text = array();
336
+
337
+ $options = new \WPMailSMTP\Options();
338
+ $mailgun = $options->get_group( 'sendgrid' );
339
+
340
+ $mg_text[] = '<strong>Api Key:</strong> ' . ( ! empty( $mailgun['api_key'] ) ? 'Yes' : 'No' );
341
+
342
+ return implode( '<br>', $mg_text );
343
+ }
344
+ }
src/Providers/Sendgrid/Options.php CHANGED
@@ -1,89 +1,89 @@
1
- <?php
2
-
3
- namespace WPMailSMTP\Providers\Sendgrid;
4
-
5
- use WPMailSMTP\Providers\OptionsAbstract;
6
-
7
- /**
8
- * Class Option.
9
- *
10
- * @since 1.0.0
11
- */
12
- class Options extends OptionsAbstract {
13
-
14
- /**
15
- * Options constructor.
16
- *
17
- * @since 1.0.0
18
- */
19
- public function __construct() {
20
-
21
- parent::__construct(
22
- array(
23
- 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/sendgrid.png',
24
- 'slug' => 'sendgrid',
25
- 'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
26
- 'description' => sprintf(
27
- wp_kses(
28
- /* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
29
- __( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per month.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
30
- array(
31
- 'br' => array(),
32
- 'a' => array(
33
- 'href' => array(),
34
- 'rel' => array(),
35
- 'target' => array(),
36
- ),
37
- )
38
- ),
39
- '<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
40
- '</a>',
41
- '<a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" target="_blank" rel="noopener noreferrer">',
42
- '</a>'
43
- ),
44
- )
45
- );
46
- }
47
-
48
- /**
49
- * @inheritdoc
50
- */
51
- public function display_options() {
52
- ?>
53
-
54
- <!-- API Key -->
55
- <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
56
- <div class="wp-mail-smtp-setting-label">
57
- <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
58
- </div>
59
- <div class="wp-mail-smtp-setting-field">
60
- <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
61
- value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
62
- <?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
63
- id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
64
- />
65
- <p class="desc">
66
- <?php
67
- printf(
68
- /* translators: %s - API key link. */
69
- esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
70
- '<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
71
- esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
72
- '</a>'
73
- );
74
- ?>
75
- <br/>
76
- <?php
77
- printf(
78
- /* translators: %s - SendGrid access level. */
79
- esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
80
- '<code>Mail Send</code>'
81
- );
82
- ?>
83
- </p>
84
- </div>
85
- </div>
86
-
87
- <?php
88
- }
89
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP\Providers\Sendgrid;
4
+
5
+ use WPMailSMTP\Providers\OptionsAbstract;
6
+
7
+ /**
8
+ * Class Option.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class Options extends OptionsAbstract {
13
+
14
+ /**
15
+ * Options constructor.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ public function __construct() {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/sendgrid.png',
24
+ 'slug' => 'sendgrid',
25
+ 'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
26
+ 'description' => sprintf(
27
+ wp_kses(
28
+ /* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
29
+ __( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per month.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
30
+ array(
31
+ 'br' => array(),
32
+ 'a' => array(
33
+ 'href' => array(),
34
+ 'rel' => array(),
35
+ 'target' => array(),
36
+ ),
37
+ )
38
+ ),
39
+ '<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
40
+ '</a>',
41
+ '<a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" target="_blank" rel="noopener noreferrer">',
42
+ '</a>'
43
+ ),
44
+ )
45
+ );
46
+ }
47
+
48
+ /**
49
+ * @inheritdoc
50
+ */
51
+ public function display_options() {
52
+ ?>
53
+
54
+ <!-- API Key -->
55
+ <div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
56
+ <div class="wp-mail-smtp-setting-label">
57
+ <label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
58
+ </div>
59
+ <div class="wp-mail-smtp-setting-field">
60
+ <input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
61
+ value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
62
+ <?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
63
+ id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
64
+ />
65
+ <p class="desc">
66
+ <?php
67
+ printf(
68
+ /* translators: %s - API key link. */
69
+ esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
70
+ '<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
71
+ esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
72
+ '</a>'
73
+ );
74
+ ?>
75
+ <br/>
76
+ <?php
77
+ printf(
78
+ /* translators: %s - SendGrid access level. */
79
+ esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
80
+ '<code>Mail Send</code>'
81
+ );
82
+ ?>
83
+ </p>
84
+ </div>
85
+ </div>
86
+
87
+ <?php
88
+ }
89
+ }
src/Upgrade.php CHANGED
@@ -1,71 +1,71 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class Upgrade helps upgrade plugin options and similar tasks when the
7
- * occasion arises.
8
- *
9
- * @since 1.1.0
10
- */
11
- class Upgrade {
12
-
13
- /**
14
- * Upgrade constructor.
15
- *
16
- * @since 1.1.0
17
- */
18
- public function __construct() {
19
-
20
- $upgrades = $this->upgrades();
21
-
22
- if ( empty( $upgrades ) ) {
23
- return;
24
- }
25
-
26
- // Run any available upgrades.
27
- foreach ( $upgrades as $upgrade ) {
28
- $this->{$upgrade}();
29
- }
30
-
31
- // Update version post upgrade(s).
32
- update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
33
- }
34
-
35
- /**
36
- * Whether we need to perform an upgrade.
37
- *
38
- * @since 1.1.0
39
- *
40
- * @return array
41
- */
42
- protected function upgrades() {
43
-
44
- $version = get_option( 'wp_mail_smtp_version' );
45
- $upgrades = array();
46
-
47
- // Version 1.1.0 upgrade; prior to this the option was not available.
48
- if ( empty( $version ) ) {
49
- $upgrades[] = 'v110_upgrade';
50
- }
51
-
52
- return $upgrades;
53
- }
54
-
55
- /**
56
- * Upgrade routine for v1.1.0.
57
- *
58
- * Set SMTPAutoTLS to true.
59
- *
60
- * @since 1.1.0
61
- */
62
- public function v110_upgrade() {
63
-
64
- $values = Options::init()->get_all();
65
-
66
- // Enable SMTPAutoTLS option.
67
- $values['smtp']['autotls'] = true;
68
-
69
- Options::init()->set( $values );
70
- }
71
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class Upgrade helps upgrade plugin options and similar tasks when the
7
+ * occasion arises.
8
+ *
9
+ * @since 1.1.0
10
+ */
11
+ class Upgrade {
12
+
13
+ /**
14
+ * Upgrade constructor.
15
+ *
16
+ * @since 1.1.0
17
+ */
18
+ public function __construct() {
19
+
20
+ $upgrades = $this->upgrades();
21
+
22
+ if ( empty( $upgrades ) ) {
23
+ return;
24
+ }
25
+
26
+ // Run any available upgrades.
27
+ foreach ( $upgrades as $upgrade ) {
28
+ $this->{$upgrade}();
29
+ }
30
+
31
+ // Update version post upgrade(s).
32
+ update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
33
+ }
34
+
35
+ /**
36
+ * Whether we need to perform an upgrade.
37
+ *
38
+ * @since 1.1.0
39
+ *
40
+ * @return array
41
+ */
42
+ protected function upgrades() {
43
+
44
+ $version = get_option( 'wp_mail_smtp_version' );
45
+ $upgrades = array();
46
+
47
+ // Version 1.1.0 upgrade; prior to this the option was not available.
48
+ if ( empty( $version ) ) {
49
+ $upgrades[] = 'v110_upgrade';
50
+ }
51
+
52
+ return $upgrades;
53
+ }
54
+
55
+ /**
56
+ * Upgrade routine for v1.1.0.
57
+ *
58
+ * Set SMTPAutoTLS to true.
59
+ *
60
+ * @since 1.1.0
61
+ */
62
+ public function v110_upgrade() {
63
+
64
+ $values = Options::init()->get_all();
65
+
66
+ // Enable SMTPAutoTLS option.
67
+ $values['smtp']['autotls'] = true;
68
+
69
+ Options::init()->set( $values );
70
+ }
71
+ }
src/WP.php CHANGED
@@ -1,140 +1,140 @@
1
- <?php
2
-
3
- namespace WPMailSMTP;
4
-
5
- /**
6
- * Class WP provides WordPress shortcuts.
7
- *
8
- * @since 1.0.0
9
- */
10
- class WP {
11
-
12
- /**
13
- * The "queue" of notices.
14
- *
15
- * @var array
16
- */
17
- protected static $admin_notices = array();
18
- /**
19
- * @var string
20
- */
21
- const ADMIN_NOTICE_SUCCESS = 'notice-success';
22
- /**
23
- * @var string
24
- */
25
- const ADMIN_NOTICE_ERROR = 'notice-error';
26
- /**
27
- * @var string
28
- */
29
- const ADMIN_NOTICE_INFO = 'notice-info';
30
- /**
31
- * @var string
32
- */
33
- const ADMIN_NOTICE_WARNING = 'notice-warning';
34
-
35
- /**
36
- * True is WP is processing an AJAX call.
37
- *
38
- * @since 1.0.0
39
- *
40
- * @return bool
41
- */
42
- public static function is_doing_ajax() {
43
-
44
- if ( function_exists( 'wp_doing_ajax' ) ) {
45
- return wp_doing_ajax();
46
- }
47
-
48
- return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
49
- }
50
-
51
- /**
52
- * True if I am in the Admin Panel, not doing AJAX.
53
- *
54
- * @since 1.0.0
55
- *
56
- * @return bool
57
- */
58
- public static function in_wp_admin() {
59
- return ( is_admin() && ! self::is_doing_ajax() );
60
- }
61
-
62
- /**
63
- * Add a notice to the "queue of notices".
64
- *
65
- * @since 1.0.0
66
- *
67
- * @param string $message Message text (HTML is OK).
68
- * @param string $class Display class (severity).
69
- */
70
- public static function add_admin_notice( $message, $class = self::ADMIN_NOTICE_INFO ) {
71
-
72
- self::$admin_notices[] = array(
73
- 'message' => $message,
74
- 'class' => $class,
75
- );
76
- }
77
-
78
- /**
79
- * Display all notices.
80
- *
81
- * @since 1.0.0
82
- */
83
- public static function display_admin_notices() {
84
-
85
- foreach ( (array) self::$admin_notices as $notice ) : ?>
86
-
87
- <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?> notice is-dismissible">
88
- <p>
89
- <?php echo $notice['message']; ?>
90
- </p>
91
- </div>
92
-
93
- <?php
94
- endforeach;
95
- }
96
-
97
- /**
98
- * Check whether WP_DEBUG is active.
99
- *
100
- * @since 1.0.0
101
- *
102
- * @return bool
103
- */
104
- public static function is_debug() {
105
- return defined( 'WP_DEBUG' ) && WP_DEBUG;
106
- }
107
-
108
- /**
109
- * Shortcut to global $wpdb.
110
- *
111
- * @since 1.0.0
112
- *
113
- * @return \wpdb
114
- */
115
- public static function wpdb() {
116
-
117
- global $wpdb;
118
-
119
- return $wpdb;
120
- }
121
-
122
- /**
123
- * Get the postfix for assets files - ".min" or empty.
124
- * ".min" if in production mode.
125
- *
126
- * @since 1.0.0
127
- *
128
- * @return string
129
- */
130
- public static function asset_min() {
131
-
132
- $min = '.min';
133
-
134
- if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
135
- $min = '';
136
- }
137
-
138
- return $min;
139
- }
140
- }
1
+ <?php
2
+
3
+ namespace WPMailSMTP;
4
+
5
+ /**
6
+ * Class WP provides WordPress shortcuts.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ class WP {
11
+
12
+ /**
13
+ * The "queue" of notices.
14
+ *
15
+ * @var array
16
+ */
17
+ protected static $admin_notices = array();
18
+ /**
19
+ * @var string
20
+ */
21
+ const ADMIN_NOTICE_SUCCESS = 'notice-success';
22
+ /**
23
+ * @var string
24
+ */
25
+ const ADMIN_NOTICE_ERROR = 'notice-error';
26
+ /**
27
+ * @var string
28
+ */
29
+ const ADMIN_NOTICE_INFO = 'notice-info';
30
+ /**
31
+ * @var string
32
+ */
33
+ const ADMIN_NOTICE_WARNING = 'notice-warning';
34
+
35
+ /**
36
+ * True is WP is processing an AJAX call.
37
+ *
38
+ * @since 1.0.0
39
+ *
40
+ * @return bool
41
+ */
42
+ public static function is_doing_ajax() {
43
+
44
+ if ( function_exists( 'wp_doing_ajax' ) ) {
45
+ return wp_doing_ajax();
46
+ }
47
+
48
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
49
+ }
50
+
51
+ /**
52
+ * True if I am in the Admin Panel, not doing AJAX.
53
+ *
54
+ * @since 1.0.0
55
+ *
56
+ * @return bool
57
+ */
58
+ public static function in_wp_admin() {
59
+ return ( is_admin() && ! self::is_doing_ajax() );
60
+ }
61
+
62
+ /**
63
+ * Add a notice to the "queue of notices".
64
+ *
65
+ * @since 1.0.0
66
+ *
67
+ * @param string $message Message text (HTML is OK).
68
+ * @param string $class Display class (severity).
69
+ */
70
+ public static function add_admin_notice( $message, $class = self::ADMIN_NOTICE_INFO ) {
71
+
72
+ self::$admin_notices[] = array(
73
+ 'message' => $message,
74
+ 'class' => $class,
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Display all notices.
80
+ *
81
+ * @since 1.0.0
82
+ */
83
+ public static function display_admin_notices() {
84
+
85
+ foreach ( (array) self::$admin_notices as $notice ) : ?>
86
+
87
+ <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?> notice is-dismissible">
88
+ <p>
89
+ <?php echo $notice['message']; ?>
90
+ </p>
91
+ </div>
92
+
93
+ <?php
94
+ endforeach;
95
+ }
96
+
97
+ /**
98
+ * Check whether WP_DEBUG is active.
99
+ *
100
+ * @since 1.0.0
101
+ *
102
+ * @return bool
103
+ */
104
+ public static function is_debug() {
105
+ return defined( 'WP_DEBUG' ) && WP_DEBUG;
106
+ }
107
+
108
+ /**
109
+ * Shortcut to global $wpdb.
110
+ *
111
+ * @since 1.0.0
112
+ *
113
+ * @return \wpdb
114
+ */
115
+ public static function wpdb() {
116
+
117
+ global $wpdb;
118
+
119
+ return $wpdb;
120
+ }
121
+
122
+ /**
123
+ * Get the postfix for assets files - ".min" or empty.
124
+ * ".min" if in production mode.
125
+ *
126
+ * @since 1.0.0
127
+ *
128
+ * @return string
129
+ */
130
+ public static function asset_min() {
131
+
132
+ $min = '.min';
133
+
134
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
135
+ $min = '';
136
+ }
137
+
138
+ return $min;
139
+ }
140
+ }
wp-mail-smtp.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- /**
8
- * Autoloader. Inspired by PSR-4 examples:
9
- *
10
- * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
11
- *
12
- * @since 1.0.0
13
- *
14
- * @param string $class The fully-qualified class name.
15
- */
16
- spl_autoload_register( function ( $class ) {
17
-
18
- list( $plugin_space ) = explode( '\\', $class );
19
- if ( $plugin_space !== 'WPMailSMTP' ) {
20
- return;
21
- }
22
-
23
- $plugin_folder = 'wp-mail-smtp';
24
-
25
- // Default directory for all code is plugin's /src/.
26
- $base_dir = WP_PLUGIN_DIR . '/' . $plugin_folder . '/src/';
27
-
28
- // Get the relative class name.
29
- $relative_class = substr( $class, strlen( $plugin_space ) + 1 );
30
-
31
- /**
32
- * Normalize a filesystem path.
33
- * Copy of the `wp_normalize_path()` from WordPress 3.9.
34
- *
35
- * @since 1.2.0
36
- *
37
- * @param string $path
38
- *
39
- * @return string
40
- */
41
- $normalize = function( $path ) {
42
- $path = str_replace( '\\', '/', $path );
43
- $path = preg_replace( '|(?<=.)/+|', '/', $path );
44
- if ( ':' === substr( $path, 1, 1 ) ) {
45
- $path = ucfirst( $path );
46
- }
47
- return $path;
48
- };
49
-
50
- // Prepare a path to a file.
51
- $file = $normalize( $base_dir . $relative_class . '.php' );
52
-
53
- // If the file exists, require it.
54
- if ( is_readable( $file ) ) {
55
- /** @noinspection PhpIncludeInspection */
56
- require_once $file;
57
- }
58
- } );
59
-
60
- /**
61
- * Global function-holder. Works similar to a singleton's instance().
62
- *
63
- * @since 1.0.0
64
- *
65
- * @return WPMailSMTP\Core
66
- */
67
- function wp_mail_smtp() {
68
- /**
69
- * @var \WPMailSMTP\Core
70
- */
71
- static $core;
72
-
73
- if ( ! isset( $core ) ) {
74
- $core = new \WPMailSMTP\Core();
75
- }
76
-
77
- return $core;
78
- }
79
-
80
- wp_mail_smtp();
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ /**
8
+ * Autoloader. Inspired by PSR-4 examples:
9
+ *
10
+ * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
11
+ *
12
+ * @since 1.0.0
13
+ *
14
+ * @param string $class The fully-qualified class name.
15
+ */
16
+ spl_autoload_register( function ( $class ) {
17
+
18
+ list( $plugin_space ) = explode( '\\', $class );
19
+ if ( $plugin_space !== 'WPMailSMTP' ) {
20
+ return;
21
+ }
22
+
23
+ $plugin_folder = 'wp-mail-smtp';
24
+
25
+ // Default directory for all code is plugin's /src/.
26
+ $base_dir = WP_PLUGIN_DIR . '/' . $plugin_folder . '/src/';
27
+
28
+ // Get the relative class name.
29
+ $relative_class = substr( $class, strlen( $plugin_space ) + 1 );
30
+
31
+ /**
32
+ * Normalize a filesystem path.
33
+ * Copy of the `wp_normalize_path()` from WordPress 3.9.
34
+ *
35
+ * @since 1.2.0
36
+ *
37
+ * @param string $path
38
+ *
39
+ * @return string
40
+ */
41
+ $normalize = function( $path ) {
42
+ $path = str_replace( '\\', '/', $path );
43
+ $path = preg_replace( '|(?<=.)/+|', '/', $path );
44
+ if ( ':' === substr( $path, 1, 1 ) ) {
45
+ $path = ucfirst( $path );
46
+ }
47
+ return $path;
48
+ };
49
+
50
+ // Prepare a path to a file.
51
+ $file = $normalize( $base_dir . $relative_class . '.php' );
52
+
53
+ // If the file exists, require it.
54
+ if ( is_readable( $file ) ) {
55
+ /** @noinspection PhpIncludeInspection */
56
+ require_once $file;
57
+ }
58
+ } );
59
+
60
+ /**
61
+ * Global function-holder. Works similar to a singleton's instance().
62
+ *
63
+ * @since 1.0.0
64
+ *
65
+ * @return WPMailSMTP\Core
66
+ */
67
+ function wp_mail_smtp() {
68
+ /**
69
+ * @var \WPMailSMTP\Core
70
+ */
71
+ static $core;
72
+
73
+ if ( ! isset( $core ) ) {
74
+ $core = new \WPMailSMTP\Core();
75
+ }
76
+
77
+ return $core;
78
+ }
79
+
80
+ wp_mail_smtp();
wp_mail_smtp.php CHANGED
@@ -1,856 +1,856 @@
1
- <?php
2
- /**
3
- * Plugin Name: WP Mail SMTP
4
- * Version: 1.2.3
5
- * Plugin URI: https://wpforms.com/
6
- * Description: Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings.
7
- * Author: WPForms
8
- * Author URI: https://wpforms.com/
9
- * Text Domain: wp-mail-smtp
10
- * Domain Path: /languages
11
- */
12
-
13
- /**
14
- * @author WPForms
15
- * @copyright WPForms, 2007-17, All Rights Reserved
16
- * This code is released under the GPL licence version 3 or later, available here
17
- * http://www.gnu.org/licenses/gpl.txt
18
- */
19
-
20
- define( 'WPMS_PLUGIN_VER', '1.2.3' );
21
- define( 'WPMS_PHP_VER', '5.3' );
22
-
23
- /**
24
- * Setting options in wp-config.php
25
- *
26
- * Specifically aimed at WPMU users, you can set the options for this plugin as
27
- * constants in wp-config.php. This disables the plugin's admin page and may
28
- * improve performance very slightly. Copy the code below into wp-config.php.
29
- */
30
-
31
- /*
32
- define('WPMS_ON', true);
33
- define('WPMS_MAIL_FROM', 'From Email');
34
- define('WPMS_MAIL_FROM_NAME', 'From Name');
35
- define('WPMS_MAILER', 'smtp'); // Possible values 'smtp', 'mail', or 'sendmail'
36
- define('WPMS_SET_RETURN_PATH', 'false'); // Sets $phpmailer->Sender if true
37
- define('WPMS_SMTP_HOST', 'localhost'); // The SMTP mail host
38
- define('WPMS_SMTP_PORT', 25); // The SMTP server port number
39
- define('WPMS_SSL', ''); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS
40
- define('WPMS_SMTP_AUTH', true); // True turns on SMTP authentication, false turns it off
41
- define('WPMS_SMTP_USER', 'username'); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true
42
- define('WPMS_SMTP_PASS', 'password'); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true
43
- */
44
-
45
- /**
46
- * Newer PHP version 5.3+ will be handled a lot differently,
47
- * with better code and newer logic.
48
- *
49
- * @since 1.0.0
50
- */
51
- if ( version_compare( phpversion(), WPMS_PHP_VER, '>=' ) ) {
52
- require_once dirname( __FILE__ ) . '/wp-mail-smtp.php';
53
- return;
54
- }
55
-
56
- /**
57
- * Array of options and their default values.
58
- * This is horrible, should be cleaned up at some point.
59
- */
60
- global $wpms_options;
61
- $wpms_options = array(
62
- 'mail_from' => '',
63
- 'mail_from_name' => '',
64
- 'mailer' => 'smtp',
65
- 'mail_set_return_path' => 'false',
66
- 'smtp_host' => 'localhost',
67
- 'smtp_port' => '25',
68
- 'smtp_ssl' => 'none',
69
- 'smtp_auth' => false,
70
- 'smtp_user' => '',
71
- 'smtp_pass' => '',
72
- 'pepipost_user' => '',
73
- 'pepipost_pass' => '',
74
- 'pepipost_port' => '2525',
75
- 'pepipost_ssl' => 'none',
76
- 'wp_mail_smtp_am_notifications_hidden' => '',
77
- );
78
-
79
- /**
80
- * Activation function. This function creates the required options and defaults.
81
- */
82
- if ( ! function_exists( 'wp_mail_smtp_activate' ) ) :
83
- /**
84
- * What to do on plugin activation.
85
- */
86
- function wp_mail_smtp_activate() {
87
-
88
- global $wpms_options;
89
-
90
- // Create the required options...
91
- foreach ( $wpms_options as $name => $val ) {
92
- add_option( $name, $val );
93
- }
94
- }
95
- endif;
96
-
97
- if ( ! function_exists( 'wp_mail_smtp_whitelist_options' ) ) :
98
- /**
99
- * Whitelist plugin options.
100
- *
101
- * @param array $whitelist_options
102
- *
103
- * @return mixed
104
- */
105
- function wp_mail_smtp_whitelist_options( $whitelist_options ) {
106
-
107
- global $wpms_options;
108
-
109
- // Add our options to the array.
110
- $whitelist_options['email'] = array_keys( $wpms_options );
111
-
112
- return $whitelist_options;
113
- }
114
- endif;
115
-
116
- /**
117
- * To avoid any (very unlikely) clashes, check if the function already exists.
118
- */
119
- if ( ! function_exists( 'phpmailer_init_smtp' ) ) :
120
- /**
121
- * This code is copied, from wp-includes/pluggable.php as at version 2.2.2.
122
- *
123
- * @param PHPMailer $phpmailer It's passed by reference, so no need to return anything.
124
- */
125
- function phpmailer_init_smtp( $phpmailer ) {
126
- /*
127
- * If constants are defined, apply them.
128
- * We should have defined all required constants before using them.
129
- */
130
- if (
131
- defined( 'WPMS_ON' ) && WPMS_ON &&
132
- defined( 'WPMS_MAILER' )
133
- ) {
134
- $phpmailer->Mailer = WPMS_MAILER;
135
-
136
- if ( defined( 'WPMS_SET_RETURN_PATH' ) && WPMS_SET_RETURN_PATH ) {
137
- $phpmailer->Sender = $phpmailer->From;
138
- }
139
-
140
- if (
141
- WPMS_MAILER === 'smtp' &&
142
- defined( 'WPMS_SSL' ) &&
143
- defined( 'WPMS_SMTP_HOST' ) &&
144
- defined( 'WPMS_SMTP_PORT' )
145
- ) {
146
- $phpmailer->SMTPSecure = WPMS_SSL;
147
- $phpmailer->Host = WPMS_SMTP_HOST;
148
- $phpmailer->Port = WPMS_SMTP_PORT;
149
-
150
- if (
151
- defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH &&
152
- defined( 'WPMS_SMTP_USER' ) &&
153
- defined( 'WPMS_SMTP_PASS' )
154
- ) {
155
- $phpmailer->SMTPAuth = true;
156
- $phpmailer->Username = WPMS_SMTP_USER;
157
- $phpmailer->Password = WPMS_SMTP_PASS;
158
- }
159
- }
160
- } else {
161
- $option_mailer = get_option( 'mailer' );
162
- $option_smtp_host = get_option( 'smtp_host' );
163
- $option_smtp_ssl = get_option( 'smtp_ssl' );
164
-
165
- // Check that mailer is not blank, and if mailer=smtp, host is not blank.
166
- if (
167
- ! $option_mailer ||
168
- ( 'smtp' === $option_mailer && ! $option_smtp_host )
169
- ) {
170
- return;
171
- }
172
-
173
- // If the mailer is pepipost, make sure we have a username and password.
174
- if ( 'pepipost' === $option_mailer && ( ! get_option( 'pepipost_user' ) && ! get_option( 'pepipost_pass' ) ) ) {
175
- return;
176
- }
177
-
178
- // Set the mailer type as per config above, this overrides the already called isMail method.
179
- $phpmailer->Mailer = $option_mailer;
180
-
181
- // Set the Sender (return-path) if required.
182
- if ( get_option( 'mail_set_return_path' ) ) {
183
- $phpmailer->Sender = $phpmailer->From;
184
- }
185
-
186
- // Set the SMTPSecure value, if set to none, leave this blank.
187
- $phpmailer->SMTPSecure = $option_smtp_ssl;
188
- if ( 'none' === $option_smtp_ssl ) {
189
- $phpmailer->SMTPSecure = '';
190
- $phpmailer->SMTPAutoTLS = false;
191
- }
192
-
193
- // If we're sending via SMTP, set the host.
194
- if ( 'smtp' === $option_mailer ) {
195
- // Set the other options.
196
- $phpmailer->Host = $option_smtp_host;
197
- $phpmailer->Port = get_option( 'smtp_port' );
198
-
199
- // If we're using smtp auth, set the username & password.
200
- if ( get_option( 'smtp_auth' ) === 'true' ) {
201
- $phpmailer->SMTPAuth = true;
202
- $phpmailer->Username = get_option( 'smtp_user' );
203
- $phpmailer->Password = get_option( 'smtp_pass' );
204
- }
205
- } elseif ( 'pepipost' === $option_mailer ) {
206
- // Set the Pepipost settings.
207
- $phpmailer->Mailer = 'smtp';
208
- $phpmailer->Host = 'smtp.pepipost.com';
209
- $phpmailer->Port = get_option( 'pepipost_port' );
210
- $phpmailer->SMTPSecure = get_option( 'pepipost_ssl' ) === 'none' ? '' : get_option( 'pepipost_ssl' );
211
- $phpmailer->SMTPAuth = true;
212
- $phpmailer->Username = get_option( 'pepipost_user' );
213
- $phpmailer->Password = get_option( 'pepipost_pass' );
214
- }
215
- }
216
-
217
- // You can add your own options here, see the phpmailer documentation for more info: http://phpmailer.sourceforge.net/docs/.
218
- /** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */
219
- $phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer );
220
- }
221
- endif;
222
-
223
- if ( ! function_exists( 'wp_mail_smtp_options_page' ) ) :
224
- /**
225
- * This function outputs the plugin options page.
226
- */
227
- function wp_mail_smtp_options_page() {
228
-
229
- global $phpmailer;
230
-
231
- // Make sure the PHPMailer class has been instantiated
232
- // (copied verbatim from wp-includes/pluggable.php)
233
- // (Re)create it, if it's gone missing.
234
- if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
235
- require_once ABSPATH . WPINC . '/class-phpmailer.php';
236
- $phpmailer = new PHPMailer( true );
237
- }
238
-
239
- // Send a test mail if necessary.
240
- if (
241
- isset( $_POST['wpms_action'] ) &&
242
- esc_html__( 'Send Test', 'wp-mail-smtp' ) === sanitize_text_field( $_POST['wpms_action'] ) &&
243
- is_email( $_POST['to'] )
244
- ) {
245
-
246
- check_admin_referer( 'test-email' );
247
-
248
- // Set up the mail variables.
249
- $to = sanitize_text_field( $_POST['to'] );
250
- /* translators: %s - email address where test mail will be sent to. */
251
- $subject = 'WP Mail SMTP: ' . sprintf( esc_html__( 'Test mail to %s', 'wp-mail-smtp' ), $to );
252
- $message = esc_html__( 'This is a test email generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' );
253
-
254
- // Set SMTPDebug level, default is 2 (commands + data + connection status).
255
- $phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 2 );
256
-
257
- // Start output buffering to grab smtp debugging output.
258
- ob_start();
259
-
260
- // Send the test mail.
261
- $result = wp_mail( $to, $subject, $message );
262
-
263
- // Grab the smtp debugging output.
264
- $smtp_debug = ob_get_clean();
265
-
266
- // Output the response.
267
- ?>
268
- <div id="message" class="updated notice is-dismissible"><p><strong><?php esc_html_e( 'Test Message Sent', 'wp-mail-smtp' ); ?></strong></p>
269
- <p><?php esc_html_e( 'The result was:', 'wp-mail-smtp' ); ?></p>
270
- <pre><?php var_dump( $result ); ?></pre>
271
-
272
- <p><?php esc_html_e( 'The full debugging output is shown below:', 'wp-mail-smtp' ); ?></p>
273
- <pre><?php print_r( $phpmailer ); ?></pre>
274
-
275
- <p><?php esc_html_e( 'The SMTP debugging output is shown below:', 'wp-mail-smtp' ); ?></p>
276
- <pre><?php echo $smtp_debug; ?></pre>
277
- </div>
278
- <?php
279
-
280
- // Destroy $phpmailer so it doesn't cause issues later.
281
- unset( $phpmailer );
282
- }
283
-
284
- ?>
285
- <div class="wrap">
286
- <h2>
287
- <?php esc_html_e( 'WP Mail SMTP Settings', 'wp-mail-smtp' ); ?>
288
- </h2>
289
-
290
- <form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
291
- <?php wp_nonce_field( 'email-options' ); ?>
292
-
293
- <table class="form-table">
294
- <tr valign="top">
295
- <th scope="row">
296
- <label for="mail_from"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
297
- </th>
298
- <td>
299
- <input name="mail_from" type="email" id="mail_from" value="<?php print( get_option( 'mail_from' ) ); ?>" size="40" class="regular-text"/>
300
-
301
- <p class="description">
302
- <?php
303
- esc_html_e( 'You can specify the email address that emails should be sent from. If you leave this blank, the default email will be used.', 'wp-mail-smtp' );
304
- if ( get_option( 'db_version' ) < 6124 ) {
305
- print( '<br /><span style="color: red;">' );
306
- _e( '<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name&lt;email@domain.com&gt; in this field.', 'wp-mail-smtp' );
307
- print( '</span>' );
308
- }
309
- ?>
310
- </p>
311
- </td>
312
- </tr>
313
- <tr valign="top">
314
- <th scope="row">
315
- <label for="mail_from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
316
- </th>
317
- <td>
318
- <input name="mail_from_name" type="text" id="mail_from_name" value="<?php print( get_option( 'mail_from_name' ) ); ?>" size="40" class="regular-text"/>
319
-
320
- <p class="description">
321
- <?php esc_html_e( 'You can specify the name that emails should be sent from. If you leave this blank, the emails will be sent from WordPress.', 'wp-mail-smtp' ); ?>
322
- </p>
323
- </td>
324
- </tr>
325
- </table>
326
-
327
- <table class="form-table">
328
- <tr valign="top">
329
- <th scope="row">
330
- <?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?>
331
- </th>
332
- <td>
333
- <fieldset>
334
- <legend class="screen-reader-text">
335
- <span><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></span>
336
- </legend>
337
-
338
- <p>
339
- <input id="mailer_smtp" class="wpms_mailer" type="radio" name="mailer" value="smtp" <?php checked( 'smtp', get_option( 'mailer' ) ); ?> />
340
- <label for="mailer_smtp"><?php esc_html_e( 'Send all WordPress emails via SMTP.', 'wp-mail-smtp' ); ?></label>
341
- </p>
342
- <p>
343
- <input id="mailer_mail" class="wpms_mailer" type="radio" name="mailer" value="mail" <?php checked( 'mail', get_option( 'mailer' ) ); ?> />
344
- <label for="mailer_mail"><?php esc_html_e( 'Use the PHP mail() function to send emails.', 'wp-mail-smtp' ); ?></label>
345
- </p>
346
-
347
- <?php if ( wp_mail_smtp_is_pepipost_active() ) : ?>
348
- <p>
349
- <input id="mailer_pepipost" class="wpms_mailer" type="radio" name="mailer" value="pepipost" <?php checked( 'pepipost', get_option( 'mailer' ) ); ?> />
350
- <label for="mailer_pepipost"><?php esc_html_e( 'Use Pepipost SMTP to send emails.', 'wp-mail-smtp' ); ?></label>
351
- </p>
352
- <p class="description">
353
- <?php
354
- printf(
355
- /* translators: %1$s - link start; %2$s - link end. */
356
- esc_html__( 'Looking for high inbox delivery? Try Pepipost with easy setup and free emails. Learn more %1$shere%2$s.', 'wp-mail-smtp' ),
357
- '<a href="https://app1.pepipost.com/index.php/login/wp_mail_smtp?page=signup&utm_source=WordPress&utm_campaign=Plugins&utm_medium=wp_mail_smtp&utm_term=organic&code=WP-MAIL-SMTP" target="_blank">',
358
- '</a>'
359
- );
360
- ?>
361
- </p>
362
- <?php endif; ?>
363
- </fieldset>
364
- </td>
365
- </tr>
366
- </table>
367
-
368
- <table class="form-table">
369
- <tr valign="top">
370
- <th scope="row">
371
- <?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?>
372
- </th>
373
- <td>
374
- <fieldset>
375
- <legend class="screen-reader-text">
376
- <span><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></span>
377
- </legend>
378
-
379
- <label for="mail_set_return_path">
380
- <input name="mail_set_return_path" type="checkbox" id="mail_set_return_path" value="true" <?php checked( 'true', get_option( 'mail_set_return_path' ) ); ?> />
381
- <?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?>
382
- </label>
383
-
384
- <p class="description">
385
- <?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?>
386
- </p>
387
- </fieldset>
388
- </td>
389
- </tr>
390
- </table>
391
-
392
- <table class="form-table">
393
- <tr valign="top">
394
- <th scope="row">
395
- <?php _e( 'Hide Announcements', 'wp-mail-smtp' ); ?>
396
- </th>
397
- <td>
398
- <fieldset>
399
- <legend class="screen-reader-text">
400
- <span><?php _e( 'Hide Announcements', 'wp-mail-smtp' ); ?></span>
401
- </legend>
402
-
403
- <label for="wp_mail_smtp_am_notifications_hidden">
404
- <input name="wp_mail_smtp_am_notifications_hidden" type="checkbox" id="wp_mail_smtp_am_notifications_hidden" value="true" <?php checked( 'true', get_option( 'wp_mail_smtp_am_notifications_hidden' ) ); ?> />
405
- <?php _e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?>
406
- </label>
407
- </fieldset>
408
- </td>
409
- </tr>
410
- </table>
411
-
412
- <p class="submit">
413
- <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/>
414
- </p>
415
-
416
- <div id="wpms_section_smtp" class="wpms_section">
417
- <h3>
418
- <?php esc_html_e( 'SMTP Options', 'wp-mail-smtp' ); ?>
419
- </h3>
420
- <p><?php esc_html_e( 'These options only apply if you have chosen to send mail by SMTP above.', 'wp-mail-smtp' ); ?></p>
421
-
422
- <table class="form-table">
423
- <tr valign="top">
424
- <th scope="row">
425
- <label for="smtp_host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
426
- </th>
427
- <td>
428
- <input name="smtp_host" type="text" id="smtp_host" value="<?php print( get_option( 'smtp_host' ) ); ?>" size="40" class="regular-text"/>
429
- </td>
430
- </tr>
431
- <tr valign="top">
432
- <th scope="row">
433
- <label for="smtp_port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
434
- </th>
435
- <td>
436
- <input name="smtp_port" type="text" id="smtp_port" value="<?php print( get_option( 'smtp_port' ) ); ?>" size="6" class="regular-text"/>
437
- </td>
438
- </tr>
439
- <tr valign="top">
440
- <th scope="row"><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?> </th>
441
- <td>
442
- <fieldset>
443
- <legend class="screen-reader-text">
444
- <span><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></span>
445
- </legend>
446
-
447
- <input id="smtp_ssl_none" type="radio" name="smtp_ssl" value="none" <?php checked( 'none', get_option( 'smtp_ssl' ) ); ?> />
448
- <label for="smtp_ssl_none">
449
- <span><?php esc_html_e( 'No encryption.', 'wp-mail-smtp' ); ?></span>
450
- </label><br/>
451
-
452
- <input id="smtp_ssl_ssl" type="radio" name="smtp_ssl" value="ssl" <?php checked( 'ssl', get_option( 'smtp_ssl' ) ); ?> />
453
- <label for="smtp_ssl_ssl">
454
- <span><?php esc_html_e( 'Use SSL encryption.', 'wp-mail-smtp' ); ?></span>
455
- </label><br/>
456
-
457
- <input id="smtp_ssl_tls" type="radio" name="smtp_ssl" value="tls" <?php checked( 'tls', get_option( 'smtp_ssl' ) ); ?> />
458
- <label for="smtp_ssl_tls">
459
- <span><?php esc_html_e( 'Use TLS encryption.', 'wp-mail-smtp' ); ?></span>
460
- </label>
461
-
462
- <p class="description"><?php esc_html_e( 'TLS is not the same as STARTTLS. For most servers SSL is the recommended option.', 'wp-mail-smtp' ); ?></p>
463
- </fieldset>
464
- </td>
465
- </tr>
466
- <tr valign="top">
467
- <th scope="row"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?> </th>
468
- <td>
469
- <fieldset>
470
- <legend class="screen-reader-text">
471
- <span><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></span>
472
- </legend>
473
-
474
- <input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked( 'false', get_option( 'smtp_auth' ) ); ?> />
475
- <label for="smtp_auth_false">
476
- <span><?php esc_html_e( 'No: Do not use SMTP authentication.', 'wp-mail-smtp' ); ?></span>
477
- </label><br/>
478
-
479
- <input id="smtp_auth_true" type="radio" name="smtp_auth" value="true" <?php checked( 'true', get_option( 'smtp_auth' ) ); ?> />
480
- <label for="smtp_auth_true">
481
- <span><?php esc_html_e( 'Yes: Use SMTP authentication.', 'wp-mail-smtp' ); ?></span>
482
- </label><br/>
483
-
484
- <p class="description">
485
- <?php esc_html_e( 'If this is set to no, the values below are ignored.', 'wp-mail-smtp' ); ?>
486
- </p>
487
- </fieldset>
488
- </td>
489
- </tr>
490
- <tr valign="top">
491
- <th scope="row">
492
- <label for="smtp_user"><?php esc_html_e( 'Username', 'wp-mail-smtp' ); ?></label>
493
- </th>
494
- <td>
495
- <input name="smtp_user" type="text" id="smtp_user" value="<?php print( get_option( 'smtp_user' ) ); ?>" size="40" class="code" autocomplete="off"/>
496
- </td>
497
- </tr>
498
- <tr valign="top">
499
- <th scope="row">
500
- <label for="smtp_pass"><?php esc_html_e( 'Password', 'wp-mail-smtp' ); ?></label>
501
- </th>
502
- <td>
503
- <input name="smtp_pass" type="password" id="smtp_pass" value="<?php print( get_option( 'smtp_pass' ) ); ?>" size="40" class="code" autocomplete="off"/>
504
-
505
- <p class="description">
506
- <?php esc_html_e( 'This is in plain text because it must not be stored encrypted.', 'wp-mail-smtp' ); ?>
507
- </p>
508
- </td>
509
- </tr>
510
- </table>
511
-
512
- <p class="submit">
513
- <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/>
514
- </p>
515
- </div><!-- #wpms_section_smtp -->
516
-
517
- <?php if ( wp_mail_smtp_is_pepipost_active() ) : ?>
518
- <div id="wpms_section_pepipost" class="wpms_section">
519
- <h3>
520
- <?php esc_html_e( 'Pepipost SMTP Options', 'wp-mail-smtp' ); ?>
521
- </h3>
522
- <p>
523
- <?php
524
- printf(
525
- /* translators: %s - Pepipost registration URL. */
526
- esc_html__( 'You need to signup on %s to get the SMTP username/password.', 'wp-mail-smtp' ),
527
- '<a href="https://app1.pepipost.com/index.php/login/wp_mail_smtp?page=signup&utm_source=WordPress&utm_campaign=Plugins&utm_medium=wp_mail_smtp&utm_term=organic&code=WP-MAIL-SMTP" target="_blank">Pepipost</a>',
528
- ''
529
- );
530
- ?>
531
- </p>
532
- <table class="form-table">
533
- <tr valign="top">
534
- <th scope="row">
535
- <label for="pepipost_user"><?php esc_html_e( 'Username', 'wp-mail-smtp' ); ?></label>
536
- </th>
537
- <td>
538
- <input name="pepipost_user" type="text" id="pepipost_user" value="<?php print( get_option( 'pepipost_user' ) ); ?>" size="40" class="code"/>
539
- </td>
540
- </tr>
541
- <tr valign="top">
542
- <th scope="row">
543
- <label for="pepipost_pass"><?php esc_html_e( 'Password', 'wp-mail-smtp' ); ?></label>
544
- </th>
545
- <td>
546
- <input name="pepipost_pass" type="text" id="pepipost_pass" value="<?php print( get_option( 'pepipost_pass' ) ); ?>" size="40" class="code"/>
547
- </td>
548
- </tr>
549
- <tr valign="top">
550
- <th scope="row">
551
- <label for="pepipost_port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
552
- </th>
553
- <td>
554
- <input name="pepipost_port" type="text" id="pepipost_port" value="<?php print( get_option( 'pepipost_port' ) ); ?>" size="6" class="regular-text"/>
555
- </td>
556
- </tr>
557
- <tr valign="top">
558
- <th scope="row">
559
- <?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?>
560
- </th>
561
- <td>
562
- <fieldset>
563
- <legend class="screen-reader-text">
564
- <span>
565
- <?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?>
566
- </span>
567
- </legend>
568
-
569
- <input id="pepipost_ssl_none" type="radio" name="pepipost_ssl" value="none" <?php checked( 'none', get_option( 'pepipost_ssl' ) ); ?> />
570
- <label for="pepipost_ssl_none">
571
- <span><?php esc_html_e( 'No encryption.', 'wp-mail-smtp' ); ?></span>
572
- </label><br/>
573
-
574
- <input id="pepipost_ssl_ssl" type="radio" name="pepipost_ssl" value="ssl" <?php checked( 'ssl', get_option( 'pepipost_ssl' ) ); ?> />
575
- <label for="pepipost_ssl_ssl">
576
- <span><?php esc_html_e( 'Use SSL encryption.', 'wp-mail-smtp' ); ?></span>
577
- </label><br/>
578
-
579
- <input id="pepipost_ssl_tls" type="radio" name="pepipost_ssl" value="tls" <?php checked( 'tls', get_option( 'pepipost_ssl' ) ); ?> />
580
- <label for="pepipost_ssl_tls">
581
- <span><?php esc_html_e( 'Use TLS encryption.', 'wp-mail-smtp' ); ?></span>
582
- </label>
583
- </fieldset>
584
- </td>
585
- </tr>
586
- </table>
587
-
588
- <p class="submit">
589
- <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/>
590
- </p>
591
- </div><!-- #wpms_section_pepipost -->
592
- <?php endif; ?>
593
-
594
- <input type="hidden" name="action" value="update"/>
595
- <input type="hidden" name="option_page" value="email">
596
- </form>
597
-
598
- <h3><?php esc_html_e( 'Send a Test Email', 'wp-mail-smtp' ); ?></h3>
599
-
600
- <form method="POST" action="">
601
- <?php wp_nonce_field( 'test-email' ); ?>
602
-
603
- <table class="form-table">
604
- <tr valign="top">
605
- <th scope="row">
606
- <label for="to"><?php esc_html_e( 'To', 'wp-mail-smtp' ); ?></label>
607
- </th>
608
- <td>
609
- <input name="to" type="email" id="to" value="" size="40" class="code"/>
610
- <p class="description"><?php esc_html_e( 'Type an email address here and then click Send Test to generate a test email.', 'wp-mail-smtp' ); ?></p>
611
- </td>
612
- </tr>
613
- </table>
614
-
615
- <p class="submit">
616
- <input type="submit" name="wpms_action" id="wpms_action" class="button-primary" value="<?php esc_attr_e( 'Send Test', 'wp-mail-smtp' ); ?>"/>
617
- </p>
618
- </form>
619
-
620
- <script type="text/javascript">
621
- /* globals jQuery */
622
- var wpmsOnMailerChange = function ( mailer ) {
623
- // Hide all the mailer forms.
624
- jQuery( '.wpms_section' ).hide();
625
- // Show the target mailer form.
626
- jQuery( '#wpms_section_' + mailer ).show();
627
- };
628
- jQuery( document ).ready( function () {
629
- // Call wpmsOnMailerChange() on startup with the current mailer.
630
- wpmsOnMailerChange( jQuery( 'input.wpms_mailer:checked' ).val() );
631
-
632
- // Watch the mailer for any changes
633
- jQuery( 'input.wpms_mailer' ).on( 'change', function ( e ) {
634
- // Call the wpmsOnMailerChange() handler, passing the value of the newly selected mailer.
635
- wpmsOnMailerChange( jQuery( e.target ).val() );
636
- } );
637
- } );
638
- </script>
639
-
640
- </div>
641
- <?php
642
- } // End of wp_mail_smtp_options_page() function definition.
643
- endif;
644
-
645
- if ( ! function_exists( 'wp_mail_smtp_menus' ) ) :
646
- /**
647
- * This function adds the required page (only 1 at the moment).
648
- */
649
- function wp_mail_smtp_menus() {
650
-
651
- if ( function_exists( 'add_submenu_page' ) ) {
652
- add_options_page( esc_html__( 'WP Mail SMTP Settings', 'wp-mail-smtp' ), esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ), 'manage_options', __FILE__, 'wp_mail_smtp_options_page' );
653
- }
654
- } // End of wp_mail_smtp_menus() function definition.
655
- endif;
656
-
657
- if ( ! function_exists( 'wp_mail_smtp_mail_from' ) ) :
658
- /**
659
- * This function sets the from email value.
660
- *
661
- * @param string $orig
662
- *
663
- * @return string
664
- */
665
- function wp_mail_smtp_mail_from( $orig ) {
666
- /*
667
- * This is copied from pluggable.php lines 348-354 as at revision 10150
668
- * http://trac.wordpress.org/browser/branches/2.7/wp-includes/pluggable.php#L348.
669
- */
670
-
671
- // In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
672
- $server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
673
-
674
- // Get the site domain and get rid of www.
675
- $sitename = strtolower( $server_name );
676
- if ( substr( $sitename, 0, 4 ) === 'www.' ) {
677
- $sitename = substr( $sitename, 4 );
678
- }
679
-
680
- $default_from = 'wordpress@' . $sitename;
681
-
682
- /*
683
- * End of copied code.
684
- */
685
-
686
- // If the from email is not the default, return it unchanged.
687
- if ( $orig !== $default_from ) {
688
- return $orig;
689
- }
690
-
691
- if (
692
- defined( 'WPMS_ON' ) && WPMS_ON &&
693
- defined( 'WPMS_MAIL_FROM' )
694
- ) {
695
- $mail_from_email = WPMS_MAIL_FROM;
696
-
697
- if ( ! empty( $mail_from_email ) ) {
698
- return $mail_from_email;
699
- }
700
- }
701
-
702
- if ( is_email( get_option( 'mail_from' ), false ) ) {
703
- return get_option( 'mail_from' );
704
- }
705
-
706
- // If in doubt, return the original value.
707
- return $orig;
708
- } // End of wp_mail_smtp_mail_from() function definition.
709
- endif;
710
-
711
- if ( ! function_exists( 'wp_mail_smtp_mail_from_name' ) ) :
712
- /**
713
- * This function sets the from name value.
714
- *
715
- * @param string $orig
716
- *
717
- * @return string
718
- */
719
- function wp_mail_smtp_mail_from_name( $orig ) {
720
-
721
- // Only filter if the from name is the default.
722
- if ( 'WordPress' === $orig ) {
723
- if (
724
- defined( 'WPMS_ON' ) && WPMS_ON &&
725
- defined( 'WPMS_MAIL_FROM_NAME' )
726
- ) {
727
- $mail_from_name = WPMS_MAIL_FROM_NAME;
728
-
729
- if ( ! empty( $mail_from_name ) ) {
730
- return $mail_from_name;
731
- }
732
- }
733
-
734
- $from_name = get_option( 'mail_from_name' );
735
- if ( ! empty( $from_name ) && is_string( $from_name ) ) {
736
- return $from_name;
737
- }
738
- }
739
-
740
- return $orig;
741
- }
742
- endif;
743
-
744
- /**
745
- * Add a link to Settings page of a plugin on Plugins page.
746
- *
747
- * @param array $links
748
- * @param string $file
749
- *
750
- * @return mixed
751
- */
752
- function wp_mail_plugin_action_links( $links, $file ) {
753
-
754
- if ( plugin_basename( __FILE__ ) !== $file ) {
755
- return $links;
756
- }
757
-
758
- $settings_link = '<a href="options-general.php?page=' . plugin_basename( __FILE__ ) . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
759
-
760
- array_unshift( $links, $settings_link );
761
-
762
- return $links;
763
- }
764
-
765
- /**
766
- * Awesome Motive Notifications.
767
- *
768
- * @since 0.11
769
- */
770
- function wp_mail_smtp_am_notifications() {
771
-
772
- $is_hidden = get_option( 'wp_mail_smtp_am_notifications_hidden', '' );
773
-
774
- if ( 'true' === $is_hidden ) {
775
- return;
776
- }
777
-
778
- if ( ! class_exists( 'WPMS_AM_Notification' ) ) {
779
- require_once dirname( __FILE__ ) . '/class-wpms-am-notification.php';
780
- }
781
-
782
- new WPMS_AM_Notification( 'smtp', WPMS_PLUGIN_VER );
783
- }
784
-
785
- add_action( 'plugins_loaded', 'wp_mail_smtp_am_notifications' );
786
-
787
- /**
788
- * Check whether the site is using Pepipost or not.
789
- *
790
- * @since 0.11
791
- *
792
- * @return bool
793
- */
794
- function wp_mail_smtp_is_pepipost_active() {
795
- return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', 'pepipost' === get_option( 'mailer' ) );
796
- }
797
-
798
- /**
799
- * Check the current PHP version and display a notice if on unsupported PHP.
800
- *
801
- * @since 0.11
802
- */
803
- function wp_mail_smtp_check_php_version() {
804
-
805
- // Display for PHP below 5.3.
806
- if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
807
- return;
808
- }
809
-
810
- // Display for admins only.
811
- if ( ! is_super_admin() ) {
812
- return;
813
- }
814
-
815
- // Display on Dashboard page only.
816
- if ( isset( $GLOBALS['pagenow'] ) && 'index.php' !== $GLOBALS['pagenow'] ) {
817
- return;
818
- }
819
-
820
- echo '<div class="notice notice-error">' .
821
- '<p>' .
822
- sprintf(
823
- /* translators: %1$s - WP Mail SMTP plugin name; %2$s - opening a link tag; %3$s - closing a link tag. */
824
- esc_html__(
825
- 'Your site is running an outdated version of PHP that is no longer supported and may cause issues with %1$s. %2$sRead more%3$s for additional information.',
826
- 'wpforms'
827
- ),
828
- '<strong>WP Mail SMTP</strong>',
829
- '<a href="https://wpforms.com/docs/supported-php-version/" target="_blank">',
830
- '</a>'
831
- ) .
832
- '</p>' .
833
- '</div>';
834
- }
835
-
836
- add_action( 'admin_notices', 'wp_mail_smtp_check_php_version' );
837
-
838
- // Add an action on phpmailer_init.
839
- add_action( 'phpmailer_init', 'phpmailer_init_smtp' );
840
-
841
- if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) {
842
- // Whitelist our options.
843
- add_filter( 'whitelist_options', 'wp_mail_smtp_whitelist_options' );
844
- // Add the create pages options.
845
- add_action( 'admin_menu', 'wp_mail_smtp_menus' );
846
- // Add an activation hook for this plugin.
847
- register_activation_hook( __FILE__, 'wp_mail_smtp_activate' );
848
- // Adds "Settings" link to the Plugins page.
849
- add_filter( 'plugin_action_links', 'wp_mail_plugin_action_links', 10, 2 );
850
- }
851
-
852
- // Add filters to replace the mail from name and email address.
853
- add_filter( 'wp_mail_from', 'wp_mail_smtp_mail_from' );
854
- add_filter( 'wp_mail_from_name', 'wp_mail_smtp_mail_from_name' );
855
-
856
- load_plugin_textdomain( 'wp-mail-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
1
+ <?php
2
+ /**
3
+ * Plugin Name: WP Mail SMTP
4
+ * Version: 1.2.4
5
+ * Plugin URI: https://wpforms.com/
6
+ * Description: Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings.
7
+ * Author: WPForms
8
+ * Author URI: https://wpforms.com/
9
+ * Text Domain: wp-mail-smtp
10
+ * Domain Path: /languages
11
+ */
12
+
13
+ /**
14
+ * @author WPForms
15
+ * @copyright WPForms, 2007-17, All Rights Reserved
16
+ * This code is released under the GPL licence version 3 or later, available here
17
+ * http://www.gnu.org/licenses/gpl.txt
18
+ */
19
+
20
+ define( 'WPMS_PLUGIN_VER', '1.2.4' );
21
+ define( 'WPMS_PHP_VER', '5.3' );
22
+
23
+ /**
24
+ * Setting options in wp-config.php
25
+ *
26
+ * Specifically aimed at WPMU users, you can set the options for this plugin as
27
+ * constants in wp-config.php. This disables the plugin's admin page and may
28
+ * improve performance very slightly. Copy the code below into wp-config.php.
29
+ */
30
+
31
+ /*
32
+ define('WPMS_ON', true);
33
+ define('WPMS_MAIL_FROM', 'From Email');
34
+ define('WPMS_MAIL_FROM_NAME', 'From Name');
35
+ define('WPMS_MAILER', 'smtp'); // Possible values 'smtp', 'mail', or 'sendmail'
36
+ define('WPMS_SET_RETURN_PATH', 'false'); // Sets $phpmailer->Sender if true
37
+ define('WPMS_SMTP_HOST', 'localhost'); // The SMTP mail host
38
+ define('WPMS_SMTP_PORT', 25); // The SMTP server port number
39
+ define('WPMS_SSL', ''); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS
40
+ define('WPMS_SMTP_AUTH', true); // True turns on SMTP authentication, false turns it off
41
+ define('WPMS_SMTP_USER', 'username'); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true
42
+ define('WPMS_SMTP_PASS', 'password'); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true
43
+ */
44
+
45
+ /**
46
+ * Newer PHP version 5.3+ will be handled a lot differently,
47
+ * with better code and newer logic.
48
+ *
49
+ * @since 1.0.0
50
+ */
51
+ if ( version_compare( phpversion(), WPMS_PHP_VER, '>=' ) ) {
52
+ require_once dirname( __FILE__ ) . '/wp-mail-smtp.php';
53
+ return;
54
+ }
55
+
56
+ /**
57
+ * Array of options and their default values.
58
+ * This is horrible, should be cleaned up at some point.
59
+ */
60
+ global $wpms_options;
61
+ $wpms_options = array(
62
+ 'mail_from' => '',
63
+ 'mail_from_name' => '',
64
+ 'mailer' => 'smtp',
65
+ 'mail_set_return_path' => 'false',
66
+ 'smtp_host' => 'localhost',
67
+ 'smtp_port' => '25',
68
+ 'smtp_ssl' => 'none',
69
+ 'smtp_auth' => false,
70
+ 'smtp_user' => '',
71
+ 'smtp_pass' => '',
72
+ 'pepipost_user' => '',
73
+ 'pepipost_pass' => '',
74
+ 'pepipost_port' => '2525',
75
+ 'pepipost_ssl' => 'none',
76
+ 'wp_mail_smtp_am_notifications_hidden' => '',
77
+ );
78
+
79
+ /**
80
+ * Activation function. This function creates the required options and defaults.
81
+ */
82
+ if ( ! function_exists( 'wp_mail_smtp_activate' ) ) :
83
+ /**
84
+ * What to do on plugin activation.
85
+ */
86
+ function wp_mail_smtp_activate() {
87
+
88
+ global $wpms_options;
89
+
90
+ // Create the required options...
91
+ foreach ( $wpms_options as $name => $val ) {
92
+ add_option( $name, $val );
93
+ }
94
+ }
95
+ endif;
96
+
97
+ if ( ! function_exists( 'wp_mail_smtp_whitelist_options' ) ) :
98
+ /**
99
+ * Whitelist plugin options.
100
+ *
101
+ * @param array $whitelist_options
102
+ *
103
+ * @return mixed
104
+ */
105
+ function wp_mail_smtp_whitelist_options( $whitelist_options ) {
106
+
107
+ global $wpms_options;
108
+
109
+ // Add our options to the array.
110
+ $whitelist_options['email'] = array_keys( $wpms_options );
111
+
112
+ return $whitelist_options;
113
+ }
114
+ endif;
115
+
116
+ /**
117
+ * To avoid any (very unlikely) clashes, check if the function already exists.
118
+ */
119
+ if ( ! function_exists( 'phpmailer_init_smtp' ) ) :
120
+ /**
121
+ * This code is copied, from wp-includes/pluggable.php as at version 2.2.2.
122
+ *
123
+ * @param PHPMailer $phpmailer It's passed by reference, so no need to return anything.
124
+ */
125
+ function phpmailer_init_smtp( $phpmailer ) {
126
+ /*
127
+ * If constants are defined, apply them.
128
+ * We should have defined all required constants before using them.
129
+ */
130
+ if (
131
+ defined( 'WPMS_ON' ) && WPMS_ON &&
132
+ defined( 'WPMS_MAILER' )
133
+ ) {
134
+ $phpmailer->Mailer = WPMS_MAILER;
135
+
136
+ if ( defined( 'WPMS_SET_RETURN_PATH' ) && WPMS_SET_RETURN_PATH ) {
137
+ $phpmailer->Sender = $phpmailer->From;
138
+ }
139
+
140
+ if (
141
+ WPMS_MAILER === 'smtp' &&
142
+ defined( 'WPMS_SSL' ) &&
143
+ defined( 'WPMS_SMTP_HOST' ) &&
144
+ defined( 'WPMS_SMTP_PORT' )
145
+ ) {
146
+ $phpmailer->SMTPSecure = WPMS_SSL;
147
+ $phpmailer->Host = WPMS_SMTP_HOST;
148
+ $phpmailer->Port = WPMS_SMTP_PORT;
149
+
150
+ if (
151
+ defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH &&
152
+ defined( 'WPMS_SMTP_USER' ) &&
153
+ defined( 'WPMS_SMTP_PASS' )
154
+ ) {
155
+ $phpmailer->SMTPAuth = true;
156
+ $phpmailer->Username = WPMS_SMTP_USER;
157
+ $phpmailer->Password = WPMS_SMTP_PASS;
158
+ }
159
+ }
160
+ } else {
161
+ $option_mailer = get_option( 'mailer' );
162
+ $option_smtp_host = get_option( 'smtp_host' );
163
+ $option_smtp_ssl = get_option( 'smtp_ssl' );
164
+
165
+ // Check that mailer is not blank, and if mailer=smtp, host is not blank.
166
+ if (
167
+ ! $option_mailer ||
168
+ ( 'smtp' === $option_mailer && ! $option_smtp_host )
169
+ ) {
170
+ return;
171
+ }
172
+
173
+ // If the mailer is pepipost, make sure we have a username and password.
174
+ if ( 'pepipost' === $option_mailer && ( ! get_option( 'pepipost_user' ) && ! get_option( 'pepipost_pass' ) ) ) {
175
+ return;
176
+ }
177
+
178
+ // Set the mailer type as per config above, this overrides the already called isMail method.
179
+ $phpmailer->Mailer = $option_mailer;
180
+
181
+ // Set the Sender (return-path) if required.
182
+ if ( get_option( 'mail_set_return_path' ) ) {
183
+ $phpmailer->Sender = $phpmailer->From;
184
+ }
185
+
186
+ // Set the SMTPSecure value, if set to none, leave this blank.
187
+ $phpmailer->SMTPSecure = $option_smtp_ssl;
188
+ if ( 'none' === $option_smtp_ssl ) {
189
+ $phpmailer->SMTPSecure = '';
190
+ $phpmailer->SMTPAutoTLS = false;
191
+ }
192
+
193
+ // If we're sending via SMTP, set the host.
194
+ if ( 'smtp' === $option_mailer ) {
195
+ // Set the other options.
196
+ $phpmailer->Host = $option_smtp_host;
197
+ $phpmailer->Port = get_option( 'smtp_port' );
198
+
199
+ // If we're using smtp auth, set the username & password.
200
+ if ( get_option( 'smtp_auth' ) === 'true' ) {
201
+ $phpmailer->SMTPAuth = true;
202
+ $phpmailer->Username = get_option( 'smtp_user' );
203
+ $phpmailer->Password = get_option( 'smtp_pass' );
204
+ }
205
+ } elseif ( 'pepipost' === $option_mailer ) {
206
+ // Set the Pepipost settings.
207
+ $phpmailer->Mailer = 'smtp';
208
+ $phpmailer->Host = 'smtp.pepipost.com';
209
+ $phpmailer->Port = get_option( 'pepipost_port' );
210
+ $phpmailer->SMTPSecure = get_option( 'pepipost_ssl' ) === 'none' ? '' : get_option( 'pepipost_ssl' );
211
+ $phpmailer->SMTPAuth = true;
212
+ $phpmailer->Username = get_option( 'pepipost_user' );
213
+ $phpmailer->Password = get_option( 'pepipost_pass' );
214
+ }
215
+ }
216
+
217
+ // You can add your own options here, see the phpmailer documentation for more info: http://phpmailer.sourceforge.net/docs/.
218
+ /** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */
219
+ $phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer );
220
+ }
221
+ endif;
222
+
223
+ if ( ! function_exists( 'wp_mail_smtp_options_page' ) ) :
224
+ /**
225
+ * This function outputs the plugin options page.
226
+ */
227
+ function wp_mail_smtp_options_page() {
228
+
229
+ global $phpmailer;
230
+
231
+ // Make sure the PHPMailer class has been instantiated
232
+ // (copied verbatim from wp-includes/pluggable.php)
233
+ // (Re)create it, if it's gone missing.
234
+ if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
235
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
236
+ $phpmailer = new PHPMailer( true );
237
+ }
238
+
239
+ // Send a test mail if necessary.
240
+ if (
241
+ isset( $_POST['wpms_action'] ) &&
242
+ esc_html__( 'Send Test', 'wp-mail-smtp' ) === sanitize_text_field( $_POST['wpms_action'] ) &&
243
+ is_email( $_POST['to'] )
244
+ ) {
245
+
246
+ check_admin_referer( 'test-email' );
247
+
248
+ // Set up the mail variables.
249
+ $to = sanitize_text_field( $_POST['to'] );
250
+ /* translators: %s - email address where test mail will be sent to. */
251
+ $subject = 'WP Mail SMTP: ' . sprintf( esc_html__( 'Test mail to %s', 'wp-mail-smtp' ), $to );
252
+ $message = esc_html__( 'This is a test email generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' );
253
+
254
+ // Set SMTPDebug level, default is 2 (commands + data + connection status).
255
+ $phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 2 );
256
+
257
+ // Start output buffering to grab smtp debugging output.
258
+ ob_start();
259
+
260
+ // Send the test mail.
261
+ $result = wp_mail( $to, $subject, $message );
262
+
263
+ // Grab the smtp debugging output.
264
+ $smtp_debug = ob_get_clean();
265
+
266
+ // Output the response.
267
+ ?>
268
+ <div id="message" class="updated notice is-dismissible"><p><strong><?php esc_html_e( 'Test Message Sent', 'wp-mail-smtp' ); ?></strong></p>
269
+ <p><?php esc_html_e( 'The result was:', 'wp-mail-smtp' ); ?></p>
270
+ <pre><?php var_dump( $result ); ?></pre>
271
+
272
+ <p><?php esc_html_e( 'The full debugging output is shown below:', 'wp-mail-smtp' ); ?></p>
273
+ <pre><?php print_r( $phpmailer ); ?></pre>
274
+
275
+ <p><?php esc_html_e( 'The SMTP debugging output is shown below:', 'wp-mail-smtp' ); ?></p>
276
+ <pre><?php echo $smtp_debug; ?></pre>
277
+ </div>
278
+ <?php
279
+
280
+ // Destroy $phpmailer so it doesn't cause issues later.
281
+ unset( $phpmailer );
282
+ }
283
+
284
+ ?>
285
+ <div class="wrap">
286
+ <h2>
287
+ <?php esc_html_e( 'WP Mail SMTP Settings', 'wp-mail-smtp' ); ?>
288
+ </h2>
289
+
290
+ <form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
291
+ <?php wp_nonce_field( 'email-options' ); ?>
292
+
293
+ <table class="form-table">
294
+ <tr valign="top">
295
+ <th scope="row">
296
+ <label for="mail_from"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
297
+ </th>
298
+ <td>
299
+ <input name="mail_from" type="email" id="mail_from" value="<?php print( get_option( 'mail_from' ) ); ?>" size="40" class="regular-text"/>
300
+
301
+ <p class="description">
302
+ <?php
303
+ esc_html_e( 'You can specify the email address that emails should be sent from. If you leave this blank, the default email will be used.', 'wp-mail-smtp' );
304
+ if ( get_option( 'db_version' ) < 6124 ) {
305
+ print( '<br /><span style="color: red;">' );
306
+ _e( '<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name&lt;email@domain.com&gt; in this field.', 'wp-mail-smtp' );
307
+ print( '</span>' );
308
+ }
309
+ ?>
310
+ </p>
311
+ </td>
312
+ </tr>
313
+ <tr valign="top">
314
+ <th scope="row">
315
+ <label for="mail_from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
316
+ </th>
317
+ <td>
318
+ <input name="mail_from_name" type="text" id="mail_from_name" value="<?php print( get_option( 'mail_from_name' ) ); ?>" size="40" class="regular-text"/>
319
+
320
+ <p class="description">
321
+ <?php esc_html_e( 'You can specify the name that emails should be sent from. If you leave this blank, the emails will be sent from WordPress.', 'wp-mail-smtp' ); ?>
322
+ </p>
323
+ </td>
324
+ </tr>
325
+ </table>
326
+
327
+ <table class="form-table">
328
+ <tr valign="top">
329
+ <th scope="row">
330
+ <?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?>
331
+ </th>
332
+ <td>
333
+ <fieldset>
334
+ <legend class="screen-reader-text">
335
+ <span><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></span>
336
+ </legend>
337
+
338
+ <p>
339
+ <input id="mailer_smtp" class="wpms_mailer" type="radio" name="mailer" value="smtp" <?php checked( 'smtp', get_option( 'mailer' ) ); ?> />
340
+ <label for="mailer_smtp"><?php esc_html_e( 'Send all WordPress emails via SMTP.', 'wp-mail-smtp' ); ?></label>
341
+ </p>
342
+ <p>
343
+ <input id="mailer_mail" class="wpms_mailer" type="radio" name="mailer" value="mail" <?php checked( 'mail', get_option( 'mailer' ) ); ?> />
344
+ <label for="mailer_mail"><?php esc_html_e( 'Use the PHP mail() function to send emails.', 'wp-mail-smtp' ); ?></label>
345
+ </p>
346
+
347
+ <?php if ( wp_mail_smtp_is_pepipost_active() ) : ?>
348
+ <p>
349
+ <input id="mailer_pepipost" class="wpms_mailer" type="radio" name="mailer" value="pepipost" <?php checked( 'pepipost', get_option( 'mailer' ) ); ?> />
350
+ <label for="mailer_pepipost"><?php esc_html_e( 'Use Pepipost SMTP to send emails.', 'wp-mail-smtp' ); ?></label>
351
+ </p>
352
+ <p class="description">
353
+ <?php
354
+ printf(
355
+ /* translators: %1$s - link start; %2$s - link end. */
356
+ esc_html__( 'Looking for high inbox delivery? Try Pepipost with easy setup and free emails. Learn more %1$shere%2$s.', 'wp-mail-smtp' ),
357
+ '<a href="https://app1.pepipost.com/index.php/login/wp_mail_smtp?page=signup&utm_source=WordPress&utm_campaign=Plugins&utm_medium=wp_mail_smtp&utm_term=organic&code=WP-MAIL-SMTP" target="_blank">',
358
+ '</a>'
359
+ );
360
+ ?>
361
+ </p>
362
+ <?php endif; ?>
363
+ </fieldset>
364
+ </td>
365
+ </tr>
366
+ </table>
367
+
368
+ <table class="form-table">
369
+ <tr valign="top">
370
+ <th scope="row">
371
+ <?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?>
372
+ </th>
373
+ <td>
374
+ <fieldset>
375
+ <legend class="screen-reader-text">
376
+ <span><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></span>
377
+ </legend>
378
+
379
+ <label for="mail_set_return_path">
380
+ <input name="mail_set_return_path" type="checkbox" id="mail_set_return_path" value="true" <?php checked( 'true', get_option( 'mail_set_return_path' ) ); ?> />
381
+ <?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?>
382
+ </label>
383
+
384
+ <p class="description">
385
+ <?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?>
386
+ </p>
387
+ </fieldset>
388
+ </td>
389
+ </tr>
390
+ </table>
391
+
392
+ <table class="form-table">
393
+ <tr valign="top">
394
+ <th scope="row">
395
+ <?php _e( 'Hide Announcements', 'wp-mail-smtp' ); ?>
396
+ </th>
397
+ <td>
398
+ <fieldset>
399
+ <legend class="screen-reader-text">
400
+ <span><?php _e( 'Hide Announcements', 'wp-mail-smtp' ); ?></span>
401
+ </legend>
402
+
403
+ <label for="wp_mail_smtp_am_notifications_hidden">
404
+ <input name="wp_mail_smtp_am_notifications_hidden" type="checkbox" id="wp_mail_smtp_am_notifications_hidden" value="true" <?php checked( 'true', get_option( 'wp_mail_smtp_am_notifications_hidden' ) ); ?> />
405
+ <?php _e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?>
406
+ </label>
407
+ </fieldset>
408
+ </td>
409
+ </tr>
410
+ </table>
411
+
412
+ <p class="submit">
413
+ <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/>
414
+ </p>
415
+
416
+ <div id="wpms_section_smtp" class="wpms_section">
417
+ <h3>
418
+ <?php esc_html_e( 'SMTP Options', 'wp-mail-smtp' ); ?>
419
+ </h3>
420
+ <p><?php esc_html_e( 'These options only apply if you have chosen to send mail by SMTP above.', 'wp-mail-smtp' ); ?></p>
421
+
422
+ <table class="form-table">
423
+ <tr valign="top">
424
+ <th scope="row">
425
+ <label for="smtp_host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
426
+ </th>
427
+ <td>
428
+ <input name="smtp_host" type="text" id="smtp_host" value="<?php print( get_option( 'smtp_host' ) ); ?>" size="40" class="regular-text"/>
429
+ </td>
430
+ </tr>
431
+ <tr valign="top">
432
+ <th scope="row">
433
+ <label for="smtp_port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
434
+ </th>
435
+ <td>
436
+ <input name="smtp_port" type="text" id="smtp_port" value="<?php print( get_option( 'smtp_port' ) ); ?>" size="6" class="regular-text"/>
437
+ </td>
438
+ </tr>
439
+ <tr valign="top">
440
+ <th scope="row"><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?> </th>
441
+ <td>
442
+ <fieldset>
443
+ <legend class="screen-reader-text">
444
+ <span><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></span>
445
+ </legend>
446
+
447
+ <input id="smtp_ssl_none" type="radio" name="smtp_ssl" value="none" <?php checked( 'none', get_option( 'smtp_ssl' ) ); ?> />
448
+ <label for="smtp_ssl_none">
449
+ <span><?php esc_html_e( 'No encryption.', 'wp-mail-smtp' ); ?></span>
450
+ </label><br/>
451
+
452
+ <input id="smtp_ssl_ssl" type="radio" name="smtp_ssl" value="ssl" <?php checked( 'ssl', get_option( 'smtp_ssl' ) ); ?> />
453
+ <label for="smtp_ssl_ssl">
454
+ <span><?php esc_html_e( 'Use SSL encryption.', 'wp-mail-smtp' ); ?></span>
455
+ </label><br/>
456
+
457
+ <input id="smtp_ssl_tls" type="radio" name="smtp_ssl" value="tls" <?php checked( 'tls', get_option( 'smtp_ssl' ) ); ?> />
458
+ <label for="smtp_ssl_tls">
459
+ <span><?php esc_html_e( 'Use TLS encryption.', 'wp-mail-smtp' ); ?></span>
460
+ </label>
461
+
462
+ <p class="description"><?php esc_html_e( 'TLS is not the same as STARTTLS. For most servers SSL is the recommended option.', 'wp-mail-smtp' ); ?></p>
463
+ </fieldset>
464
+ </td>
465
+ </tr>
466
+ <tr valign="top">
467
+ <th scope="row"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?> </th>
468
+ <td>
469
+ <fieldset>
470
+ <legend class="screen-reader-text">
471
+ <span><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></span>
472
+ </legend>
473
+
474
+ <input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked( 'false', get_option( 'smtp_auth' ) ); ?> />
475
+ <label for="smtp_auth_false">
476
+ <span><?php esc_html_e( 'No: Do not use SMTP authentication.', 'wp-mail-smtp' ); ?></span>
477
+ </label><br/>
478
+
479
+ <input id="smtp_auth_true" type="radio" name="smtp_auth" value="true" <?php checked( 'true', get_option( 'smtp_auth' ) ); ?> />
480
+ <label for="smtp_auth_true">
481
+ <span><?php esc_html_e( 'Yes: Use SMTP authentication.', 'wp-mail-smtp' ); ?></span>
482
+ </label><br/>
483
+
484
+ <p class="description">
485
+ <?php esc_html_e( 'If this is set to no, the values below are ignored.', 'wp-mail-smtp' ); ?>
486
+ </p>
487
+ </fieldset>
488
+ </td>
489
+ </tr>
490
+ <tr valign="top">
491
+ <th scope="row">
492
+ <label for="smtp_user"><?php esc_html_e( 'Username', 'wp-mail-smtp' ); ?></label>
493
+ </th>
494
+ <td>
495
+ <input name="smtp_user" type="text" id="smtp_user" value="<?php print( get_option( 'smtp_user' ) ); ?>" size="40" class="code" autocomplete="off"/>
496
+ </td>
497
+ </tr>
498
+ <tr valign="top">
499
+ <th scope="row">
500
+ <label for="smtp_pass"><?php esc_html_e( 'Password', 'wp-mail-smtp' ); ?></label>
501
+ </th>
502
+ <td>
503
+ <input name="smtp_pass" type="password" id="smtp_pass" value="<?php print( get_option( 'smtp_pass' ) ); ?>" size="40" class="code" autocomplete="off"/>
504
+
505
+ <p class="description">
506
+ <?php esc_html_e( 'This is in plain text because it must not be stored encrypted.', 'wp-mail-smtp' ); ?>
507
+ </p>
508
+ </td>
509
+ </tr>
510
+ </table>
511
+
512
+ <p class="submit">
513
+ <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/>
514
+ </p>
515
+ </div><!-- #wpms_section_smtp -->
516
+
517
+ <?php if ( wp_mail_smtp_is_pepipost_active() ) : ?>
518
+ <div id="wpms_section_pepipost" class="wpms_section">
519
+ <h3>
520
+ <?php esc_html_e( 'Pepipost SMTP Options', 'wp-mail-smtp' ); ?>
521
+ </h3>
522
+ <p>
523
+ <?php
524
+ printf(
525
+ /* translators: %s - Pepipost registration URL. */
526
+ esc_html__( 'You need to signup on %s to get the SMTP username/password.', 'wp-mail-smtp' ),
527
+ '<a href="https://app1.pepipost.com/index.php/login/wp_mail_smtp?page=signup&utm_source=WordPress&utm_campaign=Plugins&utm_medium=wp_mail_smtp&utm_term=organic&code=WP-MAIL-SMTP" target="_blank">Pepipost</a>',
528
+ ''
529
+ );
530
+ ?>
531
+ </p>
532
+ <table class="form-table">
533
+ <tr valign="top">
534
+ <th scope="row">
535
+ <label for="pepipost_user"><?php esc_html_e( 'Username', 'wp-mail-smtp' ); ?></label>
536
+ </th>
537
+ <td>
538
+ <input name="pepipost_user" type="text" id="pepipost_user" value="<?php print( get_option( 'pepipost_user' ) ); ?>" size="40" class="code"/>
539
+ </td>
540
+ </tr>
541
+ <tr valign="top">
542
+ <th scope="row">
543
+ <label for="pepipost_pass"><?php esc_html_e( 'Password', 'wp-mail-smtp' ); ?></label>
544
+ </th>
545
+ <td>
546
+ <input name="pepipost_pass" type="text" id="pepipost_pass" value="<?php print( get_option( 'pepipost_pass' ) ); ?>" size="40" class="code"/>
547
+ </td>
548
+ </tr>
549
+ <tr valign="top">
550
+ <th scope="row">
551
+ <label for="pepipost_port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
552
+ </th>
553
+ <td>
554
+ <input name="pepipost_port" type="text" id="pepipost_port" value="<?php print( get_option( 'pepipost_port' ) ); ?>" size="6" class="regular-text"/>
555
+ </td>
556
+ </tr>
557
+ <tr valign="top">
558
+ <th scope="row">
559
+ <?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?>
560
+ </th>
561
+ <td>
562
+ <fieldset>
563
+ <legend class="screen-reader-text">
564
+ <span>
565
+ <?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?>
566
+ </span>
567
+ </legend>
568
+
569
+ <input id="pepipost_ssl_none" type="radio" name="pepipost_ssl" value="none" <?php checked( 'none', get_option( 'pepipost_ssl' ) ); ?> />
570
+ <label for="pepipost_ssl_none">
571
+ <span><?php esc_html_e( 'No encryption.', 'wp-mail-smtp' ); ?></span>
572
+ </label><br/>
573
+
574
+ <input id="pepipost_ssl_ssl" type="radio" name="pepipost_ssl" value="ssl" <?php checked( 'ssl', get_option( 'pepipost_ssl' ) ); ?> />
575
+ <label for="pepipost_ssl_ssl">
576
+ <span><?php esc_html_e( 'Use SSL encryption.', 'wp-mail-smtp' ); ?></span>
577
+ </label><br/>
578
+
579
+ <input id="pepipost_ssl_tls" type="radio" name="pepipost_ssl" value="tls" <?php checked( 'tls', get_option( 'pepipost_ssl' ) ); ?> />
580
+ <label for="pepipost_ssl_tls">
581
+ <span><?php esc_html_e( 'Use TLS encryption.', 'wp-mail-smtp' ); ?></span>
582
+ </label>
583
+ </fieldset>
584
+ </td>
585
+ </tr>
586
+ </table>
587
+
588
+ <p class="submit">
589
+ <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/>
590
+ </p>
591
+ </div><!-- #wpms_section_pepipost -->
592
+ <?php endif; ?>
593
+
594
+ <input type="hidden" name="action" value="update"/>
595
+ <input type="hidden" name="option_page" value="email">
596
+ </form>
597
+
598
+ <h3><?php esc_html_e( 'Send a Test Email', 'wp-mail-smtp' ); ?></h3>
599
+
600
+ <form method="POST" action="">
601
+ <?php wp_nonce_field( 'test-email' ); ?>
602
+
603
+ <table class="form-table">
604
+ <tr valign="top">
605
+ <th scope="row">
606
+ <label for="to"><?php esc_html_e( 'To', 'wp-mail-smtp' ); ?></label>
607
+ </th>
608
+ <td>
609
+ <input name="to" type="email" id="to" value="" size="40" class="code"/>
610
+ <p class="description"><?php esc_html_e( 'Type an email address here and then click Send Test to generate a test email.', 'wp-mail-smtp' ); ?></p>
611
+ </td>
612
+ </tr>
613
+ </table>
614
+
615
+ <p class="submit">
616
+ <input type="submit" name="wpms_action" id="wpms_action" class="button-primary" value="<?php esc_attr_e( 'Send Test', 'wp-mail-smtp' ); ?>"/>
617
+ </p>
618
+ </form>
619
+
620
+ <script type="text/javascript">
621
+ /* globals jQuery */
622
+ var wpmsOnMailerChange = function ( mailer ) {
623
+ // Hide all the mailer forms.
624
+ jQuery( '.wpms_section' ).hide();
625
+ // Show the target mailer form.
626
+ jQuery( '#wpms_section_' + mailer ).show();
627
+ };
628
+ jQuery( document ).ready( function () {
629
+ // Call wpmsOnMailerChange() on startup with the current mailer.
630
+ wpmsOnMailerChange( jQuery( 'input.wpms_mailer:checked' ).val() );
631
+
632
+ // Watch the mailer for any changes
633
+ jQuery( 'input.wpms_mailer' ).on( 'change', function ( e ) {
634
+ // Call the wpmsOnMailerChange() handler, passing the value of the newly selected mailer.
635
+ wpmsOnMailerChange( jQuery( e.target ).val() );
636
+ } );
637
+ } );
638
+ </script>
639
+
640
+ </div>
641
+ <?php
642
+ } // End of wp_mail_smtp_options_page() function definition.
643
+ endif;
644
+
645
+ if ( ! function_exists( 'wp_mail_smtp_menus' ) ) :
646
+ /**
647
+ * This function adds the required page (only 1 at the moment).
648
+ */
649
+ function wp_mail_smtp_menus() {
650
+
651
+ if ( function_exists( 'add_submenu_page' ) ) {
652
+ add_options_page( esc_html__( 'WP Mail SMTP Settings', 'wp-mail-smtp' ), esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ), 'manage_options', __FILE__, 'wp_mail_smtp_options_page' );
653
+ }
654
+ } // End of wp_mail_smtp_menus() function definition.
655
+ endif;
656
+
657
+ if ( ! function_exists( 'wp_mail_smtp_mail_from' ) ) :
658
+ /**
659
+ * This function sets the from email value.
660
+ *
661
+ * @param string $orig
662
+ *
663
+ * @return string
664
+ */
665
+ function wp_mail_smtp_mail_from( $orig ) {
666
+ /*
667
+ * This is copied from pluggable.php lines 348-354 as at revision 10150
668
+ * http://trac.wordpress.org/browser/branches/2.7/wp-includes/pluggable.php#L348.
669
+ */
670
+
671
+ // In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
672
+ $server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
673
+
674
+ // Get the site domain and get rid of www.
675
+ $sitename = strtolower( $server_name );
676
+ if ( substr( $sitename, 0, 4 ) === 'www.' ) {
677
+ $sitename = substr( $sitename, 4 );
678
+ }
679
+
680
+ $default_from = 'wordpress@' . $sitename;
681
+
682
+ /*
683
+ * End of copied code.
684
+ */
685
+
686
+ // If the from email is not the default, return it unchanged.
687
+ if ( $orig !== $default_from ) {
688
+ return $orig;
689
+ }
690
+
691
+ if (
692
+ defined( 'WPMS_ON' ) && WPMS_ON &&
693
+ defined( 'WPMS_MAIL_FROM' )
694
+ ) {
695
+ $mail_from_email = WPMS_MAIL_FROM;
696
+
697
+ if ( ! empty( $mail_from_email ) ) {
698
+ return $mail_from_email;
699
+ }
700
+ }
701
+
702
+ if ( is_email( get_option( 'mail_from' ), false ) ) {
703
+ return get_option( 'mail_from' );
704
+ }
705
+
706
+ // If in doubt, return the original value.
707
+ return $orig;
708
+ } // End of wp_mail_smtp_mail_from() function definition.
709
+ endif;
710
+
711
+ if ( ! function_exists( 'wp_mail_smtp_mail_from_name' ) ) :
712
+ /**
713
+ * This function sets the from name value.
714
+ *
715
+ * @param string $orig
716
+ *
717
+ * @return string
718
+ */
719
+ function wp_mail_smtp_mail_from_name( $orig ) {
720
+
721
+ // Only filter if the from name is the default.
722
+ if ( 'WordPress' === $orig ) {
723
+ if (
724
+ defined( 'WPMS_ON' ) && WPMS_ON &&
725
+ defined( 'WPMS_MAIL_FROM_NAME' )
726
+ ) {
727
+ $mail_from_name = WPMS_MAIL_FROM_NAME;
728
+
729
+ if ( ! empty( $mail_from_name ) ) {
730
+ return $mail_from_name;
731
+ }
732
+ }
733
+
734
+ $from_name = get_option( 'mail_from_name' );
735
+ if ( ! empty( $from_name ) && is_string( $from_name ) ) {
736
+ return $from_name;
737
+ }
738
+ }
739
+
740
+ return $orig;
741
+ }
742
+ endif;
743
+
744
+ /**
745
+ * Add a link to Settings page of a plugin on Plugins page.
746
+ *
747
+ * @param array $links
748
+ * @param string $file
749
+ *
750
+ * @return mixed
751
+ */
752
+ function wp_mail_plugin_action_links( $links, $file ) {
753
+
754
+ if ( plugin_basename( __FILE__ ) !== $file ) {
755
+ return $links;
756
+ }
757
+
758
+ $settings_link = '<a href="options-general.php?page=' . plugin_basename( __FILE__ ) . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
759
+
760
+ array_unshift( $links, $settings_link );
761
+
762
+ return $links;
763
+ }
764
+
765
+ /**
766
+ * Awesome Motive Notifications.
767
+ *
768
+ * @since 0.11
769
+ */
770
+ function wp_mail_smtp_am_notifications() {
771
+
772
+ $is_hidden = get_option( 'wp_mail_smtp_am_notifications_hidden', '' );
773
+
774
+ if ( 'true' === $is_hidden ) {
775
+ return;
776
+ }
777
+
778
+ if ( ! class_exists( 'WPMS_AM_Notification' ) ) {
779
+ require_once dirname( __FILE__ ) . '/class-wpms-am-notification.php';
780
+ }
781
+
782
+ new WPMS_AM_Notification( 'smtp', WPMS_PLUGIN_VER );
783
+ }
784
+
785
+ add_action( 'plugins_loaded', 'wp_mail_smtp_am_notifications' );
786
+
787
+ /**
788
+ * Check whether the site is using Pepipost or not.
789
+ *
790
+ * @since 0.11
791
+ *
792
+ * @return bool
793
+ */
794
+ function wp_mail_smtp_is_pepipost_active() {
795
+ return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', 'pepipost' === get_option( 'mailer' ) );
796
+ }
797
+
798
+ /**
799
+ * Check the current PHP version and display a notice if on unsupported PHP.
800
+ *
801
+ * @since 0.11
802
+ */
803
+ function wp_mail_smtp_check_php_version() {
804
+
805
+ // Display for PHP below 5.3.
806
+ if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
807
+ return;
808
+ }
809
+
810
+ // Display for admins only.
811
+ if ( ! is_super_admin() ) {
812
+ return;
813
+ }
814
+
815
+ // Display on Dashboard page only.
816
+ if ( isset( $GLOBALS['pagenow'] ) && 'index.php' !== $GLOBALS['pagenow'] ) {
817
+ return;
818
+ }
819
+
820
+ echo '<div class="notice notice-error">' .
821
+ '<p>' .
822
+ sprintf(
823
+ /* translators: %1$s - WP Mail SMTP plugin name; %2$s - opening a link tag; %3$s - closing a link tag. */
824
+ esc_html__(
825
+ 'Your site is running an outdated version of PHP that is no longer supported and may cause issues with %1$s. %2$sRead more%3$s for additional information.',
826
+ 'wpforms'
827
+ ),
828
+ '<strong>WP Mail SMTP</strong>',
829
+ '<a href="https://wpforms.com/docs/supported-php-version/" target="_blank">',
830
+ '</a>'
831
+ ) .
832
+ '</p>' .
833
+ '</div>';
834
+ }
835
+
836
+ add_action( 'admin_notices', 'wp_mail_smtp_check_php_version' );
837
+
838
+ // Add an action on phpmailer_init.
839
+ add_action( 'phpmailer_init', 'phpmailer_init_smtp' );
840
+
841
+ if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) {
842
+ // Whitelist our options.
843
+ add_filter( 'whitelist_options', 'wp_mail_smtp_whitelist_options' );
844
+ // Add the create pages options.
845
+ add_action( 'admin_menu', 'wp_mail_smtp_menus' );
846
+ // Add an activation hook for this plugin.
847
+ register_activation_hook( __FILE__, 'wp_mail_smtp_activate' );
848
+ // Adds "Settings" link to the Plugins page.
849
+ add_filter( 'plugin_action_links', 'wp_mail_plugin_action_links', 10, 2 );
850
+ }
851
+
852
+ // Add filters to replace the mail from name and email address.
853
+ add_filter( 'wp_mail_from', 'wp_mail_smtp_mail_from' );
854
+ add_filter( 'wp_mail_from_name', 'wp_mail_smtp_mail_from_name' );
855
+
856
+ load_plugin_textdomain( 'wp-mail-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );