Mailgun for WordPress - Version 1.6

Version Description

(2018-9-21): = - Refactor admin notifications - Enable Settings page for all WordPress install types - Enable Test Configuration for all WordPress install types - Test plugin up to WordPress 4.9.8.

Download this release

Release Info

Developer Mailgun
Plugin Icon 128x128 Mailgun for WordPress
Version 1.6
Comparing to
See all releases

Code changes from version 1.5.14 to 1.6

CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
  Changelog
2
  =========
3
 
4
- 1.5.14 (2018-09-11):
 
 
 
 
 
 
5
  - Force SSL-secured SMTP connections to use port 465 (SMTPS) to connect, 587 for plain and TLS
6
  - Support region endpoint switching for SMTP
7
 
1
  Changelog
2
  =========
3
 
4
+ 1.6 (2018-9-21)
5
+ - Refactor admin notifications
6
+ - Enable Settings page for all WordPress install types
7
+ - Enable Test Configuration for all WordPress install types
8
+ - Test plugin up to WordPress 4.9.8.
9
+
10
+ 1.5.14 (2018-09-11)
11
  - Force SSL-secured SMTP connections to use port 465 (SMTPS) to connect, 587 for plain and TLS
12
  - Support region endpoint switching for SMTP
13
 
includes/admin.php CHANGED
@@ -1,490 +1,484 @@
1
  <?php
2
 
3
- /*
4
- * mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun
5
- * Copyright (C) 2016 Mailgun, et al.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License along
18
- * with this program; if not, write to the Free Software Foundation, Inc.,
19
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
- */
21
-
22
- class MailgunAdmin extends Mailgun
23
- {
24
- /**
25
- * @var array Array of "safe" option defaults.
26
- */
27
- private $defaults;
28
-
29
- /**
30
- * Setup backend functionality in WordPress.
31
- *
32
- * @return void
33
- *
34
- * @since 0.1
35
- */
36
- public function __construct()
37
- {
38
- Mailgun::__construct();
39
-
40
- // Load localizations if available
41
- load_plugin_textdomain('mailgun', false, 'mailgun/languages');
42
-
43
- // Activation hook
44
- register_activation_hook($this->plugin_file, array(&$this, 'init'));
45
-
46
- if (!defined('MAILGUN_USEAPI') || !MAILGUN_USEAPI) {
47
- // Hook into admin_init and register settings and potentially register an admin_notice
48
- add_action('admin_init', array(&$this, 'admin_init'));
49
-
50
- // Activate the options page
51
- add_action('admin_menu', array(&$this, 'admin_menu'));
52
- }
53
-
54
- // Register an AJAX action for testing mail sending capabilities
55
- add_action('wp_ajax_mailgun-test', array(&$this, 'ajax_send_test'));
56
- }
57
-
58
- /**
59
- * Initialize the default options during plugin activation.
60
- *
61
- * @return void
62
- *
63
- * @since 0.1
64
- */
65
- public function init()
66
- {
67
- $sitename = strtolower($_SERVER['SERVER_NAME']);
68
- if (substr($sitename, 0, 4) == 'www.') {
69
- $sitename = substr($sitename, 4);
70
- }
71
- $regionDefault = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
72
-
73
- $this->defaults = array(
74
- 'region' => $regionDefault,
75
- 'useAPI' => '1',
76
- 'apiKey' => '',
77
- 'domain' => '',
78
- 'username' => '',
79
- 'password' => '',
80
- 'secure' => '1',
81
- 'sectype' => 'tls',
82
- 'track-clicks' => '',
83
- 'track-opens' => '',
84
- 'campaign-id' => '',
85
- 'override-from' => '0',
86
- 'tag' => $sitename,
87
- );
88
- if (!$this->options) {
89
- $this->options = $this->defaults;
90
- add_option('mailgun', $this->options);
91
- }
92
- }
93
-
94
- /**
95
- * Add the options page.
96
- *
97
- * @return void
98
- *
99
- * @since 0.1
100
- */
101
- public function admin_menu()
102
- {
103
- if (current_user_can('manage_options')) {
104
- $this->hook_suffix = add_options_page(__('Mailgun', 'mailgun'), __('Mailgun', 'mailgun'), 'manage_options', 'mailgun', array(&$this, 'options_page'));
105
- add_options_page(__('Mailgun Lists', 'mailgun'), __('Mailgun Lists', 'mailgun'), 'manage_options', 'mailgun-lists', array(&$this, 'lists_page'));
106
- add_action("admin_print_scripts-{$this->hook_suffix}", array(&$this, 'admin_js'));
107
- add_filter("plugin_action_links_{$this->plugin_basename}", array(&$this, 'filter_plugin_actions'));
108
- add_action("admin_footer-{$this->hook_suffix}", array(&$this, 'admin_footer_js'));
109
- }
110
- }
111
-
112
- /**
113
- * Enqueue javascript required for the admin settings page.
114
- *
115
- * @return void
116
- *
117
- * @since 0.1
118
- */
119
- public function admin_js()
120
- {
121
- wp_enqueue_script('jquery');
122
- }
123
-
124
- /**
125
- * Output JS to footer for enhanced admin page functionality.
126
- *
127
- * @since 0.1
128
- */
129
- public function admin_footer_js()
130
- {
131
- ?>
132
- <script type="text/javascript">
133
- /* <![CDATA[ */
134
- var mailgunApiOrNot = function() {
135
- if (jQuery("#mailgun-api").val() == 1) {
136
- jQuery(".mailgun-smtp").hide();
137
- jQuery(".mailgun-api").show();
 
 
138
  } else {
139
- jQuery(".mailgun-api").hide();
140
- jQuery(".mailgun-smtp").show();
141
  }
142
 
143
- }
144
- var formModified = false;
145
- jQuery().ready(function() {
146
- mailgunApiOrNot();
147
- jQuery('#mailgun-api').change(function() {
148
- mailgunApiOrNot();
149
- });
150
- jQuery('#mailgun-test').click(function(e) {
151
- e.preventDefault();
152
- if ( formModified ) {
153
- var doTest = confirm('<?php _e('The Mailgun plugin configuration has changed since you last saved. Do you wish to test anyway?\n\nClick "Cancel" and then "Save Changes" if you wish to save your changes.', 'mailgun'); ?>');
154
- if ( ! doTest ) {
155
- return false;
156
- }
 
 
 
 
 
 
 
 
 
157
  }
158
- jQuery(this).val('<?php _e('Testing...', 'mailgun'); ?>');
159
- jQuery("#mailgun-test-result").text('');
160
- jQuery.get(
161
- ajaxurl,
162
- {
163
- action: 'mailgun-test',
164
- _wpnonce: '<?php echo wp_create_nonce(); ?>'
165
- }
166
- )
167
- .complete(function() {
168
- jQuery("#mailgun-test").val('<?php _e('Test Configuration', 'mailgun'); ?>');
169
  })
170
- .success(function(data) {
171
- alert(
172
- 'Mailgun ' + data.method + ' Test ' + data.message
173
- + '; status "' + data.error + '"'
174
- );
175
  })
176
- .error(function() {
177
- alert('Mailgun Test <?php _e('Failure', 'mailgun'); ?>');
178
- });
179
- });
180
- jQuery("#mailgun-form").change(function() {
181
- formModified = true;
182
- });
183
- });
184
- /* ]]> */
185
- </script>
186
- <?php
187
-
188
- }
189
-
190
- /**
191
- * Output the options page.
192
- *
193
- * @return void
194
- *
195
- * @since 0.1
196
- */
197
- public function options_page()
198
- {
199
- if (!@include 'options-page.php') {
200
- printf(__('<div id="message" class="updated fade"><p>The options page for the <strong>Mailgun</strong> plugin cannot be displayed. The file <strong>%s</strong> is missing. Please reinstall the plugin.</p></div>', 'mailgun'), dirname(__FILE__).'/options-page.php');
201
- }
202
- }
203
-
204
- /**
205
- * Output the lists page.
206
- *
207
- * @return void
208
- *
209
- * @since 0.1
210
- */
211
- public function lists_page()
212
- {
213
- if (!@include 'lists-page.php') {
214
- printf(__('<div id="message" class="updated fade"><p>The lists page for the <strong>Mailgun</strong> plugin cannot be displayed. The file <strong>%s</strong> is missing. Please reinstall the plugin.</p></div>', 'mailgun'), dirname(__FILE__).'/lists-page.php');
215
- }
216
- }
217
-
218
- // /options-general.php?page=mailgun-lists
219
-
220
- /**
221
- * Wrapper function hooked into admin_init to register settings
222
- * and potentially register an admin notice if the plugin hasn't
223
- * been configured yet.
224
- *
225
- * @return void
226
- *
227
- * @since 0.1
228
- */
229
- public function admin_init()
230
- {
231
- $this->register_settings();
232
- $region = $this->get_option('region');
233
- $apiKey = $this->get_option('apiKey');
234
- $useAPI = $this->get_option('useAPI');
235
- $password = $this->get_option('password');
236
-
237
- add_action('admin_notices', array(&$this, 'admin_notices'));
238
- }
239
-
240
- /**
241
- * Whitelist the mailgun options.
242
- *
243
- * @return void
244
- *
245
- * @since 0.1
246
- */
247
- public function register_settings()
248
- {
249
- register_setting('mailgun', 'mailgun', array(&$this, 'validation'));
250
- }
251
-
252
- /**
253
- * Data validation callback function for options.
254
- *
255
- * @param array $options An array of options posted from the options page
256
- *
257
- * @return array
258
- *
259
- * @since 0.1
260
- */
261
- public function validation($options)
262
- {
263
- $apiKey = trim($options['apiKey']);
264
- $username = trim($options['username']);
265
- if (!empty($apiKey)) {
266
- $pos = strpos($apiKey, 'api:');
267
- if ($pos !== false && $pos == 0) {
268
- $apiKey = substr($apiKey, 4);
269
- }
270
-
271
- if (1 === preg_match('(\w{32}-\w{8}-\w{8})', $apiKey)) {
272
- $options['apiKey'] = $apiKey;
273
- } else {
274
- $pos = strpos($apiKey, 'key-');
275
- if ($pos === false || $pos > 4) {
276
- $apiKey = "key-{$apiKey}";
277
- }
278
 
279
- $options['apiKey'] = $apiKey;
280
- }
281
- }
282
-
283
- if (!empty($username)) {
284
- $username = preg_replace('/@.+$/', '', $username);
285
- $options['username'] = $username;
286
- }
287
-
288
- foreach ($options as $key => $value) {
289
- $options[$key] = trim($value);
290
- }
291
-
292
- if (empty($options['override-from'])) {
293
- $options['override-from'] = $this->defaults['override-from'];
294
- }
295
-
296
- if (empty($options['sectype'])) {
297
- $options['sectype'] = $this->defaults['sectype'];
298
- }
299
- // alternatively:
300
- // foreach ($defaults as $key => $value) {
301
- // if (empty($options[$key])) {
302
- // $options[$key] = $value;
303
- // }
304
- // }
305
-
306
- $this->options = $options;
307
-
308
- return $options;
309
- }
310
-
311
- /**
312
- * Function to output an admin notice when the plugin has not
313
- * been configured yet.
314
- *
315
- * @return void
316
- *
317
- * @since 0.1
318
- */
319
- public function admin_notices()
320
- {
321
- $screen = get_current_screen();
322
- if (!current_user_can('manage_options') || $screen->id == $this->hook_suffix
323
- ) {
324
- return;
325
- }
326
-
327
- if ((!$this->get_option('apiKey') && $this->get_option('useAPI') === '1')
328
- || (!$this->get_option('password') && $this->get_option('useAPI') === '0')
329
- ) {
330
- ?>
331
- <div id='mailgun-warning' class='notice notice-warning fade'>
332
- <p>
333
- <strong>
334
- <?php _e('Mailgun is almost ready. ', 'mailgun'); ?>
335
- </strong>
336
- <?php printf(__('You must <a href="%1$s">configure Mailgun</a> for it to work.', 'mailgun'), menu_page_url('mailgun', false)); ?>
337
- </p>
338
- </div>
339
- <?php
340
 
341
- }
342
-
343
- if ($this->get_option('override-from') === '1'
344
- && (!$this->get_option('from-name')
345
- || !$this->get_option('from-address'))
346
- ) {
347
- ?>
348
- <div id='mailgun-warning' class='notice notice-warning fade'>
349
- <p>
350
- <strong>
351
- <?php _e('Mailgun is almost ready. ', 'mailgun'); ?>
352
- </strong>
353
- <?php printf(__('"Override From" option requires that "From Name" and "From Address" be set to work properly! <a href="%1$s">Configure Mailgun now</a>.', 'mailgun'), menu_page_url('mailgun', false)); ?>
354
- </p>
355
- </div>
356
- <?php
357
 
358
- }
359
-
360
- if (!$this->get_option('region') && $this->get_option('useAPI') === '1') {
361
- ?>
362
- <div id='mailgun-warning' class='notice notice-warning fade'>
363
- <p>
364
- <strong>
365
- <?php _e('Mailgun now supports multiple regions! ', 'mailgun'); ?>
366
- </strong>
367
- <?php printf(__('By default, we will use the US region, but we now have an EU region generally available. You can change regions <a href="%1$s">here</a>.', 'mailgun'), menu_page_url('mailgun', false)); ?>
368
- </p>
369
- </div>
370
- <?php
371
- }
372
- }
373
-
374
- /**
375
- * Add a settings link to the plugin actions.
376
- *
377
- * @param array $links Array of the plugin action links
378
- *
379
- * @return array
380
- *
381
- * @since 0.1
382
- */
383
- public function filter_plugin_actions($links)
384
- {
385
- $settings_link = '<a href="'.menu_page_url('mailgun', false).'">'.__('Settings', 'mailgun').'</a>';
386
- array_unshift($links, $settings_link);
387
-
388
- return $links;
389
- }
390
-
391
- /**
392
- * AJAX callback function to test mail sending functionality.
393
- *
394
- * @return string
395
- *
396
- * @since 0.1
397
- */
398
- public function ajax_send_test()
399
- {
400
- nocache_headers();
401
- header('Content-Type: application/json');
402
-
403
- if (!current_user_can('manage_options') || !wp_verify_nonce($_GET['_wpnonce'])) {
404
- die(
405
- json_encode(
406
- array(
407
- 'message' => __('Unauthorized', 'mailgun'),
408
- 'method' => null,
409
- 'error' => __('Unauthorized', 'mailgun'),
410
- )
411
- )
412
- );
413
- }
414
-
415
- $getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
416
- $useAPI = (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI) ? MAILGUN_USEAPI : $this->get_option('useAPI');
417
- $secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
418
- $sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
419
-
420
- if ((bool) !$getRegion) {
421
- mg_api_last_error(__("Region has not been selected", "mailgun"));
422
- } else {
423
-
424
- if ($getRegion === 'us') {
425
- $region = __("U.S./North America", "mailgun");
426
- }
427
 
428
- if ($getRegion === "eu") {
429
- $region = __("Europe", "mailgun");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
  }
 
 
 
 
 
 
 
 
 
 
 
 
431
  }
432
 
433
- if ((bool) $useAPI) {
434
- $method = __('HTTP API', 'mailgun');
435
- } else {
436
- $method = ((bool) $secure) ? __('Secure SMTP', 'mailgun') : __('Insecure SMTP', 'mailgun');
437
- if ((bool) $secure) {
438
- $method = $method . sprintf(__(' via %s', 'mailgun'), $sectype);
439
- }
440
- }
441
-
442
- $admin_email = get_option('admin_email');
443
- $result = wp_mail(
444
- $admin_email,
445
- __('Mailgun WordPress Plugin Test', 'mailgun'),
446
- sprintf(__("This is a test email generated by the Mailgun WordPress plugin.\n\nIf you have received this message, the requested test has succeeded.\n\nThe sending region is set to %s.\n\nThe method used to send this email was: %s.", 'mailgun'), $region, $method),
447
- array('Content-Type: text/plain')
448
- );
449
-
450
- if ((bool) $useAPI) {
451
- if (!function_exists('mg_api_last_error')) {
452
- if (!include dirname(__FILE__).'/wp-mail-api.php') {
453
- self::deactivate_and_die(dirname(__FILE__).'/wp-mail-api.php');
454
- }
455
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
 
457
- $error_msg = mg_api_last_error();
458
- } else {
459
- if (!function_exists('mg_smtp_last_error')) {
460
- if (!include dirname(__FILE__).'/wp-mail-smtp.php') {
461
- self::deactivate_and_die(dirname(__FILE__).'/wp-mail-smtp.php');
462
- }
463
- }
464
-
465
- $error_msg = mg_smtp_last_error();
466
- }
467
-
468
- if ($result) {
469
- die(
470
- json_encode(
471
- array(
472
- 'message' => __('Success', 'mailgun'),
473
- 'method' => $method,
474
- 'error' => __('Success', 'mailgun'),
475
- )
476
- )
477
- );
478
- } else {
479
- die(
480
- json_encode(
481
- array(
482
- 'message' => __('Failure', 'mailgun'),
483
- 'method' => $method,
484
- 'error' => $error_msg,
485
- )
486
- )
487
- );
488
- }
489
- }
490
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ /*
4
+ * mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun
5
+ * Copyright (C) 2016 Mailgun, et al.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License along
18
+ * with this program; if not, write to the Free Software Foundation, Inc.,
19
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ */
21
+
22
+ class MailgunAdmin extends Mailgun
23
+ {
24
+ /**
25
+ * @var array Array of "safe" option defaults.
26
+ */
27
+ private $defaults;
28
+
29
+ /**
30
+ * Setup backend functionality in WordPress.
31
+ *
32
+ * @return void
33
+ *
34
+ * @since 0.1
35
+ */
36
+ public function __construct()
37
+ {
38
+ Mailgun::__construct();
39
+
40
+ // Load localizations if available
41
+ load_plugin_textdomain('mailgun', false, 'mailgun/languages');
42
+
43
+ // Activation hook
44
+ register_activation_hook($this->plugin_file, array(&$this, 'init'));
45
+
46
+ // Hook into admin_init and register settings and potentially register an admin_notice
47
+ add_action('admin_init', array(&$this, 'admin_init'));
48
+
49
+ // Activate the options page
50
+ add_action('admin_menu', array(&$this, 'admin_menu'));
51
+
52
+ // Register an AJAX action for testing mail sending capabilities
53
+ add_action('wp_ajax_mailgun-test', array(&$this, 'ajax_send_test'));
54
+ }
55
+
56
+ /**
57
+ * Initialize the default options during plugin activation.
58
+ *
59
+ * @return void
60
+ *
61
+ * @since 0.1
62
+ */
63
+ public function init()
64
+ {
65
+ $sitename = strtolower($_SERVER[ 'SERVER_NAME' ]);
66
+ if (substr($sitename, 0, 4) == 'www.'):
67
+ $sitename = substr($sitename, 4);
68
+ endif;
69
+
70
+ $region = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
71
+ $regionDefault = $region ?: 'us';
72
+
73
+ $this->defaults = array(
74
+ 'region' => $regionDefault,
75
+ 'useAPI' => '1',
76
+ 'apiKey' => '',
77
+ 'domain' => '',
78
+ 'username' => '',
79
+ 'password' => '',
80
+ 'secure' => '1',
81
+ 'sectype' => 'tls',
82
+ 'track-clicks' => '',
83
+ 'track-opens' => '',
84
+ 'campaign-id' => '',
85
+ 'override-from' => '0',
86
+ 'tag' => $sitename,
87
+ );
88
+ if (!$this->options):
89
+ $this->options = $this->defaults;
90
+ add_option('mailgun', $this->options);
91
+ endif;
92
+ }
93
+
94
+ /**
95
+ * Add the options page.
96
+ *
97
+ * @return void
98
+ *
99
+ * @since 0.1
100
+ */
101
+ public function admin_menu()
102
+ {
103
+ if (current_user_can('manage_options')):
104
+ $this->hook_suffix = add_options_page(__('Mailgun', 'mailgun'), __('Mailgun', 'mailgun'),
105
+ 'manage_options', 'mailgun', array(&$this, 'options_page'));
106
+ add_options_page(__('Mailgun Lists', 'mailgun'), __('Mailgun Lists', 'mailgun'), 'manage_options',
107
+ 'mailgun-lists', array(&$this, 'lists_page'));
108
+ add_action("admin_print_scripts-{$this->hook_suffix}", array(&$this, 'admin_js'));
109
+ add_filter("plugin_action_links_{$this->plugin_basename}", array(&$this, 'filter_plugin_actions'));
110
+ add_action("admin_footer-{$this->hook_suffix}", array(&$this, 'admin_footer_js'));
111
+ endif;
112
+ }
113
+
114
+ /**
115
+ * Enqueue javascript required for the admin settings page.
116
+ *
117
+ * @return void
118
+ *
119
+ * @since 0.1
120
+ */
121
+ public function admin_js()
122
+ {
123
+ wp_enqueue_script('jquery');
124
+ }
125
+
126
+ /**
127
+ * Output JS to footer for enhanced admin page functionality.
128
+ *
129
+ * @since 0.1
130
+ */
131
+ public function admin_footer_js()
132
+ {
133
+ ?>
134
+ <script type="text/javascript">
135
+ /* <![CDATA[ */
136
+ var mailgunApiOrNot = function () {
137
+ if (jQuery('#mailgun-api').val() == 1) {
138
+ jQuery('.mailgun-smtp').hide()
139
+ jQuery('.mailgun-api').show()
140
  } else {
141
+ jQuery('.mailgun-api').hide()
142
+ jQuery('.mailgun-smtp').show()
143
  }
144
 
145
+ }
146
+ var formModified = false
147
+ jQuery().ready(function () {
148
+ mailgunApiOrNot()
149
+ jQuery('#mailgun-api').change(function () {
150
+ mailgunApiOrNot()
151
+ })
152
+ jQuery('#mailgun-test').click(function (e) {
153
+ e.preventDefault()
154
+ if (formModified) {
155
+ var doTest = confirm('<?php _e('The Mailgun plugin configuration has changed since you last saved. Do you wish to test anyway?\n\nClick "Cancel" and then "Save Changes" if you wish to save your changes.',
156
+ 'mailgun'); ?>')
157
+ if (!doTest) {
158
+ return false
159
+ }
160
+ }
161
+ jQuery(this).val('<?php _e('Testing...', 'mailgun'); ?>')
162
+ jQuery('#mailgun-test-result').text('')
163
+ jQuery.get(
164
+ ajaxurl,
165
+ {
166
+ action: 'mailgun-test',
167
+ _wpnonce: '<?php echo wp_create_nonce(); ?>'
168
  }
169
+ )
170
+ .complete(function () {
171
+ jQuery('#mailgun-test').val('<?php _e('Test Configuration', 'mailgun'); ?>')
 
 
 
 
 
 
 
 
172
  })
173
+ .success(function (data) {
174
+ alert(
175
+ 'Mailgun ' + data.method + ' Test ' + data.message
176
+ + '; status "' + data.error + '"'
177
+ )
178
  })
179
+ .error(function () {
180
+ alert('Mailgun Test <?php _e('Failure', 'mailgun'); ?>')
181
+ })
182
+ })
183
+ jQuery('#mailgun-form').change(function () {
184
+ formModified = true
185
+ })
186
+ })
187
+ /* ]]> */
188
+ </script>
189
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
+ /**
194
+ * Output the options page.
195
+ *
196
+ * @return void
197
+ *
198
+ * @since 0.1
199
+ */
200
+ public function options_page()
201
+ {
202
+ if (!@include 'options-page.php'):
203
+ printf(__('<div id="message" class="updated fade"><p>The options page for the <strong>Mailgun</strong> plugin cannot be displayed. The file <strong>%s</strong> is missing. Please reinstall the plugin.</p></div>',
204
+ 'mailgun'), dirname(__FILE__) . '/options-page.php');
205
+ endif;
206
+ }
 
 
207
 
208
+ /**
209
+ * Output the lists page.
210
+ *
211
+ * @return void
212
+ *
213
+ * @since 0.1
214
+ */
215
+ public function lists_page()
216
+ {
217
+ if (!@include 'lists-page.php'):
218
+ printf(__('<div id="message" class="updated fade"><p>The lists page for the <strong>Mailgun</strong> plugin cannot be displayed. The file <strong>%s</strong> is missing. Please reinstall the plugin.</p></div>',
219
+ 'mailgun'), dirname(__FILE__) . '/lists-page.php');
220
+ endif;
221
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
+ /**
224
+ * Wrapper function hooked into admin_init to register settings
225
+ * and potentially register an admin notice if the plugin hasn't
226
+ * been configured yet.
227
+ *
228
+ * @return void
229
+ *
230
+ * @since 0.1
231
+ */
232
+ public function admin_init()
233
+ {
234
+ $this->register_settings();
235
+ $region = $this->get_option('region');
236
+ $apiKey = $this->get_option('apiKey');
237
+ $useAPI = $this->get_option('useAPI');
238
+ $password = $this->get_option('password');
239
+
240
+ add_action('admin_notices', array(&$this, 'admin_notices'));
241
+ }
242
+
243
+ /**
244
+ * Whitelist the mailgun options.
245
+ *
246
+ * @return void
247
+ *
248
+ * @since 0.1
249
+ */
250
+ public function register_settings()
251
+ {
252
+ register_setting('mailgun', 'mailgun', array(&$this, 'validation'));
253
+ }
254
+
255
+ /**
256
+ * Data validation callback function for options.
257
+ *
258
+ * @param array $options An array of options posted from the options page
259
+ *
260
+ * @return array
261
+ *
262
+ * @since 0.1
263
+ */
264
+ public function validation($options)
265
+ {
266
+ $apiKey = trim($options[ 'apiKey' ]);
267
+ $username = trim($options[ 'username' ]);
268
+ if (!empty($apiKey)):
269
+ $pos = strpos($apiKey, 'api:');
270
+ if ($pos !== false && $pos == 0):
271
+ $apiKey = substr($apiKey, 4);
272
+ endif;
273
+
274
+ if (1 === preg_match('(\w{32}-\w{8}-\w{8})', $apiKey)):
275
+ $options[ 'apiKey' ] = $apiKey;
276
+ else:
277
+ $pos = strpos($apiKey, 'key-');
278
+ if ($pos === false || $pos > 4):
279
+ $apiKey = "key-{$apiKey}";
280
+ endif;
281
+
282
+ $options[ 'apiKey' ] = $apiKey;
283
+ endif;
284
+ endif;
285
+
286
+ if (!empty($username)):
287
+ $username = preg_replace('/@.+$/', '', $username);
288
+ $options[ 'username' ] = $username;
289
+ endif;
290
+
291
+ foreach ($options as $key => $value) {
292
+ $options[ $key ] = trim($value);
293
  }
294
+
295
+ if (empty($options[ 'override-from' ])):
296
+ $options[ 'override-from' ] = $this->defaults[ 'override-from' ];
297
+ endif;
298
+
299
+ if (empty($options[ 'sectype' ])):
300
+ $options[ 'sectype' ] = $this->defaults[ 'sectype' ];
301
+ endif;
302
+
303
+ $this->options = $options;
304
+
305
+ return $options;
306
  }
307
 
308
+ /**
309
+ * Function to output an admin notice
310
+ * when plugin settings or constants need to be configured
311
+ *
312
+ * @return void
313
+ *
314
+ * @since 0.1
315
+ */
316
+ public function admin_notices()
317
+ {
318
+ $screen = get_current_screen();
319
+ if (!current_user_can('manage_options') || $screen->id == $this->hook_suffix):
320
+ return;
321
+ endif;
322
+
323
+ if ((defined('WP_ALLOW_MULTISITE') && !defined('MAILGUN_REGION'))
324
+ || (!$this->get_option('apiKey') && $this->get_option('useAPI') === '1')
325
+ || (!$this->get_option('password') && $this->get_option('useAPI') === '0')
326
+ || (!$this->get_option('region') && $this->get_option('useAPI') === '1')
327
+ ):
328
+ ?>
329
+ <div id='mailgun-warning' class='notice notice-warning is-dismissible'>
330
+ <p>
331
+ <strong>
332
+ <?php _e('Mailgun is almost ready. ', 'mailgun'); ?>
333
+ </strong>
334
+ <?php
335
+ printf(
336
+ __('With the latest update, Mailgun now supports multiple regions! By default, we will use the U.S. region, but we now have an EU region available. You can configure your Mailgun settings <a href="%1$s">here</a> or in your wp-config.php.',
337
+ 'mailgun'),
338
+ menu_page_url('mailgun', false)
339
+ );
340
+ ?>
341
+ </p>
342
+ </div>
343
+ <?php
344
+ endif;
345
+
346
+ if ($this->get_option('override-from') === '1' &&
347
+ (!$this->get_option('from-name') || !$this->get_option('from-address'))
348
+ ):
349
+ ?>
350
+ <div id='mailgun-warning' class='notice notice-warning is-dismissible'>
351
+ <p>
352
+ <strong>
353
+ <?php _e('Mailgun is almost ready. ', 'mailgun'); ?>
354
+ </strong>
355
+ <?php
356
+ printf(
357
+ __('"Override From" option requires that "From Name" and "From Address" be set to work properly! <a href="%1$s">Configure Mailgun now</a>.',
358
+ 'mailgun'),
359
+ menu_page_url('mailgun', false)
360
+ );
361
+ ?>
362
+ </p>
363
+ </div>
364
+ <?php
365
+ endif;
366
+ }
367
 
368
+ /**
369
+ * Add a settings link to the plugin actions.
370
+ *
371
+ * @param array $links Array of the plugin action links
372
+ *
373
+ * @return array
374
+ *
375
+ * @since 0.1
376
+ */
377
+ public function filter_plugin_actions($links)
378
+ {
379
+ $settings_link = '<a href="' . menu_page_url('mailgun', false) . '">' . __('Settings', 'mailgun') . '</a>';
380
+ array_unshift($links, $settings_link);
381
+
382
+ return $links;
383
+ }
384
+
385
+ /**
386
+ * AJAX callback function to test mail sending functionality.
387
+ *
388
+ * @return string
389
+ *
390
+ * @since 0.1
391
+ */
392
+ public function ajax_send_test()
393
+ {
394
+ nocache_headers();
395
+ header('Content-Type: application/json');
396
+
397
+ if (!current_user_can('manage_options') || !wp_verify_nonce($_GET[ '_wpnonce' ])):
398
+ die(
399
+ json_encode(
400
+ array(
401
+ 'message' => __('Unauthorized', 'mailgun'),
402
+ 'method' => null,
403
+ 'error' => __('Unauthorized', 'mailgun'),
404
+ )
405
+ )
406
+ );
407
+ endif;
408
+
409
+ $getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
410
+ $useAPI = (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI) ? MAILGUN_USEAPI : $this->get_option('useAPI');
411
+ $secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
412
+ $sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
413
+
414
+ if ((bool) !$getRegion):
415
+ mg_api_last_error(__("Region has not been selected", "mailgun"));
416
+ else:
417
+ if ($getRegion === 'us'):
418
+ $region = __("U.S./North America", "mailgun");
419
+ endif;
420
+
421
+ if ($getRegion === "eu"):
422
+ $region = __("Europe", "mailgun");
423
+ endif;
424
+ endif;
425
+
426
+ if ((bool) $useAPI):
427
+ $method = __('HTTP API', 'mailgun');
428
+ else:
429
+ $method = ((bool) $secure) ? __('Secure SMTP', 'mailgun') : __('Insecure SMTP', 'mailgun');
430
+ if ((bool) $secure):
431
+ $method = $method . sprintf(__(' via %s', 'mailgun'), $sectype);
432
+ endif;
433
+ endif;
434
+
435
+ $admin_email = get_option('admin_email');
436
+ $result = wp_mail(
437
+ $admin_email,
438
+ __('Mailgun WordPress Plugin Test', 'mailgun'),
439
+ sprintf(__("This is a test email generated by the Mailgun WordPress plugin.\n\nIf you have received this message, the requested test has succeeded.\n\nThe sending region is set to %s.\n\nThe method used to send this email was: %s.",
440
+ 'mailgun'), $region, $method),
441
+ array('Content-Type: text/plain')
442
+ );
443
+
444
+ if ((bool) $useAPI):
445
+ if (!function_exists('mg_api_last_error')):
446
+ if (!include dirname(__FILE__) . '/wp-mail-api.php'):
447
+ self::deactivate_and_die(dirname(__FILE__) . '/wp-mail-api.php');
448
+ endif;
449
+ endif;
450
+
451
+ $error_msg = mg_api_last_error();
452
+ else:
453
+ if (!function_exists('mg_smtp_last_error')):
454
+ if (!include dirname(__FILE__) . '/wp-mail-smtp.php'):
455
+ self::deactivate_and_die(dirname(__FILE__) . '/wp-mail-smtp.php');
456
+ endif;
457
+ endif;
458
+
459
+ $error_msg = mg_smtp_last_error();
460
+ endif;
461
+
462
+ if ($result):
463
+ die(
464
+ json_encode(
465
+ array(
466
+ 'message' => __('Success', 'mailgun'),
467
+ 'method' => $method,
468
+ 'error' => __('Success', 'mailgun'),
469
+ )
470
+ )
471
+ );
472
+ else:
473
+ die(
474
+ json_encode(
475
+ array(
476
+ 'message' => __('Failure', 'mailgun'),
477
+ 'method' => $method,
478
+ 'error' => $error_msg,
479
+ )
480
+ )
481
+ );
482
+ endif;
483
+ }
484
+ }
includes/lists-page.php CHANGED
@@ -23,15 +23,15 @@ global $mailgun;
23
 
24
  // check mailgun domain & api key
25
  $missing_error = '';
26
- $api_key = $this->get_option('apiKey');
27
- $mailgun_domain = $this->get_option('domain');
28
- if ($api_key != '') {
29
- if ($mailgun_domain == '') {
30
  $missing_error = '<strong style="color:red;">Missing or invalid Mailgun Domain</strong>. ';
31
- }
32
- } else {
33
  $missing_error = '<strong style="color:red;">Missing or invalid API Key</strong>. ';
34
- }
35
 
36
  // import available lists
37
  $lists_arr = $mailgun->get_lists();
@@ -85,8 +85,8 @@ $lists_arr = $mailgun->get_lists();
85
  <h3>Multi-list subscription</h3>
86
  <p>
87
  <?php _e('To allow users to subscribe to multiple lists on a single form, comma-separate the Mailgun list ids.', 'mailgun'); ?></p>
88
- <p class="description">
89
- <?php _e('<strong>Example:</strong> [mailgun id="list1@mydomain.com,list2@mydomain.com"]'); ?>
90
  </p>
91
 
92
  <?php endif; ?>
23
 
24
  // check mailgun domain & api key
25
  $missing_error = '';
26
+ $api_key = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $this->get_option('apiKey');
27
+ $mailgun_domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $this->get_option('domain');
28
+ if ($api_key != ''):
29
+ if ($mailgun_domain == ''):
30
  $missing_error = '<strong style="color:red;">Missing or invalid Mailgun Domain</strong>. ';
31
+ endif;
32
+ else:
33
  $missing_error = '<strong style="color:red;">Missing or invalid API Key</strong>. ';
34
+ endif;
35
 
36
  // import available lists
37
  $lists_arr = $mailgun->get_lists();
85
  <h3>Multi-list subscription</h3>
86
  <p>
87
  <?php _e('To allow users to subscribe to multiple lists on a single form, comma-separate the Mailgun list ids.', 'mailgun'); ?></p>
88
+ <p>
89
+ <?php _e('<strong>Example:</strong> <code>[mailgun id="list1@mydomain.com,list2@mydomain.com"]</code>'); ?>
90
  </p>
91
 
92
  <?php endif; ?>
includes/options-page.php CHANGED
@@ -1,228 +1,435 @@
1
  <?php
2
 
3
- /*
4
- * mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun
5
- * Copyright (C) 2016 Mailgun, et al.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License along
18
- * with this program; if not, write to the Free Software Foundation, Inc.,
19
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
- */
21
 
22
  ?>
23
- <div class="wrap">
24
- <div id="icon-options-general" class="icon32"><br /></div>
25
- <span class="alignright"><a target="_blank" href="http://www.mailgun.com/"><img src="https://assets.mailgun.com/img/mailgun.svg" alt="Mailgun" style="width: 10em;"/></a></span>
26
- <h2><?php _e('Mailgun', 'mailgun'); ?></h2>
27
- <p>A <a target="_blank" href="http://www.mailgun.com/">Mailgun</a> account is required to use this plugin and the Mailgun service.</p>
28
- <p>If you need to register for an account, you can do so at <a target="_blank" href="http://www.mailgun.com/">http://www.mailgun.com/</a>.</p>
29
- <form id="mailgun-form" action="options.php" method="post">
30
- <?php settings_fields('mailgun'); ?>
31
- <h3><?php _e('Configuration', 'mailgun'); ?></h3>
32
- <table class="form-table">
33
- <tr valign="top">
34
- <th scope="row">
35
- <?php
36
- $config_region = (defined('MAILGUN_REGION') && MAILGUN_REGION);
37
- if ($config_region):
38
- _e('Your Region is', 'mailgun');
39
- else:
40
- _e('Select Your Region', 'mailgun');
41
- endif;
42
- ?>
43
- </th>
44
- <td>
45
- <?php
46
- if ($config_region):
47
- $region = (MAILGUN_REGION === 'us') ? __('U.S./North America', 'mailgun') : __('Europe', 'mailgun');
48
- ?>
49
- <input readonly="readonly" id="mailgun-region" type="text" name="mailgun[region]" value="<?php echo $region ?>">
50
- <p class="description"><?php _e('You have set the region in your wp-config.php file. Email will be sent from this region, and your customer data will be stored in this region.', 'mailgun') ?></p>
51
- <?php else: ?>
52
- <select id="mailgun-region" name="mailgun[region]">
53
- <option value="us"<?php selected('us', $this->get_option('region')); ?>><?php _e('U.S./North America', 'mailgun') ?></option>
54
- <option value="eu"<?php selected('eu', $this->get_option('region')); ?>><?php _e('Europe', 'mailgun') ?></option>
55
- </select>
56
- <p class="description"><?php _e('Choose a region - U.S./North America or Europe - from which to send email, and to store your customer data. Please note that your sending domain must be set up in whichever region you choose.', 'mailgun') ?></p>
57
- <?php endif; ?>
58
- </td>
59
- </tr>
60
- <tr valign="top">
61
- <th scope="row">
62
- <?php _e('Use HTTP API', 'mailgun'); ?>
63
- </th>
64
- <td>
65
- <select id="mailgun-api" name="mailgun[useAPI]">
66
- <option value="1"<?php selected('1', $this->get_option('useAPI')); ?>><?php _e('Yes', 'mailgun'); ?></option>
67
- <option value="0"<?php selected('0', $this->get_option('useAPI')); ?>><?php _e('No', 'mailgun'); ?></option>
68
- </select>
69
- <p class="description"><?php _e('Set this to "No" if your server cannot make outbound HTTP connections or if emails are not being delivered. "No" will cause this plugin to use SMTP. Default "Yes".', 'mailgun'); ?></p>
70
- </td>
71
- </tr>
72
- <tr valign="top">
73
- <th scope="row">
74
- <?php _e('Mailgun Domain Name', 'mailgun'); ?>
75
- </th>
76
- <td>
77
- <input type="text" class="regular-text" name="mailgun[domain]" value="<?php esc_attr_e($this->get_option('domain')); ?>" placeholder="samples.mailgun.org" />
78
- <p class="description"><?php _e('Your Mailgun Domain Name.', 'mailgun'); ?></p>
79
- </td>
80
- </tr>
81
- <tr valign="top" class="mailgun-api">
82
- <th scope="row">
83
- <?php _e('API Key', 'mailgun'); ?>
84
- </th>
85
- <td>
86
- <input type="text" class="regular-text" name="mailgun[apiKey]" value="<?php esc_attr_e($this->get_option('apiKey')); ?>" placeholder="key-3ax6xnjp29jd6fds4gc373sgvjxteol0" />
87
- <p class="description"><?php _e('Your Mailgun API key. Only valid for use with the API.', 'mailgun'); ?></p>
88
- </td>
89
- </tr>
90
- <tr valign="top" class="mailgun-smtp">
91
- <th scope="row">
92
- <?php _e('Username', 'mailgun'); ?>
93
- </th>
94
- <td>
95
- <input type="text" class="regular-text" name="mailgun[username]" value="<?php esc_attr_e($this->get_option('username')); ?>" placeholder="postmaster" />
96
- <p class="description"><?php _e('Your Mailgun SMTP username. Only valid for use with SMTP.', 'mailgun'); ?></p>
97
- </td>
98
- </tr>
99
- <tr valign="top" class="mailgun-smtp">
100
- <th scope="row">
101
- <?php _e('Password', 'mailgun'); ?>
102
- </th>
103
- <td>
104
- <input type="text" class="regular-text" name="mailgun[password]" value="<?php esc_attr_e($this->get_option('password')); ?>" placeholder="my-password" />
105
- <p class="description"><?php _e('Your Mailgun SMTP password that goes with the above username. Only valid for use with SMTP.', 'mailgun'); ?></p>
106
- </td>
107
- </tr>
108
- <tr valign="top" class="mailgun-smtp">
109
- <th scope="row">
110
- <?php _e('Use Secure SMTP', 'mailgun'); ?>
111
- </th>
112
- <td>
113
- <select name="mailgun[secure]">
114
- <option value="1"<?php selected('1', $this->get_option('secure')); ?>><?php _e('Yes', 'mailgun'); ?></option>
115
- <option value="0"<?php selected('0', $this->get_option('secure')); ?>><?php _e('No', 'mailgun'); ?></option>
116
- </select>
117
- <p class="description"><?php _e('Set this to "No" if your server cannot establish SSL SMTP connections or if emails are not being delivered. If you set this to "No" your password will be sent in plain text. Only valid for use with SMTP. Default "Yes".', 'mailgun'); ?></p>
118
- </td>
119
- </tr>
120
- <tr valign="top" class="mailgun-smtp">
121
- <th scope="row">
122
- <?php _e('Security Type', 'mailgun'); ?>
123
- </th>
124
- <td>
125
- <select name="mailgun[sectype]">
126
- <option value="ssl"<?php selected('ssl', $this->get_option('sectype')); ?>>SSL</option>
127
- <option value="tls"<?php selected('tls', $this->get_option('sectype')); ?>>TLS</option>
128
- </select>
129
- <p class="description"><php _e('Leave this at "TLS" unless mail sending fails. This option only matters for Secure SMTP. Default "TLS".', 'mailgun'); ?></p>
130
- </td>
131
- </tr>
132
- <tr valign="top">
133
- <th scope="row">
134
- <?php _e('Click Tracking', 'mailgun'); ?>
135
- </th>
136
- <td>
137
- <select name="mailgun[track-clicks]">
138
- <option value="htmlonly"<?php selected('htmlonly', $this->get_option('track-clicks')); ?>><?php _e('HTML Only', 'mailgun'); ?></option>
139
- <option value="yes"<?php selected('yes', $this->get_option('track-clicks')); ?>><?php _e('Yes', 'mailgun'); ?></option>
140
- <option value="no"<?php selected('no', $this->get_option('track-clicks')); ?>><?php _e('No', 'mailgun'); ?></option>
141
- </select>
142
- <p class="description"><?php _e('If enabled, Mailgun will and track links.', 'mailgun'); ?> <a href="http://documentation.mailgun.com/user_manual.html#tracking-clicks" target="_blank">Click Tracking Documentation</a></p>
143
- </td>
144
- </tr>
145
- <tr valign="top">
146
- <th scope="row">
147
- <?php _e('Open Tracking', 'mailgun'); ?>
148
- </th>
149
- <td>
150
- <select name="mailgun[track-opens]">
151
- <option value="1"<?php selected('1', $this->get_option('track-opens')); ?>><?php _e('Yes', 'mailgun'); ?></option>
152
- <option value="0"<?php selected('0', $this->get_option('track-opens')); ?>><?php _e('No', 'mailgun'); ?></option>
153
- </select>
154
- <p class="description"><?php _e('If enabled, HTML messages will include an open tracking beacon.', 'mailgun'); ?> <a href="http://documentation.mailgun.com/user_manual.html#tracking-opens" target="_blank">Open Tracking Documentation</a></p>
155
- </td>
156
- </tr>
157
- <tr valign="top">
158
- <th scope="row">
159
- <?php _e('From Address', 'mailgun'); ?>
160
- </th>
161
- <td>
162
- <input type="text" class="regular-text" name="mailgun[from-address]" value="<?php esc_attr_e($this->get_option('from-address')); ?>" placeholder="wordpress@mydomain.com" />
163
- <p class="description"><?php _e('The <address@mydomain.com> part of the sender information (<code>"Excited User &lt;user@samples.mailgun.org&gt;"</code>). This address will appear as the `From` address on sent mail. <strong>It is recommended that the @mydomain portion matches your Mailgun sending domain.</strong>', 'mailgun'); ?></p>
164
- </td>
165
- </tr>
166
- <tr valign="top">
167
- <th scope="row">
168
- <?php _e('From Name', 'mailgun'); ?>
169
- </th>
170
- <td>
171
- <input type="text" class="regular-text" name="mailgun[from-name]" value="<?php esc_attr_e($this->get_option('from-name')); ?>" placeholder="WordPress" />
172
- <p class="description"><?php _e('The "User Name" part of the sender information (<code>"Excited User &lt;user@samples.mailgun.org&gt;"</code>).', 'mailgun'); ?></p>
173
- </td>
174
- </tr>
175
- <tr valign="top">
176
- <th scope="row">
177
- <?php _e('Override "From" Details', 'mailgun'); ?>
178
- </th>
179
- <td>
180
- <select name="mailgun[override-from]">
181
- <option value="1"<?php selected('1', $this->get_option('override-from', null, '0')); ?>><?php _e('Yes', 'mailgun'); ?></option>
182
- <option value="0"<?php selected('0', $this->get_option('override-from', null, '0')); ?>><?php _e('No', 'mailgun'); ?></option>
183
- </select>
184
- <p class="description"><?php _e('If enabled, all emails will be sent with the above "From Name" and "From Address", regardless of values set by other plugins. Useful for cases where other plugins don\'t play nice with our "From Name" / "From Address" setting.', 'mailgun'); ?></p>
185
- </td>
186
- </tr>
187
- <tr valign="top">
188
- <th scope="row">
189
- <?php _e('Tag', 'mailgun'); ?>
190
- </th>
191
- <td>
192
- <input type="text" class="regular-text" name="mailgun[campaign-id]" value="<?php esc_attr_e($this->get_option('campaign-id')); ?>" placeholder="tag" />
193
- <p class="description"><?php _e('If added, this tag will exist on every outbound message. Statistics will be populated in the Mailgun Control Panel. Use a comma to define multiple tags.', 'mailgun'); ?> <?php _e('Learn more about', 'mailgun'); ?> <a href="https://documentation.mailgun.com/user_manual.html#tracking-messages" target="_blank">Tracking</a> <?php _e('and', 'mailgun'); ?> <a href="https://documentation.mailgun.com/user_manual.html#tagging" target="_blank">Tagging</a>.</p>
194
- </td>
195
- </tr>
196
- </table>
197
- <h3><?php _e('Lists', 'mailgun'); ?></h3>
198
- <table class="form-table">
199
- <tr valign="top">
200
- <th scope="row">
201
- <?php _e('Shortcode', 'mailgun'); ?>
202
- </th>
203
- <td>
204
- <div>
205
- <strong>[mailgun id="<em>{mailgun list id}</em>" collect_name="true"]</strong>
206
- </div>
207
- <div>
208
- <p class="description"><?php _e('Use the shortcode above to associate a widget instance with a mailgun list', 'mailgun'); ?></p>
209
- </div>
210
- </td>
211
- </tr>
212
- <tr valign="top">
213
- <th scope="row">
214
- <?php _e('Lists', 'mailgun'); ?>
215
- </th>
216
- <td>
217
- <a href="?page=mailgun-lists">View available lists</a>
218
- </td>
219
- </tr>
220
- </table>
221
 
222
- <p><?php _e('Before attempting to test the configuration, please click "Save Changes".', 'mailgun'); ?></p>
223
- <p class="submit">
224
- <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'mailgun'); ?>" />
225
- <input type="button" id="mailgun-test" class="button-secondary" value="<?php _e('Test Configuration', 'mailgun'); ?>" />
226
- </p>
227
- </form>
228
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ /*
4
+ * mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun
5
+ * Copyright (C) 2016 Mailgun, et al.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License along
18
+ * with this program; if not, write to the Free Software Foundation, Inc.,
19
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ */
21
 
22
  ?>
23
+ <div class="wrap">
24
+ <div id="icon-options-general" class="icon32"><br/></div>
25
+ <span class="alignright">
26
+ <a target="_blank" href="http://www.mailgun.com/">
27
+ <img src="https://assets.mailgun.com/img/mailgun.svg" alt="Mailgun" style="width:10em;"/>
28
+ </a>
29
+ </span>
30
+ <h2><?php _e('Mailgun', 'mailgun'); ?></h2>
31
+ <p>
32
+ <?php
33
+ $url = 'https://www.mailgun.com';
34
+ $link = sprintf(
35
+ wp_kses(
36
+ __('A <a href="%1$s" target="%2$s">Mailgun</a> account is required to use this plugin and the Mailgun service.', 'mailgun'),
37
+ array('a' => array(
38
+ 'href' => array(),
39
+ 'target' => array()
40
+ )
41
+ )
42
+ ), esc_url($url), '_blank'
43
+ );
44
+ echo $link;
45
+ ?>
46
+ </p>
47
+ <p>
48
+ <?php
49
+ $url = 'https://signup.mailgun.com/new/signup';
50
+ $link = sprintf(
51
+ wp_kses(
52
+ __('If you need to register for an account, you can do so at <a href="%1$s" target="%2$s">Mailgun.com</a>.', 'mailgun'),
53
+ array('a' => array(
54
+ 'href' => array(),
55
+ 'target' => array()
56
+ )
57
+ )
58
+ ), esc_url($url), '_blank'
59
+ );
60
+ echo $link;
61
+ ?>
62
+ </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
+ <h3><?php _e('Configuration', 'mailgun'); ?></h3>
65
+
66
+ <?php
67
+ $isMultisite = defined('WP_ALLOW_MULTISITE');
68
+ if (!$isMultisite):
69
+ ?>
70
+ <form id="mailgun-form" action="options.php" method="post">
71
+ <?php settings_fields('mailgun'); ?>
72
+
73
+ <table class="form-table">
74
+ <tr valign="top">
75
+ <th scope="row">
76
+ <?php _e('Select Your Region', 'mailgun'); ?>
77
+ </th>
78
+ <td>
79
+ <select id="mailgun-region" name="mailgun[region]">
80
+ <option value="us"<?php selected('us', $this->get_option('region')); ?>><?php _e('U.S./North America', 'mailgun') ?></option>
81
+ <option value="eu"<?php selected('eu', $this->get_option('region')); ?>><?php _e('Europe', 'mailgun') ?></option>
82
+ </select>
83
+ <p class="description">
84
+ <?php
85
+ _e('Choose a region - U.S./North America or Europe - from which to send email, and to store your customer data. Please note that your sending domain must be set up in whichever region you choose.', 'mailgun');
86
+ ?>
87
+ </p>
88
+ </td>
89
+ </tr>
90
+ <tr valign="top">
91
+ <th scope="row">
92
+ <?php _e('Use HTTP API', 'mailgun'); ?>
93
+ </th>
94
+ <td>
95
+ <select id="mailgun-api" name="mailgun[useAPI]">
96
+ <option value="1"<?php selected('1', $this->get_option('useAPI')); ?>><?php _e('Yes', 'mailgun'); ?></option>
97
+ <option value="0"<?php selected('0', $this->get_option('useAPI')); ?>><?php _e('No', 'mailgun'); ?></option>
98
+ </select>
99
+ <p class="description">
100
+ <?php
101
+ _e('Set this to "No" if your server cannot make outbound HTTP connections or if emails are not being delivered. "No" will cause this plugin to use SMTP. Default "Yes".', 'mailgun');
102
+ ?>
103
+ </p>
104
+ </td>
105
+ </tr>
106
+ <tr valign="top">
107
+ <th scope="row">
108
+ <?php _e('Mailgun Domain Name', 'mailgun'); ?>
109
+ </th>
110
+ <td>
111
+ <input type="text" class="regular-text"
112
+ name="mailgun[domain]"
113
+ value="<?php esc_attr_e($this->get_option('domain')); ?>"
114
+ placeholder="samples.mailgun.org"
115
+ />
116
+ <p class="description">
117
+ <?php _e('Your Mailgun Domain Name.', 'mailgun'); ?>
118
+ </p>
119
+ </td>
120
+ </tr>
121
+ <tr valign="top" class="mailgun-api">
122
+ <th scope="row">
123
+ <?php _e('API Key', 'mailgun'); ?>
124
+ </th>
125
+ <td>
126
+ <input type="text" class="regular-text" name="mailgun[apiKey]"
127
+ value="<?php esc_attr_e($this->get_option('apiKey')); ?>"
128
+ placeholder="key-3ax6xnjp29jd6fds4gc373sgvjxteol0"
129
+ />
130
+ <p class="description">
131
+ <?php
132
+ _e('Your Mailgun API key. Only valid for use with the API.', 'mailgun');
133
+ ?>
134
+ </p>
135
+ </td>
136
+ </tr>
137
+ <tr valign="top" class="mailgun-smtp">
138
+ <th scope="row">
139
+ <?php _e('Username', 'mailgun'); ?>
140
+ </th>
141
+ <td>
142
+ <input type="text" class="regular-text"
143
+ name="mailgun[username]"
144
+ value="<?php esc_attr_e($this->get_option('username')); ?>"
145
+ placeholder="postmaster"
146
+ />
147
+ <p class="description">
148
+ <?php
149
+ _e('Your Mailgun SMTP username. Only valid for use with SMTP.', 'mailgun');
150
+ ?>
151
+ </p>
152
+ </td>
153
+ </tr>
154
+ <tr valign="top" class="mailgun-smtp">
155
+ <th scope="row">
156
+ <?php _e('Password', 'mailgun'); ?>
157
+ </th>
158
+ <td>
159
+ <input type="text" class="regular-text"
160
+ name="mailgun[password]"
161
+ value="<?php esc_attr_e($this->get_option('password')); ?>"
162
+ placeholder="my-password"
163
+ />
164
+ <p class="description">
165
+ <?php
166
+ _e('Your Mailgun SMTP password that goes with the above username. Only valid for use with SMTP.', 'mailgun');
167
+ ?>
168
+ </p>
169
+ </td>
170
+ </tr>
171
+ <tr valign="top" class="mailgun-smtp">
172
+ <th scope="row">
173
+ <?php _e('Use Secure SMTP', 'mailgun'); ?>
174
+ </th>
175
+ <td>
176
+ <select name="mailgun[secure]">
177
+ <option value="1"<?php selected('1', $this->get_option('secure')); ?>><?php _e('Yes', 'mailgun'); ?></option>
178
+ <option value="0"<?php selected('0', $this->get_option('secure')); ?>><?php _e('No', 'mailgun'); ?></option>
179
+ </select>
180
+ <p class="description">
181
+ <?php
182
+ _e('Set this to "No" if your server cannot establish SSL SMTP connections or if emails are not being delivered. If you set this to "No" your password will be sent in plain text. Only valid for use with SMTP. Default "Yes".', 'mailgun');
183
+ ?>
184
+ </p>
185
+ </td>
186
+ </tr>
187
+ <tr valign="top" class="mailgun-smtp">
188
+ <th scope="row">
189
+ <?php _e('Security Type', 'mailgun'); ?>
190
+ </th>
191
+ <td>
192
+ <select name="mailgun[sectype]">
193
+ <option value="ssl"<?php selected('ssl', $this->get_option('sectype')); ?>>SSL</option>
194
+ <option value="tls"<?php selected('tls', $this->get_option('sectype')); ?>>TLS</option>
195
+ </select>
196
+ <p class="description">
197
+ <?php
198
+ _e('Leave this at "TLS" unless mail sending fails. This option only matters for Secure SMTP. Default "TLS".', 'mailgun');
199
+ ?>
200
+ </p>
201
+ </td>
202
+ </tr>
203
+ <tr valign="top">
204
+ <th scope="row">
205
+ <?php _e('Click Tracking', 'mailgun'); ?>
206
+ </th>
207
+ <td>
208
+ <select name="mailgun[track-clicks]">
209
+ <option value="htmlonly"<?php selected('htmlonly', $this->get_option('track-clicks')); ?>><?php _e('HTML Only', 'mailgun'); ?></option>
210
+ <option value="yes"<?php selected('yes', $this->get_option('track-clicks')); ?>><?php _e('Yes', 'mailgun'); ?></option>
211
+ <option value="no"<?php selected('no', $this->get_option('track-clicks')); ?>><?php _e('No', 'mailgun'); ?></option>
212
+ </select>
213
+ <p class="description">
214
+ <?php
215
+ $url = 'http://documentation.mailgun.com/user_manual.html#tracking-clicks';
216
+ $link = sprintf(
217
+ wp_kses(
218
+ __('If enabled, Mailgun will and track links. <a href="%1$s" target="%2$s">Open Tracking Documentation</a>.', 'mailgun'),
219
+ array('a' => array(
220
+ 'href' => array(),
221
+ 'target' => array()
222
+ )
223
+ )
224
+ ), esc_url($url), '_blank'
225
+ );
226
+ echo $link;
227
+ ?>
228
+ </p>
229
+ </td>
230
+ </tr>
231
+ <tr valign="top">
232
+ <th scope="row">
233
+ <?php _e('Open Tracking', 'mailgun'); ?>
234
+ </th>
235
+ <td>
236
+ <select name="mailgun[track-opens]">
237
+ <option value="1"<?php selected('1', $this->get_option('track-opens')); ?>><?php _e('Yes', 'mailgun'); ?></option>
238
+ <option value="0"<?php selected('0', $this->get_option('track-opens')); ?>><?php _e('No', 'mailgun'); ?></option>
239
+ </select>
240
+ <p class="description">
241
+ <?php
242
+ $url = 'http://documentation.mailgun.com/user_manual.html#tracking-opens';
243
+ $link = sprintf(
244
+ wp_kses(
245
+ __('If enabled, HTML messages will include an open tracking beacon. <a href="%1$s" target="%2$s">Open Tracking Documentation</a>.', 'mailgun'),
246
+ array('a' => array(
247
+ 'href' => array(),
248
+ 'target' => array()
249
+ )
250
+ )
251
+ ), esc_url($url), '_blank'
252
+ );
253
+ echo $link;
254
+ ?>
255
+ </p>
256
+ </td>
257
+ </tr>
258
+ <tr valign="top">
259
+ <th scope="row">
260
+ <?php _e('From Address', 'mailgun'); ?>
261
+ </th>
262
+ <td>
263
+ <input type="text"
264
+ class="regular-text"
265
+ name="mailgun[from-address]"
266
+ value="<?php esc_attr_e($this->get_option('from-address')); ?>"
267
+ placeholder="wordpress@mydomain.com"
268
+ />
269
+ <p class="description">
270
+ <?php
271
+ _e('The &lt;address@mydomain.com&gt; part of the sender information (<code>"Excited User &lt;user@samples.mailgun.org&gt;"</code>). This address will appear as the `From` address on sent mail. <strong>It is recommended that the @mydomain portion matches your Mailgun sending domain.</strong>', 'mailgun');
272
+ ?>
273
+ </p>
274
+ </td>
275
+ </tr>
276
+ <tr valign="top">
277
+ <th scope="row">
278
+ <?php _e('From Name', 'mailgun'); ?>
279
+ </th>
280
+ <td>
281
+ <input type="text" class="regular-text"
282
+ name="mailgun[from-name]"
283
+ value="<?php esc_attr_e($this->get_option('from-name')); ?>"
284
+ placeholder="WordPress"
285
+ />
286
+ <p class="description">
287
+ <?php
288
+ _e('The "User Name" part of the sender information (<code>"Excited User &lt;user@samples.mailgun.org&gt;"</code>).', 'mailgun');
289
+ ?>
290
+ </p>
291
+ </td>
292
+ </tr>
293
+ <tr valign="top">
294
+ <th scope="row">
295
+ <?php _e('Override "From" Details', 'mailgun'); ?>
296
+ </th>
297
+ <td>
298
+ <select name="mailgun[override-from]">
299
+ <option value="1"<?php selected('1', $this->get_option('override-from', null, '0')); ?>><?php _e('Yes', 'mailgun'); ?></option>
300
+ <option value="0"<?php selected('0', $this->get_option('override-from', null, '0')); ?>><?php _e('No', 'mailgun'); ?></option>
301
+ </select>
302
+ <p class="description">
303
+ <?php
304
+ _e('If enabled, all emails will be sent with the above "From Name" and "From Address", regardless of values set by other plugins. Useful for cases where other plugins don\'t play nice with our "From Name" / "From Address" setting.', 'mailgun');
305
+ ?>
306
+ </p>
307
+ </td>
308
+ </tr>
309
+ <tr valign="top">
310
+ <th scope="row">
311
+ <?php _e('Tag', 'mailgun'); ?>
312
+ </th>
313
+ <td>
314
+ <input type="text" class="regular-text"
315
+ name="mailgun[campaign-id]"
316
+ value="<?php esc_attr_e($this->get_option('campaign-id')); ?>"
317
+ placeholder="tag"
318
+ />
319
+ <p class="description">
320
+ <?php
321
+ _e('If added, this tag will exist on every outbound message. Statistics will be populated in the Mailgun Control Panel. Use a comma to define multiple tags. ', 'mailgun');
322
+ _e('Learn more about', 'mailgun');
323
+
324
+ $url1 = 'https://documentation.mailgun.com/user_manual.html#tracking-messages';
325
+ $url2 = 'https://documentation.mailgun.com/user_manual.html#tagging';
326
+ $link = sprintf(
327
+ wp_kses(
328
+ __('<a href="%1$s" target="%3$s">Tracking</a> and <a href="%2$s">Tagging</a>', 'mailgun'),
329
+ array('a' => array(
330
+ 'href' => array(),
331
+ 'target' => array()
332
+ )
333
+ )
334
+ ), esc_url($url1), esc_url($url2), '_blank'
335
+ );
336
+ echo $link;
337
+ ?>
338
+ </p>
339
+ </td>
340
+ </tr>
341
+ </table>
342
+ <?php else: ?>
343
+ <p>
344
+ <?php
345
+ _e('Once you have configured the plugin settings in your wp-config.php, you can test it here.', 'mailgun');
346
+ ?>
347
+ </p>
348
+ <p><?php _e('The definitions are as follows:', 'mailgun'); ?></p>
349
+ <p>
350
+ <pre>
351
+ MAILGUN_REGION Choices: 'us' or 'eu'
352
+ ex. define('MAILGUN_REGION', 'us');
353
+ MAILGUN_USEAPI Choices: '0' or '1' (0 = false/no)
354
+ MAILGUN_APIKEY
355
+ MAILGUN_DOMAIN
356
+ MAILGUN_USERNAME
357
+ MAILGUN_PASSWORD
358
+ MAILGUN_SECURE
359
+ MAILGUN_SECTYPE Choices: 'ssl' or 'tls'
360
+ MAILGUN_FROM_NAME
361
+ MAILGUN_FROM_ADDRESS
362
+ </pre>
363
+ </p>
364
+ <?php endif; ?>
365
+ <h3><?php _e('Lists', 'mailgun'); ?></h3>
366
+ <table class="form-table">
367
+ <tr valign="top">
368
+ <th scope="row">
369
+ <?php _e('Shortcode', 'mailgun'); ?>
370
+ </th>
371
+ <td>
372
+ <div>
373
+ <code>[mailgun id="<em>{mailgun list id}</em>" collect_name="true"]</code>
374
+ </div>
375
+ <div>
376
+ <p class="description">
377
+ <?php
378
+ _e('Use the shortcode above to associate a widget instance with a mailgun list', 'mailgun');
379
+ ?>
380
+ </p>
381
+ </div>
382
+ </td>
383
+ </tr>
384
+ <tr valign="top">
385
+ <th scope="row">
386
+ <?php _e('Lists', 'mailgun'); ?>
387
+ </th>
388
+ <td>
389
+ <?php
390
+ $url = '?page=mailgun-lists';
391
+
392
+ $link = sprintf(
393
+ wp_kses(
394
+ __('<a href="%1$s" target="%2$s">View available lists</a>.', 'mailgun'),
395
+ array('a' => array(
396
+ 'href' => array(),
397
+ 'target' => array()
398
+ )
399
+ )
400
+ ), esc_url($url), '_blank'
401
+ );
402
+ echo $link;
403
+ ?>
404
+ </td>
405
+ </tr>
406
+ </table>
407
+
408
+ <?php if (!$isMultisite): ?>
409
+ <p>
410
+ <?php
411
+ _e('Before attempting to test the configuration, please click "Save Changes".', 'mailgun');
412
+ ?>
413
+ </p>
414
+ <p class="submit">
415
+ <input type="submit"
416
+ class="button-primary"
417
+ value="<?php _e('Save Changes', 'mailgun'); ?>"
418
+ />
419
+ <input type="button"
420
+ id="mailgun-test"
421
+ class="button-secondary"
422
+ value="<?php _e('Test Configuration', 'mailgun'); ?>"
423
+ />
424
+ </p>
425
+ <?php else: ?>
426
+ <p class="submit">
427
+ <input type="button"
428
+ id="mailgun-test"
429
+ class="button-secondary"
430
+ value="<?php _e('Test Configuration', 'mailgun'); ?>"
431
+ />
432
+ </p>
433
+ <?php endif; ?>
434
+ </form>
435
+ </div>
languages/mailgun-template.po CHANGED
@@ -61,10 +61,6 @@ msgstr ""
61
  msgid "Mailgun is almost ready. "
62
  msgstr ""
63
 
64
- #: includes/admin.php:301
65
- msgid "You must <a href=\"%1$s\">configure Mailgun</a> for it to work."
66
- msgstr ""
67
-
68
  #: includes/admin.php:309
69
  msgid ""
70
  "\"Override From\" option requires that \"From Name\" and \"From Address\" be "
61
  msgid "Mailgun is almost ready. "
62
  msgstr ""
63
 
 
 
 
 
64
  #: includes/admin.php:309
65
  msgid ""
66
  "\"Override From\" option requires that \"From Name\" and \"From Address\" be "
mailgun.php CHANGED
@@ -1,478 +1,486 @@
1
  <?php
2
 
3
- /**
4
- * Plugin Name: Mailgun
5
- * Plugin URI: http://wordpress.org/extend/plugins/mailgun/
6
- * Description: Mailgun integration for WordPress
7
- * Version: 1.5.14
8
- * Author: Mailgun
9
- * Author URI: http://www.mailgun.com/
10
- * License: GPLv2 or later
11
- * Text Domain: mailgun
12
- * Domain Path: /languages/.
13
- */
14
-
15
- /*
16
- * mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun
17
- * Copyright (C) 2016 Mailgun, et al.
18
- *
19
- * This program is free software; you can redistribute it and/or modify
20
- * it under the terms of the GNU General Public License as published by
21
- * the Free Software Foundation; either version 2 of the License, or
22
- * (at your option) any later version.
23
- *
24
- * This program is distributed in the hope that it will be useful,
25
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
- * GNU General Public License for more details.
28
- *
29
- * You should have received a copy of the GNU General Public License along
30
- * with this program; if not, write to the Free Software Foundation, Inc.,
31
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32
- */
33
-
34
- /**
35
- * Entrypoint for the Mailgun plugin. Sets up the mailing "strategy" -
36
- * either API or SMTP.
37
- *
38
- * Registers handlers for later actions and sets up config variables with
39
- * Wordpress.
40
- */
41
- class Mailgun
42
- {
43
- /**
44
- * Setup shared functionality for Admin and Front End.
45
- *
46
- * @since 0.1
47
- */
48
- public function __construct()
49
- {
50
- $this->options = get_option('mailgun');
51
- $this->plugin_file = __FILE__;
52
- $this->plugin_basename = plugin_basename($this->plugin_file);
53
-
54
- // Either override the wp_mail function or configure PHPMailer to use the
55
- // Mailgun SMTP servers
56
- // When using SMTP, we also need to inject a `wp_mail` filter to make "from" settings
57
- // work properly. Fixes issues with 1.5.7+
58
- if ($this->get_option('useAPI') || (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI)) {
59
- if (!function_exists('wp_mail')) {
60
- if (!include dirname(__FILE__).'/includes/wp-mail-api.php') {
61
- self::deactivate_and_die(dirname(__FILE__).'/includes/wp-mail-api.php');
62
- }
63
- }
64
- } else {
65
- // Using SMTP, include the SMTP filter
66
- if (!function_exists('mg_smtp_mail_filter')) {
67
- if (!include dirname(__FILE__).'/includes/wp-mail-smtp.php') {
68
- self::deactivate_and_die(dirname(__FILE__).'/includes/wp-mail-smtp.php');
69
- }
70
- }
71
- add_filter('wp_mail', 'mg_smtp_mail_filter');
72
- add_action('phpmailer_init', array(&$this, 'phpmailer_init'));
73
- add_action('wp_mail_failed', 'wp_mail_failed');
74
- }
75
- }
76
-
77
- /**
78
- * Get specific option from the options table.
79
- *
80
- * @param string $option Name of option to be used as array key for retrieving the specific value
81
- * @param array $options Array to iterate over for specific values
82
- * @param bool $default False if no options are set
83
- *
84
- * @return mixed
85
- *
86
- * @since 0.1
87
- */
88
- public function get_option($option, $options = null, $default = false)
89
- {
90
- if (is_null($options)) {
91
- $options = &$this->options;
92
- }
93
- if (isset($options[$option])) {
94
- return $options[$option];
95
- } else {
96
- return $default;
97
- }
98
- }
99
-
100
- /**
101
- * Hook into phpmailer to override SMTP based configurations
102
- * to use the Mailgun SMTP server.
103
- *
104
- * @param object $phpmailer The PHPMailer object to modify by reference
105
- *
106
- * @return void
107
- *
108
- * @since 0.1
109
- */
110
- public function phpmailer_init(&$phpmailer)
111
- {
112
- $username = (defined('MAILGUN_USERNAME') && MAILGUN_USERNAME) ? MAILGUN_USERNAME : $this->get_option('username');
113
- $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $this->get_option('domain');
114
- $username = preg_replace('/@.+$/', '', $username)."@{$domain}";
115
- $secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
116
- $sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
117
- $password = (defined('MAILGUN_PASSWORD') && MAILGUN_PASSWORD) ? MAILGUN_PASSWORD : $this->get_option('password');
118
- $region = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
119
-
120
- $smtp_endpoint = mg_smtp_get_region($region);
121
- $smtp_endpoint = (bool) $smtp_endpoint ? $smtp_endpoint : 'smtp.mailgun.org';
122
-
123
- $phpmailer->Mailer = 'smtp';
124
- $phpmailer->Host = $smtp_endpoint;
125
- if ( 'ssl' === $sectype ) {
126
- // For SSL-only connections, use 465
127
- $phpmailer->Port = 465;
128
- } else {
129
- // Otherwise, use 587.
130
- $phpmailer->Port = 587;
131
- }
132
- $phpmailer->SMTPAuth = true;
133
- $phpmailer->Username = $username;
134
- $phpmailer->Password = $password;
135
-
136
- $phpmailer->SMTPSecure = (bool) $secure ? $sectype : '';
137
- // Without this line... wp_mail for SMTP-only will always return false. But why? :(
138
- $phpmailer->Debugoutput = 'mg_smtp_debug_output';
139
- $phpmailer->SMTPDebug = 2;
140
-
141
- // Emit some logging for SMTP connection
142
- mg_smtp_debug_output(sprintf("PHPMailer configured to send via %s:%s", $phpmailer->Host, $phpmailer->Port), 'DEBUG');
143
- }
144
-
145
- /**
146
- * Deactivate this plugin and die.
147
- * Deactivate the plugin when files critical to it's operation cannot be loaded
148
- *
149
- * @param $file Files critical to plugin functionality
150
- *
151
- * @return void
152
- *
153
- * @since 0.1
154
- */
155
- public function deactivate_and_die($file)
156
- {
157
- load_plugin_textdomain('mailgun', false, 'mailgun/languages');
158
- $message = sprintf(__('Mailgun has been automatically deactivated because the file <strong>%s</strong> is missing. Please reinstall the plugin and reactivate.'), $file);
159
- if (!function_exists('deactivate_plugins')) {
160
- include ABSPATH.'wp-admin/includes/plugin.php';
161
- }
162
- deactivate_plugins(__FILE__);
163
- wp_die($message);
164
- }
165
-
166
- /**
167
- * Make a Mailgun api call.
168
- *
169
- * @param string $uri The endpoint for the Mailgun API
170
- * @param array $params Array of parameters passed to the API
171
- * @param string $method The form request type
172
- *
173
- * @return array
174
- *
175
- * @since 0.1
176
- */
177
- public function api_call($uri, $params = array(), $method = 'POST')
178
- {
179
- $options = get_option('mailgun');
180
- $getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $options['region'];
181
- $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $options['apiKey'];
182
- $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options['domain'];
183
-
184
- $region = mg_api_get_region($getRegion);
185
- $this->api_endpoint = ($region) ? $region : 'https://api.mailgun.net/v3/';
186
-
187
- $time = time();
188
- $url = $this->api_endpoint.$uri;
189
- $headers = array(
190
- 'Authorization' => 'Basic '.base64_encode("api:{$apiKey}"),
191
- );
192
-
193
- switch ($method) {
194
- case 'GET':
195
- $params['sess'] = '';
196
- $querystring = http_build_query($params);
197
- $url = $url.'?'.$querystring;
198
- $params = '';
199
- break;
200
- case 'POST':
201
- case 'PUT':
202
- case 'DELETE':
203
- $params['sess'] = '';
204
- $params['time'] = $time;
205
- $params['hash'] = sha1(date('U'));
206
- break;
207
- }
208
-
209
- // make the request
210
- $args = array(
211
- 'method' => $method,
212
- 'body' => $params,
213
- 'headers' => $headers,
214
- 'sslverify' => true,
215
- );
216
-
217
- // make the remote request
218
- $result = wp_remote_request($url, $args);
219
- if (!is_wp_error($result)) {
220
- return $result['body'];
221
- } else {
222
- return $result->get_error_message();
223
- }
224
- }
225
-
226
- /**
227
- * Get account associated lists.
228
- *
229
- * @return array
230
- *
231
- * @since 0.1
232
- */
233
- public function get_lists()
234
- {
235
- $results = array();
236
-
237
- $lists_json = $this->api_call('lists', array(), 'GET');
238
- $lists_arr = json_decode($lists_json, true);
239
- if (isset($lists_arr['items']) && !empty($lists_arr['items'])) {
240
- $results = $lists_arr['items'];
241
- }
242
-
243
- return $results;
244
- }
245
-
246
- /**
247
- * Handle add list ajax post.
248
- *
249
- * @return string json
250
- *
251
- * @since 0.1
252
- */
253
- public function add_list()
254
- {
255
- $response = array();
256
-
257
- $name = isset($_POST['name']) ? $_POST['name'] : null;
258
- $email = isset($_POST['email']) ? $_POST['email'] : null;
259
-
260
- $list_addresses = $_POST['addresses'];
261
-
262
- if (!empty($list_addresses)) {
263
- foreach ($list_addresses as $address => $val) {
264
- $response[] = $this->api_call(
265
- "lists/{$address}/members",
266
- array(
267
- 'address' => $email,
268
- 'name' => $name,
269
- )
270
- );
271
- }
272
-
273
- echo json_encode(array('status' => 200, 'message' => 'Thank you!'));
274
- } else {
275
- echo json_encode(array('status' => 500, 'message' => 'Uh oh. We weren\'t able to add you to the list'.count($list_addresses) ? 's.' : '. Please try again.'));
276
- }
277
-
278
- wp_die();
279
- }
280
-
281
- /**
282
- * Frontend List Form.
283
- *
284
- * @param string $list_address Mailgun address list id
285
- * @param array $args widget arguments
286
- * @param array $instance widget instance params
287
- *
288
- * @since 0.1
289
- */
290
- public function list_form($list_address, $args = array(), $instance = array())
291
- {
292
- $widget_class_id = "mailgun-list-widget-{$args['widget_id']}";
293
- $form_class_id = "list-form-{$args['widget_id']}";
294
-
295
- // List addresses from the plugin config
296
- $list_addresses = array_map('trim', explode(',', $list_address));
297
-
298
- // All list info from the API; used for list info when more than one list is available to subscribe to
299
- $all_list_addresses = $this->get_lists(); ?>
300
- <div class="mailgun-list-widget-front <?php echo $widget_class_id; ?> widget">
301
- <form class="list-form <?php echo $form_class_id; ?>">
302
- <div class="mailgun-list-widget-inputs">
303
- <?php if (isset($args['list_title'])) : ?>
304
- <div class="mailgun-list-title">
305
- <h4 class="widget-title">
306
- <span><?php echo $args['list_title']; ?></span>
307
- </h4>
308
- </div>
309
- <?php endif; ?>
310
- <?php if (isset($args['list_description'])) : ?>
311
- <div class="mailgun-list-description">
312
- <p class="widget-description">
313
- <span><?php echo $args['list_description']; ?></span>
314
- </p>
315
- </div>
316
- <?php endif; ?>
317
- <?php if (isset($args['collect_name']) && intval($args['collect_name']) === 1) : ?>
318
- <p class="mailgun-list-widget-name">
319
- <strong>Name:</strong>
320
- <input type="text" name="name" />
321
- </p>
322
- <?php endif; ?>
323
- <p class="mailgun-list-widget-email">
324
- <strong>Email:</strong>
325
- <input type="text" name="email" />
326
- </p>
327
- </div>
328
-
329
- <?php if (count($list_addresses) > 1) : ?>
330
- <ul class="mailgun-lists" style="list-style: none;">
331
- <?php foreach ($all_list_addresses as $la) : ?>
332
- <?php if (!in_array($la['address'], $list_addresses)) {
333
- continue;
334
- } ?>
335
- <li>
336
- <input type="checkbox" class="mailgun-list-name" name="addresses[<?php echo $la['address']; ?>]" /> <?php echo $la['name']; ?>
337
- </li>
338
- <?php endforeach; ?>
339
- </ul>
340
- <?php else : ?>
341
- <input type="hidden" name="addresses[<?php echo $list_addresses[0]; ?>]" value="on" />
342
- <?php endif; ?>
343
-
344
- <input class="mailgun-list-submit-button" data-form-id="<?php echo $form_class_id; ?>" type="button" value="Subscribe" />
345
- <input type="hidden" name="mailgun-submission" value="1" />
346
-
347
- </form>
348
- <div class="widget-list-panel result-panel" style="display:none;">
349
- <span>Thank you for subscribing!</span>
350
- </div>
351
- </div>
352
-
353
- <script>
354
-
355
- jQuery(document).ready(function(){
356
-
357
- jQuery('.mailgun-list-submit-button').on('click', function() {
358
-
359
- var form_id = jQuery(this).data('form-id');
360
-
361
- if(jQuery('.mailgun-list-name').length > 0 && jQuery('.'+form_id+' .mailgun-list-name:checked').length < 1) {
362
- alert('Please select a list to subscribe to.');
363
- return;
364
- }
365
-
366
- if(jQuery('.'+form_id+' .mailgun-list-widget-name input') && jQuery('.'+form_id+' .mailgun-list-widget-name input').val() === '') {
367
- alert('Please enter your subscription name.');
368
- return;
369
- }
370
-
371
- if(jQuery('.'+form_id+' .mailgun-list-widget-email input').val() === '') {
372
- alert('Please enter your subscription email.');
373
- return;
374
- }
375
-
376
- jQuery.ajax({
 
 
 
 
 
 
 
 
 
 
 
377
  url: '<?php echo admin_url('admin-ajax.php?action=add_list'); ?>',
378
- action:'add_list',
379
  type: 'post',
380
  dataType: 'json',
381
- data: jQuery('.'+form_id+'').serialize(),
382
- success: function(data) {
383
-
384
- data_msg = data.message;
385
- already_exists = false;
386
- if(data_msg !== undefined){
387
- already_exists = data_msg.indexOf('Address already exists') > -1;
388
- }
389
-
390
- // success
391
- if((data.status === 200)) {
392
- jQuery('.<?php echo $widget_class_id; ?> .widget-list-panel').css('display', 'none');
393
- jQuery('.<?php echo $widget_class_id; ?> .list-form').css('display', 'none');
394
- jQuery('.<?php echo $widget_class_id; ?> .result-panel').css('display', 'block');
395
  // error
396
- } else {
397
- alert(data_msg);
398
- }
399
  }
400
- });
401
- });
402
- });
403
-
404
- </script>
405
-
406
- <?php
407
-
408
- }
409
-
410
- /**
411
- * Initialize List Form.
412
- *
413
- * @param array $atts Form attributes
414
- *
415
- * @return string
416
- *
417
- * @since 0.1
418
- */
419
- public function build_list_form($atts)
420
- {
421
- if (isset($atts['id']) && $atts['id'] != '') {
422
- $args['widget_id'] = md5(rand(10000, 99999) + $atts['id']);
423
-
424
- if (isset($atts['collect_name'])) {
425
- $args['collect_name'] = true;
426
- }
427
-
428
- if (isset($atts['title'])) {
429
- $args['list_title'] = $atts['title'];
430
- }
431
-
432
- if (isset($atts['description'])) {
433
- $args['list_description'] = $atts['description'];
434
- }
435
-
436
- ob_start();
437
- $this->list_form($atts['id'], $args);
438
- $output_string = ob_get_contents();
439
- ob_end_clean();
440
-
441
- return $output_string;
442
- } else {
443
- ?>
444
- <span>Mailgun list ID needed to render form!</span>
445
- <br />
446
- <strong>Example :</strong> [mailgun id="[your list id]"]
447
- <?php
448
-
449
- }
450
- }
451
-
452
- /**
453
- * Initialize List Widget.
454
- *
455
- * @since 0.1
456
- */
457
- public function load_list_widget()
458
- {
459
- register_widget('list_widget');
460
- add_shortcode('mailgun', array(&$this, 'build_list_form'));
461
- }
462
- }
463
-
464
- $mailgun = new Mailgun();
465
-
466
- if (@include dirname(__FILE__).'/includes/widget.php') {
467
- add_action('widgets_init', array(&$mailgun, 'load_list_widget'));
468
- add_action('wp_ajax_nopriv_add_list', array(&$mailgun, 'add_list'));
469
- add_action('wp_ajax_add_list', array(&$mailgun, 'add_list'));
470
- }
471
-
472
- if (is_admin()) {
473
- if (@include dirname(__FILE__).'/includes/admin.php') {
474
- $mailgunAdmin = new MailgunAdmin();
475
- } else {
476
- Mailgun::deactivate_and_die(dirname(__FILE__).'/includes/admin.php');
477
- }
478
- }
1
  <?php
2
 
3
+ /**
4
+ * Plugin Name: Mailgun
5
+ * Plugin URI: http://wordpress.org/extend/plugins/mailgun/
6
+ * Description: Mailgun integration for WordPress
7
+ * Version: 1.6
8
+ * Author: Mailgun
9
+ * Author URI: http://www.mailgun.com/
10
+ * License: GPLv2 or later
11
+ * Text Domain: mailgun
12
+ * Domain Path: /languages/.
13
+ */
14
+
15
+ /*
16
+ * mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun
17
+ * Copyright (C) 2016 Mailgun, et al.
18
+ *
19
+ * This program is free software; you can redistribute it and/or modify
20
+ * it under the terms of the GNU General Public License as published by
21
+ * the Free Software Foundation; either version 2 of the License, or
22
+ * (at your option) any later version.
23
+ *
24
+ * This program is distributed in the hope that it will be useful,
25
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ * GNU General Public License for more details.
28
+ *
29
+ * You should have received a copy of the GNU General Public License along
30
+ * with this program; if not, write to the Free Software Foundation, Inc.,
31
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32
+ */
33
+
34
+ /**
35
+ * Entrypoint for the Mailgun plugin. Sets up the mailing "strategy" -
36
+ * either API or SMTP.
37
+ *
38
+ * Registers handlers for later actions and sets up config variables with
39
+ * Wordpress.
40
+ */
41
+ class Mailgun
42
+ {
43
+ /**
44
+ * Setup shared functionality for Admin and Front End.
45
+ *
46
+ * @since 0.1
47
+ */
48
+ public function __construct()
49
+ {
50
+ $this->options = get_option('mailgun');
51
+ $this->plugin_file = __FILE__;
52
+ $this->plugin_basename = plugin_basename($this->plugin_file);
53
+
54
+ // Either override the wp_mail function or configure PHPMailer to use the
55
+ // Mailgun SMTP servers
56
+ // When using SMTP, we also need to inject a `wp_mail` filter to make "from" settings
57
+ // work properly. Fixes issues with 1.5.7+
58
+ if ($this->get_option('useAPI') || (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI)):
59
+ if (!function_exists('wp_mail')):
60
+ if (!include dirname(__FILE__) . '/includes/wp-mail-api.php'):
61
+ self::deactivate_and_die(dirname(__FILE__) . '/includes/wp-mail-api.php');
62
+ endif;
63
+ endif;
64
+ else:
65
+ // Using SMTP, include the SMTP filter
66
+ if (!function_exists('mg_smtp_mail_filter')):
67
+ if (!include dirname(__FILE__) . '/includes/wp-mail-smtp.php'):
68
+ self::deactivate_and_die(dirname(__FILE__) . '/includes/wp-mail-smtp.php');
69
+ endif;
70
+ endif;
71
+ add_filter('wp_mail', 'mg_smtp_mail_filter');
72
+ add_action('phpmailer_init', array(&$this, 'phpmailer_init'));
73
+ add_action('wp_mail_failed', 'wp_mail_failed');
74
+ endif;
75
+ }
76
+
77
+ /**
78
+ * Get specific option from the options table.
79
+ *
80
+ * @param string $option Name of option to be used as array key for retrieving the specific value
81
+ * @param array $options Array to iterate over for specific values
82
+ * @param bool $default False if no options are set
83
+ *
84
+ * @return mixed
85
+ *
86
+ * @since 0.1
87
+ */
88
+ public function get_option($option, $options = null, $default = false)
89
+ {
90
+ if (is_null($options)):
91
+ $options = &$this->options;
92
+ endif;
93
+ if (isset($options[ $option ])):
94
+ return $options[ $option ];
95
+ else:
96
+ return $default;
97
+ endif;
98
+ }
99
+
100
+ /**
101
+ * Hook into phpmailer to override SMTP based configurations
102
+ * to use the Mailgun SMTP server.
103
+ *
104
+ * @param object $phpmailer The PHPMailer object to modify by reference
105
+ *
106
+ * @return void
107
+ *
108
+ * @since 0.1
109
+ */
110
+ public function phpmailer_init(&$phpmailer)
111
+ {
112
+ $username = (defined('MAILGUN_USERNAME') && MAILGUN_USERNAME) ? MAILGUN_USERNAME : $this->get_option('username');
113
+ $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $this->get_option('domain');
114
+ $username = preg_replace('/@.+$/', '', $username) . "@{$domain}";
115
+ $secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
116
+ $sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
117
+ $password = (defined('MAILGUN_PASSWORD') && MAILGUN_PASSWORD) ? MAILGUN_PASSWORD : $this->get_option('password');
118
+ $region = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
119
+
120
+ $smtp_endpoint = mg_smtp_get_region($region);
121
+ $smtp_endpoint = (bool) $smtp_endpoint ? $smtp_endpoint : 'smtp.mailgun.org';
122
+
123
+ $phpmailer->Mailer = 'smtp';
124
+ $phpmailer->Host = $smtp_endpoint;
125
+
126
+ if ('ssl' === $sectype):
127
+ // For SSL-only connections, use 465
128
+ $phpmailer->Port = 465;
129
+ else:
130
+ // Otherwise, use 587.
131
+ $phpmailer->Port = 587;
132
+ endif;
133
+
134
+ $phpmailer->SMTPAuth = true;
135
+ $phpmailer->Username = $username;
136
+ $phpmailer->Password = $password;
137
+
138
+ $phpmailer->SMTPSecure = (bool) $secure ? $sectype : '';
139
+ // Without this line... wp_mail for SMTP-only will always return false. But why? :(
140
+ $phpmailer->Debugoutput = 'mg_smtp_debug_output';
141
+ $phpmailer->SMTPDebug = 2;
142
+
143
+ // Emit some logging for SMTP connection
144
+ mg_smtp_debug_output(sprintf("PHPMailer configured to send via %s:%s", $phpmailer->Host, $phpmailer->Port),
145
+ 'DEBUG');
146
+ }
147
+
148
+ /**
149
+ * Deactivate this plugin and die.
150
+ * Deactivate the plugin when files critical to it's operation cannot be loaded
151
+ *
152
+ * @param $file Files critical to plugin functionality
153
+ *
154
+ * @return void
155
+ *
156
+ * @since 0.1
157
+ */
158
+ public function deactivate_and_die($file)
159
+ {
160
+ load_plugin_textdomain('mailgun', false, 'mailgun/languages');
161
+ $message = sprintf(__('Mailgun has been automatically deactivated because the file <strong>%s</strong> is missing. Please reinstall the plugin and reactivate.'),
162
+ $file);
163
+ if (!function_exists('deactivate_plugins')):
164
+ include ABSPATH . 'wp-admin/includes/plugin.php';
165
+ endif;
166
+ deactivate_plugins(__FILE__);
167
+ wp_die($message);
168
+ }
169
+
170
+ /**
171
+ * Make a Mailgun api call.
172
+ *
173
+ * @param string $uri The endpoint for the Mailgun API
174
+ * @param array $params Array of parameters passed to the API
175
+ * @param string $method The form request type
176
+ *
177
+ * @return array
178
+ *
179
+ * @since 0.1
180
+ */
181
+ public function api_call($uri, $params = array(), $method = 'POST')
182
+ {
183
+ $options = get_option('mailgun');
184
+ $getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $options[ 'region' ];
185
+ $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $options[ 'apiKey' ];
186
+ $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options[ 'domain' ];
187
+
188
+ $region = mg_api_get_region($getRegion);
189
+ $this->api_endpoint = ($region) ? $region : 'https://api.mailgun.net/v3/';
190
+
191
+ $time = time();
192
+ $url = $this->api_endpoint . $uri;
193
+ $headers = array(
194
+ 'Authorization' => 'Basic ' . base64_encode("api:{$apiKey}"),
195
+ );
196
+
197
+ switch ($method) {
198
+ case 'GET':
199
+ $params[ 'sess' ] = '';
200
+ $querystring = http_build_query($params);
201
+ $url = $url . '?' . $querystring;
202
+ $params = '';
203
+ break;
204
+ case 'POST':
205
+ case 'PUT':
206
+ case 'DELETE':
207
+ $params[ 'sess' ] = '';
208
+ $params[ 'time' ] = $time;
209
+ $params[ 'hash' ] = sha1(date('U'));
210
+ break;
211
+ }
212
+
213
+ // make the request
214
+ $args = array(
215
+ 'method' => $method,
216
+ 'body' => $params,
217
+ 'headers' => $headers,
218
+ 'sslverify' => true,
219
+ );
220
+
221
+ // make the remote request
222
+ $result = wp_remote_request($url, $args);
223
+ if (!is_wp_error($result)):
224
+ return $result[ 'body' ];
225
+ else:
226
+ return $result->get_error_message();
227
+ endif;
228
+ }
229
+
230
+ /**
231
+ * Get account associated lists.
232
+ *
233
+ * @return array
234
+ *
235
+ * @since 0.1
236
+ */
237
+ public function get_lists()
238
+ {
239
+ $results = array();
240
+
241
+ $lists_json = $this->api_call('lists', array(), 'GET');
242
+ $lists_arr = json_decode($lists_json, true);
243
+ if (isset($lists_arr[ 'items' ]) && !empty($lists_arr[ 'items' ])):
244
+ $results = $lists_arr[ 'items' ];
245
+ endif;
246
+
247
+ return $results;
248
+ }
249
+
250
+ /**
251
+ * Handle add list ajax post.
252
+ *
253
+ * @return string json
254
+ *
255
+ * @since 0.1
256
+ */
257
+ public function add_list()
258
+ {
259
+ $response = array();
260
+
261
+ $name = isset($_POST[ 'name' ]) ? $_POST[ 'name' ] : null;
262
+ $email = isset($_POST[ 'email' ]) ? $_POST[ 'email' ] : null;
263
+
264
+ $list_addresses = $_POST[ 'addresses' ];
265
+
266
+ if (!empty($list_addresses)):
267
+ foreach ($list_addresses as $address => $val):
268
+ $response[] = $this->api_call(
269
+ "lists/{$address}/members",
270
+ array(
271
+ 'address' => $email,
272
+ 'name' => $name,
273
+ )
274
+ );
275
+ endforeach;
276
+
277
+ echo json_encode(array('status' => 200, 'message' => 'Thank you!'));
278
+ else:
279
+ echo json_encode(array(
280
+ 'status' => 500,
281
+ 'message' => 'Uh oh. We weren\'t able to add you to the list' . count($list_addresses) ? 's.' : '. Please try again.'
282
+ ));
283
+ endif;
284
+
285
+ wp_die();
286
+ }
287
+
288
+ /**
289
+ * Frontend List Form.
290
+ *
291
+ * @param string $list_address Mailgun address list id
292
+ * @param array $args widget arguments
293
+ * @param array $instance widget instance params
294
+ *
295
+ * @since 0.1
296
+ */
297
+ public function list_form($list_address, $args = array(), $instance = array())
298
+ {
299
+ $widget_class_id = "mailgun-list-widget-{$args['widget_id']}";
300
+ $form_class_id = "list-form-{$args['widget_id']}";
301
+
302
+ // List addresses from the plugin config
303
+ $list_addresses = array_map('trim', explode(',', $list_address));
304
+
305
+ // All list info from the API; used for list info when more than one list is available to subscribe to
306
+ $all_list_addresses = $this->get_lists();
307
+ ?>
308
+ <div class="mailgun-list-widget-front <?php echo $widget_class_id; ?> widget">
309
+ <form class="list-form <?php echo $form_class_id; ?>">
310
+ <div class="mailgun-list-widget-inputs">
311
+ <?php if (isset($args[ 'list_title' ])): ?>
312
+ <div class="mailgun-list-title">
313
+ <h4 class="widget-title">
314
+ <span><?php echo $args[ 'list_title' ]; ?></span>
315
+ </h4>
316
+ </div>
317
+ <?php endif; ?>
318
+ <?php if (isset($args[ 'list_description' ])): ?>
319
+ <div class="mailgun-list-description">
320
+ <p class="widget-description">
321
+ <span><?php echo $args[ 'list_description' ]; ?></span>
322
+ </p>
323
+ </div>
324
+ <?php endif; ?>
325
+ <?php if (isset($args[ 'collect_name' ]) && intval($args[ 'collect_name' ]) === 1): ?>
326
+ <p class="mailgun-list-widget-name">
327
+ <strong>Name:</strong>
328
+ <input type="text" name="name"/>
329
+ </p>
330
+ <?php endif; ?>
331
+ <p class="mailgun-list-widget-email">
332
+ <strong>Email:</strong>
333
+ <input type="text" name="email"/>
334
+ </p>
335
+ </div>
336
+
337
+ <?php if (count($list_addresses) > '1'): ?>
338
+ <ul class="mailgun-lists" style="list-style: none;">
339
+ <?php
340
+ foreach ($all_list_addresses as $la):
341
+ if (!in_array($la[ 'address' ], $list_addresses)):
342
+ continue;
343
+ endif;
344
+ ?>
345
+ <li>
346
+ <input type="checkbox" class="mailgun-list-name"
347
+ name="addresses[<?php echo $la[ 'address' ]; ?>]"/> <?php echo $la[ 'name' ]; ?>
348
+ </li>
349
+ <?php endforeach; ?>
350
+ </ul>
351
+ <?php else: ?>
352
+ <input type="hidden" name="addresses[<?php echo $list_addresses[ 0 ]; ?>]" value="on"/>
353
+ <?php endif; ?>
354
+
355
+ <input class="mailgun-list-submit-button" data-form-id="<?php echo $form_class_id; ?>" type="button"
356
+ value="Subscribe"/>
357
+ <input type="hidden" name="mailgun-submission" value="1"/>
358
+
359
+ </form>
360
+ <div class="widget-list-panel result-panel" style="display:none;">
361
+ <span>Thank you for subscribing!</span>
362
+ </div>
363
+ </div>
364
+
365
+ <script>
366
+ jQuery(document).ready(function () {
367
+
368
+ jQuery('.mailgun-list-submit-button').on('click', function () {
369
+
370
+ var form_id = jQuery(this).data('form-id')
371
+
372
+ if (jQuery('.mailgun-list-name').length > 0 && jQuery('.' + form_id + ' .mailgun-list-name:checked').length < 1) {
373
+ alert('Please select a list to subscribe to.')
374
+ return
375
+ }
376
+
377
+ if (jQuery('.' + form_id + ' .mailgun-list-widget-name input') && jQuery('.' + form_id + ' .mailgun-list-widget-name input').val() === '') {
378
+ alert('Please enter your subscription name.')
379
+ return
380
+ }
381
+
382
+ if (jQuery('.' + form_id + ' .mailgun-list-widget-email input').val() === '') {
383
+ alert('Please enter your subscription email.')
384
+ return
385
+ }
386
+
387
+ jQuery.ajax({
388
  url: '<?php echo admin_url('admin-ajax.php?action=add_list'); ?>',
389
+ action: 'add_list',
390
  type: 'post',
391
  dataType: 'json',
392
+ data: jQuery('.' + form_id + '').serialize(),
393
+ success: function (data) {
394
+
395
+ data_msg = data.message
396
+ already_exists = false
397
+ if (data_msg !== undefined) {
398
+ already_exists = data_msg.indexOf('Address already exists') > -1
399
+ }
400
+
401
+ // success
402
+ if ((data.status === 200)) {
403
+ jQuery('.<?php echo $widget_class_id; ?> .widget-list-panel').css('display', 'none')
404
+ jQuery('.<?php echo $widget_class_id; ?> .list-form').css('display', 'none')
405
+ jQuery('.<?php echo $widget_class_id; ?> .result-panel').css('display', 'block')
406
  // error
407
+ } else {
408
+ alert(data_msg)
409
+ }
410
  }
411
+ })
412
+ })
413
+ })
414
+ </script>
415
+
416
+ <?php
417
+ }
418
+
419
+ /**
420
+ * Initialize List Form.
421
+ *
422
+ * @param array $atts Form attributes
423
+ *
424
+ * @return string
425
+ *
426
+ * @since 0.1
427
+ */
428
+ public function build_list_form($atts)
429
+ {
430
+ if (isset($atts[ 'id' ]) && $atts[ 'id' ] != ''):
431
+ $args[ 'widget_id' ] = md5(rand(10000, 99999) + $atts[ 'id' ]);
432
+
433
+ if (isset($atts[ 'collect_name' ])):
434
+ $args[ 'collect_name' ] = true;
435
+ endif;
436
+
437
+ if (isset($atts[ 'title' ])):
438
+ $args[ 'list_title' ] = $atts[ 'title' ];
439
+ endif;
440
+
441
+ if (isset($atts[ 'description' ])):
442
+ $args[ 'list_description' ] = $atts[ 'description' ];
443
+ endif;
444
+
445
+ ob_start();
446
+ $this->list_form($atts[ 'id' ], $args);
447
+ $output_string = ob_get_contents();
448
+ ob_end_clean();
449
+
450
+ return $output_string;
451
+ else:
452
+ ?>
453
+ <span>Mailgun list ID needed to render form!</span>
454
+ <br/>
455
+ <strong>Example :</strong> [mailgun id="[your list id]"]
456
+ <?php
457
+ endif;
458
+ }
459
+
460
+ /**
461
+ * Initialize List Widget.
462
+ *
463
+ * @since 0.1
464
+ */
465
+ public function load_list_widget()
466
+ {
467
+ register_widget('list_widget');
468
+ add_shortcode('mailgun', array(&$this, 'build_list_form'));
469
+ }
470
+ }
471
+
472
+ $mailgun = new Mailgun();
473
+
474
+ if (@include dirname(__FILE__) . '/includes/widget.php'):
475
+ add_action('widgets_init', array(&$mailgun, 'load_list_widget'));
476
+ add_action('wp_ajax_nopriv_add_list', array(&$mailgun, 'add_list'));
477
+ add_action('wp_ajax_add_list', array(&$mailgun, 'add_list'));
478
+ endif;
479
+
480
+ if (is_admin()):
481
+ if (@include dirname(__FILE__) . '/includes/admin.php'):
482
+ $mailgunAdmin = new MailgunAdmin();
483
+ else:
484
+ Mailgun::deactivate_and_die(dirname(__FILE__) . '/includes/admin.php');
485
+ endif;
486
+ endif;
 
 
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Contributors: Mailgun, sivel, lookahead.io, m35dev
5
  Tags: mailgun, smtp, http, api, mail, email
6
  Requires at least: 3.3
7
  Tested up to: 4.9.8
8
- Stable tag: 1.5.14
9
  License: GPLv2 or later
10
 
11
 
@@ -54,7 +54,8 @@ Yes, using the following constants that can be placed in wp-config.php:
54
 
55
  `
56
  MAILGUN_REGION Type: string Choices: 'us' or 'eu'
57
- MAILGUN_USEAPI Type: boolean
 
58
  MAILGUN_APIKEY Type: string
59
  MAILGUN_DOMAIN Type: string
60
  MAILGUN_USERNAME Type: string
@@ -128,6 +129,12 @@ MAILGUN_FROM_ADDRESS Type: string
128
 
129
  == Changelog ==
130
 
 
 
 
 
 
 
131
  = 1.5.14 (2018-09-11): =
132
  - Force SSL-secured SMTP connections to use port 465 (SMTPS) to connect, 587 for plain and TLS
133
  - Support region endpoint switching for SMTP
5
  Tags: mailgun, smtp, http, api, mail, email
6
  Requires at least: 3.3
7
  Tested up to: 4.9.8
8
+ Stable tag: 1.6
9
  License: GPLv2 or later
10
 
11
 
54
 
55
  `
56
  MAILGUN_REGION Type: string Choices: 'us' or 'eu'
57
+ ex. define('MAILGUN_REGION', 'us');
58
+ MAILGUN_USEAPI Type: boolean Choices: '0' or '1' (0 = false/no)
59
  MAILGUN_APIKEY Type: string
60
  MAILGUN_DOMAIN Type: string
61
  MAILGUN_USERNAME Type: string
129
 
130
  == Changelog ==
131
 
132
+ = 1.6 (2018-9-21): =
133
+ - Refactor admin notifications
134
+ - Enable Settings page for all WordPress install types
135
+ - Enable Test Configuration for all WordPress install types
136
+ - Test plugin up to WordPress 4.9.8.
137
+
138
  = 1.5.14 (2018-09-11): =
139
  - Force SSL-secured SMTP connections to use port 465 (SMTPS) to connect, 587 for plain and TLS
140
  - Support region endpoint switching for SMTP