Mailgun for WordPress - Version 1.5.12

Version Description

(2018-08-02) - Add EU endpoint for Mailgun HTTP API - Fix broken logo image on Lists page - Test plugin up to Wordpress 4.9.7

Download this release

Release Info

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

Code changes from version 1.5.8.6 to 1.5.12

CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
  Changelog
2
  =========
3
 
 
 
 
 
 
4
  1.5.11 (2018-05-30):
5
  - Fix an issue with authentication failing for newer API keys
6
  - Test plugin up to Wordpress 4.9.6
1
  Changelog
2
  =========
3
 
4
+ 1.5.12 (2018-08-02)
5
+ - Add EU endpoint for Mailgun HTTP API
6
+ - Fix broken logo image on Lists page
7
+ - Test plugin up to Wordpress 4.9.7
8
+
9
  1.5.11 (2018-05-30):
10
  - Fix an issue with authentication failing for newer API keys
11
  - Test plugin up to Wordpress 4.9.6
includes/admin.php CHANGED
@@ -22,16 +22,16 @@
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 none
33
  *
34
- * @since 0.1
35
  */
36
  public function __construct()
37
  {
@@ -58,9 +58,9 @@ class MailgunAdmin extends Mailgun
58
  /**
59
  * Initialize the default options during plugin activation.
60
  *
61
- * @return none
62
  *
63
- * @since 0.1
64
  */
65
  public function init()
66
  {
@@ -70,6 +70,7 @@ class MailgunAdmin extends Mailgun
70
  }
71
 
72
  $this->defaults = array(
 
73
  'useAPI' => '1',
74
  'apiKey' => '',
75
  'domain' => '',
@@ -92,9 +93,9 @@ class MailgunAdmin extends Mailgun
92
  /**
93
  * Add the options page.
94
  *
95
- * @return none
96
  *
97
- * @since 0.1
98
  */
99
  public function admin_menu()
100
  {
@@ -110,9 +111,9 @@ class MailgunAdmin extends Mailgun
110
  /**
111
  * Enqueue javascript required for the admin settings page.
112
  *
113
- * @return none
114
  *
115
- * @since 0.1
116
  */
117
  public function admin_js()
118
  {
@@ -122,7 +123,7 @@ class MailgunAdmin extends Mailgun
122
  /**
123
  * Output JS to footer for enhanced admin page functionality.
124
  *
125
- * @since 0.1
126
  */
127
  public function admin_footer_js()
128
  {
@@ -188,9 +189,9 @@ class MailgunAdmin extends Mailgun
188
  /**
189
  * Output the options page.
190
  *
191
- * @return none
192
  *
193
- * @since 0.1
194
  */
195
  public function options_page()
196
  {
@@ -202,9 +203,9 @@ class MailgunAdmin extends Mailgun
202
  /**
203
  * Output the lists page.
204
  *
205
- * @return none
206
  *
207
- * @since 0.1
208
  */
209
  public function lists_page()
210
  {
@@ -220,13 +221,14 @@ class MailgunAdmin extends Mailgun
220
  * and potentially register an admin notice if the plugin hasn't
221
  * been configured yet.
222
  *
223
- * @return none
224
  *
225
- * @since 0.1
226
  */
227
  public function admin_init()
228
  {
229
  $this->register_settings();
 
230
  $apiKey = $this->get_option('apiKey');
231
  $useAPI = $this->get_option('useAPI');
232
  $password = $this->get_option('password');
@@ -237,9 +239,9 @@ class MailgunAdmin extends Mailgun
237
  /**
238
  * Whitelist the mailgun options.
239
  *
240
- * @since 0.1
241
- *
242
- * @return none
243
  */
244
  public function register_settings()
245
  {
@@ -249,11 +251,11 @@ class MailgunAdmin extends Mailgun
249
  /**
250
  * Data validation callback function for options.
251
  *
252
- * @param array $options An array of options posted from the options page
253
  *
254
- * @return array
255
  *
256
- * @since 0.1
257
  */
258
  public function validation($options)
259
  {
@@ -309,9 +311,9 @@ class MailgunAdmin extends Mailgun
309
  * Function to output an admin notice when the plugin has not
310
  * been configured yet.
311
  *
312
- * @return none
313
  *
314
- * @since 0.1
315
  */
316
  public function admin_notices()
317
  {
@@ -344,11 +346,11 @@ class MailgunAdmin extends Mailgun
344
  /**
345
  * Add a settings link to the plugin actions.
346
  *
347
- * @param array $links Array of the plugin action links
348
  *
349
- * @return array
350
  *
351
- * @since 0.1
352
  */
353
  public function filter_plugin_actions($links)
354
  {
@@ -361,9 +363,9 @@ class MailgunAdmin extends Mailgun
361
  /**
362
  * AJAX callback function to test mail sending functionality.
363
  *
364
- * @return string
365
  *
366
- * @since 0.1
367
  */
368
  public function ajax_send_test()
369
  {
@@ -382,10 +384,24 @@ class MailgunAdmin extends Mailgun
382
  );
383
  }
384
 
 
385
  $useAPI = (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI) ? MAILGUN_USEAPI : $this->get_option('useAPI');
386
  $secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
387
  $sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  if ((bool) $useAPI) {
390
  $method = __('HTTP API', 'mailgun');
391
  } else {
@@ -399,7 +415,7 @@ class MailgunAdmin extends Mailgun
399
  $result = wp_mail(
400
  $admin_email,
401
  __('Mailgun WordPress Plugin Test', 'mailgun'),
402
- 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 method used to send this email was: %s.", 'mailgun'), $method),
403
  array('Content-Type: text/plain')
404
  );
405
 
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
  {
58
  /**
59
  * Initialize the default options during plugin activation.
60
  *
61
+ * @return void
62
  *
63
+ * @since 0.1
64
  */
65
  public function init()
66
  {
70
  }
71
 
72
  $this->defaults = array(
73
+ 'region' => '0',
74
  'useAPI' => '1',
75
  'apiKey' => '',
76
  'domain' => '',
93
  /**
94
  * Add the options page.
95
  *
96
+ * @return void
97
  *
98
+ * @since 0.1
99
  */
100
  public function admin_menu()
101
  {
111
  /**
112
  * Enqueue javascript required for the admin settings page.
113
  *
114
+ * @return void
115
  *
116
+ * @since 0.1
117
  */
118
  public function admin_js()
119
  {
123
  /**
124
  * Output JS to footer for enhanced admin page functionality.
125
  *
126
+ * @since 0.1
127
  */
128
  public function admin_footer_js()
129
  {
189
  /**
190
  * Output the options page.
191
  *
192
+ * @return void
193
  *
194
+ * @since 0.1
195
  */
196
  public function options_page()
197
  {
203
  /**
204
  * Output the lists page.
205
  *
206
+ * @return void
207
  *
208
+ * @since 0.1
209
  */
210
  public function lists_page()
211
  {
221
  * and potentially register an admin notice if the plugin hasn't
222
  * been configured yet.
223
  *
224
+ * @return void
225
  *
226
+ * @since 0.1
227
  */
228
  public function admin_init()
229
  {
230
  $this->register_settings();
231
+ $region = $this->get_option('region');
232
  $apiKey = $this->get_option('apiKey');
233
  $useAPI = $this->get_option('useAPI');
234
  $password = $this->get_option('password');
239
  /**
240
  * Whitelist the mailgun options.
241
  *
242
+ * @return void
243
+ *
244
+ * @since 0.1
245
  */
246
  public function register_settings()
247
  {
251
  /**
252
  * Data validation callback function for options.
253
  *
254
+ * @param array $options An array of options posted from the options page
255
  *
256
+ * @return array
257
  *
258
+ * @since 0.1
259
  */
260
  public function validation($options)
261
  {
311
  * Function to output an admin notice when the plugin has not
312
  * been configured yet.
313
  *
314
+ * @return void
315
  *
316
+ * @since 0.1
317
  */
318
  public function admin_notices()
319
  {
346
  /**
347
  * Add a settings link to the plugin actions.
348
  *
349
+ * @param array $links Array of the plugin action links
350
  *
351
+ * @return array
352
  *
353
+ * @since 0.1
354
  */
355
  public function filter_plugin_actions($links)
356
  {
363
  /**
364
  * AJAX callback function to test mail sending functionality.
365
  *
366
+ * @return string
367
  *
368
+ * @since 0.1
369
  */
370
  public function ajax_send_test()
371
  {
384
  );
385
  }
386
 
387
+ $getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
388
  $useAPI = (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI) ? MAILGUN_USEAPI : $this->get_option('useAPI');
389
  $secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
390
  $sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
391
 
392
+ if ((bool) !$getRegion) {
393
+ mg_api_last_error(__("Region has not been selected", "mailgun"));
394
+ } else {
395
+
396
+ if ($getRegion === 'us') {
397
+ $region = __("U.S./North America", "mailgun");
398
+ }
399
+
400
+ if ($getRegion === "eu") {
401
+ $region = __("Europe", "mailgun");
402
+ }
403
+ }
404
+
405
  if ((bool) $useAPI) {
406
  $method = __('HTTP API', 'mailgun');
407
  } else {
415
  $result = wp_mail(
416
  $admin_email,
417
  __('Mailgun WordPress Plugin Test', 'mailgun'),
418
+ 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 %1$s.\n\nThe method used to send this email was: %2$s.', 'mailgun'), $region, $method),
419
  array('Content-Type: text/plain')
420
  );
421
 
includes/lists-page.php CHANGED
@@ -44,7 +44,7 @@ $lists_arr = $mailgun->get_lists();
44
 
45
  <span class="alignright">
46
  <a target="_blank" href="http://www.mailgun.com/">
47
- <img src="https://www.mailgun.com/static/img/mailgun.svg" alt="Mailgun" style="width: 10em;"/>
48
  </a>
49
  </span>
50
 
44
 
45
  <span class="alignright">
46
  <a target="_blank" href="http://www.mailgun.com/">
47
+ <img src="https://assets.mailgun.com/img/mailgun.svg" alt="Mailgun" style="width: 10em;"/>
48
  </a>
49
  </span>
50
 
includes/mg-filter.php CHANGED
@@ -22,12 +22,12 @@
22
  /**
23
  * Tries several methods to get the MIME Content-Type of a file.
24
  *
25
- * @param string $filepath
26
- * @param string $default_type If all methods fail, fallback to $default_type
27
  *
28
- * @return string Content-Type
29
  *
30
- * @since 1.5.4
31
  */
32
  function get_mime_content_type($filepath, $default_type = 'text/plain')
33
  {
@@ -58,9 +58,9 @@ function get_mime_content_type($filepath, $default_type = 'text/plain')
58
  * `$from_addr` before being returned. The filtered result is null-tested
59
  * before being returned.
60
  *
61
- * @return string
62
  *
63
- * @since 1.5.8
64
  */
65
  function mg_detect_from_name($from_name_header = null)
66
  {
@@ -123,13 +123,11 @@ function mg_detect_from_name($from_name_header = null)
123
  * might appear to be another option but some hosts may refuse to
124
  * relay mail from an unknown domain.
125
  *
126
- * @link http://trac.wordpress.org/ticket/5007.
127
  *
128
- * @param string $from_addr_header From address given by a header.
129
  *
130
- * @return string
131
- *
132
- * @since 1.5.8
133
  */
134
  function mg_detect_from_address($from_addr_header = null)
135
  {
@@ -194,11 +192,11 @@ function mg_detect_from_address($from_addr_header = null)
194
  * )
195
  * )
196
  *
197
- * @param string|array $headers
198
  *
199
- * @return array
200
  *
201
- * @since 1.5.8
202
  */
203
  function mg_parse_headers($headers = array())
204
  {
@@ -259,11 +257,11 @@ function mg_parse_headers($headers = array())
259
  * Takes a header array in the format produced by mg_parse_headers and
260
  * dumps them down in to a submittable header format.
261
  *
262
- * @param array $headers Headers to dump
263
  *
264
- * @return string String of \r\n separated headers
265
  *
266
- * @since 1.5.8
267
  */
268
  function mg_dump_headers($headers = null)
269
  {
@@ -287,3 +285,26 @@ function mg_dump_headers($headers = null)
287
  return $header_string;
288
  }
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  /**
23
  * Tries several methods to get the MIME Content-Type of a file.
24
  *
25
+ * @param string $filepath
26
+ * @param string $default_type If all methods fail, fallback to $default_type
27
  *
28
+ * @return string Content-Type
29
  *
30
+ * @since 1.5.4
31
  */
32
  function get_mime_content_type($filepath, $default_type = 'text/plain')
33
  {
58
  * `$from_addr` before being returned. The filtered result is null-tested
59
  * before being returned.
60
  *
61
+ * @return string
62
  *
63
+ * @since 1.5.8
64
  */
65
  function mg_detect_from_name($from_name_header = null)
66
  {
123
  * might appear to be another option but some hosts may refuse to
124
  * relay mail from an unknown domain.
125
  *
126
+ * @link http://trac.wordpress.org/ticket/5007.
127
  *
128
+ * @return string
129
  *
130
+ * @since 1.5.8
 
 
131
  */
132
  function mg_detect_from_address($from_addr_header = null)
133
  {
192
  * )
193
  * )
194
  *
195
+ * @param string|array $headers
196
  *
197
+ * @return array
198
  *
199
+ * @since 1.5.8
200
  */
201
  function mg_parse_headers($headers = array())
202
  {
257
  * Takes a header array in the format produced by mg_parse_headers and
258
  * dumps them down in to a submittable header format.
259
  *
260
+ * @param array $headers Headers to dump
261
  *
262
+ * @return string String of \r\n separated headers
263
  *
264
+ * @since 1.5.8
265
  */
266
  function mg_dump_headers($headers = null)
267
  {
285
  return $header_string;
286
  }
287
 
288
+ /**
289
+ * Set the API endpoint based on the region selected.
290
+ * Value can be "0" if not selected, "us" or "eu"
291
+ *
292
+ * @param string $getRegion Region value set either in config or Mailgun plugin settings.
293
+ *
294
+ * @return bool|string
295
+ *
296
+ * @since 1.5.12
297
+ */
298
+ function mg_detect_region($getRegion)
299
+ {
300
+ if ($getRegion === 'us') {
301
+ return 'https://api.mailgun.net/v3/';
302
+ }
303
+
304
+ if ($getRegion === 'eu') {
305
+ return 'https://api.eu.mailgun.net/v3/';
306
+ }
307
+
308
+ return false;
309
+ }
310
+
includes/options-page.php CHANGED
@@ -30,6 +30,19 @@
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 _e('Use HTTP API', 'mailgun'); ?>
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 _e('Select Your Region', 'mailgun'); ?>
36
+ </th>
37
+ <td>
38
+ <select id="mailgun-region" name="mailgun[region]">
39
+ <option value="0"<?php selected('0', $this->get_option('region')); ?>><?php _e('Select', 'mailgun') ?></option>
40
+ <option value="us"<?php selected('us', $this->get_option('region')); ?>><?php _e('U.S./North America', 'mailgun') ?></option>
41
+ <option value="eu"<?php selected('eu', $this->get_option('region')); ?>><?php _e('Europe', 'mailgun') ?></option>
42
+ </select>
43
+ <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.', 'mailgun') ?></p>
44
+ </td>
45
+ </tr>
46
  <tr valign="top">
47
  <th scope="row">
48
  <?php _e('Use HTTP API', 'mailgun'); ?>
includes/wp-mail-api.php CHANGED
@@ -28,11 +28,11 @@ if (!include dirname(__FILE__).'/mg-filter.php') {
28
  * mg_api_last_error is a compound getter/setter for the last error that was
29
  * encountered during a Mailgun API call.
30
  *
31
- * @param string $error OPTIONAL
32
  *
33
- * @return string Last error that occurred.
34
  *
35
- * @since 1.5.0
36
  */
37
  function mg_api_last_error($error = null)
38
  {
@@ -98,15 +98,15 @@ function mg_mutate_to_rcpt_vars_cb($to_addrs)
98
  * Based off of the core wp_mail function, but with modifications required to
99
  * send email using the Mailgun HTTP API
100
  *
101
- * @param string|array $to Array or comma-separated list of email addresses to send message.
102
- * @param string $subject Email subject
103
- * @param string $message Message contents
104
- * @param string|array $headers Optional. Additional headers.
105
- * @param string|array $attachments Optional. Files to attach.
106
  *
107
- * @return bool Whether the email contents were sent successfully.
108
  *
109
- * @since 0.1
110
  */
111
  function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
112
  {
@@ -114,12 +114,13 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
114
  extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
115
 
116
  $mailgun = get_option('mailgun');
 
117
  $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $mailgun['apiKey'];
118
  $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $mailgun['domain'];
119
 
120
- if (empty($apiKey) || empty($domain)) {
121
- return false;
122
- }
123
 
124
  if (!is_array($attachments)) {
125
  $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
@@ -341,7 +342,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
341
  // // }
342
  // }
343
 
344
- // Allow other plugins to apply attachent changes before writing to the payload.
345
  $attachments = apply_filters('mg_mutate_attachments', $attachments);
346
  if ( ($attachment_payload = mg_build_attachments_payload($attachments, $boundary)) != null ) {
347
  $payload .= $attachment_payload;
@@ -357,7 +358,14 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
357
  ),
358
  );
359
 
360
- $url = "https://api.mailgun.net/v3/{$domain}/messages";
 
 
 
 
 
 
 
361
 
362
  // TODO: Mailgun only supports 1000 recipients per request, since we are
363
  // overriding this function, let's add looping here to handle that
28
  * mg_api_last_error is a compound getter/setter for the last error that was
29
  * encountered during a Mailgun API call.
30
  *
31
+ * @param string $error OPTIONAL
32
  *
33
+ * @return string Last error that occurred.
34
  *
35
+ * @since 1.5.0
36
  */
37
  function mg_api_last_error($error = null)
38
  {
98
  * Based off of the core wp_mail function, but with modifications required to
99
  * send email using the Mailgun HTTP API
100
  *
101
+ * @param string|array $to Array or comma-separated list of email addresses to send message.
102
+ * @param string $subject Email subject
103
+ * @param string $message Message contents
104
+ * @param string|array $headers Optional. Additional headers.
105
+ * @param string|array $attachments Optional. Files to attach.
106
  *
107
+ * @return bool Whether the email contents were sent successfully.
108
  *
109
+ * @since 0.1
110
  */
111
  function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
112
  {
114
  extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
115
 
116
  $mailgun = get_option('mailgun');
117
+ $getRegion = (defined('MAILGUN_REGION') && MAILGUNE_REGION) ? MAILGUN_REGION : $mailgun['region'];
118
  $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $mailgun['apiKey'];
119
  $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $mailgun['domain'];
120
 
121
+ if (empty($apiKey) || empty($domain) || (bool) !$getRegion) {
122
+ return false;
123
+ }
124
 
125
  if (!is_array($attachments)) {
126
  $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
342
  // // }
343
  // }
344
 
345
+ // Allow other plugins to apply attachment changes before writing to the payload.
346
  $attachments = apply_filters('mg_mutate_attachments', $attachments);
347
  if ( ($attachment_payload = mg_build_attachments_payload($attachments, $boundary)) != null ) {
348
  $payload .= $attachment_payload;
358
  ),
359
  );
360
 
361
+ $endpoint = mg_detect_region($getRegion);
362
+ if ($getRegion === 'us') {
363
+ $url = $endpoint."{$domain}/messages";
364
+ }
365
+
366
+ if ($getRegion === 'eu') {
367
+ $url = $endpoint."{$domain}/messages";
368
+ }
369
 
370
  // TODO: Mailgun only supports 1000 recipients per request, since we are
371
  // overriding this function, let's add looping here to handle that
mailgun.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Mailgun
5
  * Plugin URI: http://wordpress.org/extend/plugins/mailgun/
6
  * Description: Mailgun integration for WordPress
7
- * Version: 1.5.11
8
  * Author: Mailgun
9
  * Author URI: http://www.mailgun.com/
10
  * License: GPLv2 or later
@@ -43,16 +43,13 @@ class Mailgun
43
  /**
44
  * Setup shared functionality for Admin and Front End.
45
  *
46
- * @return none
47
- *
48
- * @since 0.1
49
  */
50
  public function __construct()
51
  {
52
  $this->options = get_option('mailgun');
53
  $this->plugin_file = __FILE__;
54
  $this->plugin_basename = plugin_basename($this->plugin_file);
55
- $this->api_endpoint = 'https://api.mailgun.net/v3/';
56
 
57
  // Either override the wp_mail function or configure PHPMailer to use the
58
  // Mailgun SMTP servers
@@ -80,11 +77,13 @@ class Mailgun
80
  /**
81
  * Get specific option from the options table.
82
  *
83
- * @param string $option Name of option to be used as array key for retrieving the specific value
 
 
84
  *
85
- * @return mixed
86
  *
87
- * @since 0.1
88
  */
89
  public function get_option($option, $options = null, $default = false)
90
  {
@@ -102,11 +101,11 @@ class Mailgun
102
  * Hook into phpmailer to override SMTP based configurations
103
  * to use the Mailgun SMTP server.
104
  *
105
- * @param object $phpmailer The PHPMailer object to modify by reference
106
  *
107
- * @return none
108
  *
109
- * @since 0.1
110
  */
111
  public function phpmailer_init(&$phpmailer)
112
  {
@@ -132,12 +131,13 @@ class Mailgun
132
 
133
  /**
134
  * Deactivate this plugin and die.
 
135
  *
136
- * Used to deactivate the plugin when files critical to it's operation can not be loaded
137
- *
138
- * @since 0.1
139
- *
140
- * @return none
141
  */
142
  public function deactivate_and_die($file)
143
  {
@@ -153,18 +153,28 @@ class Mailgun
153
  /**
154
  * Make a Mailgun api call.
155
  *
156
- * @param string $endpoint The Mailgun endpoint uri
 
 
157
  *
158
- * @return array
159
  *
160
- * @since 0.1
161
  */
162
  public function api_call($uri, $params = array(), $method = 'POST')
163
  {
164
  $options = get_option('mailgun');
165
- $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $options['apiKey'];
 
166
  $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options['domain'];
167
 
 
 
 
 
 
 
 
168
  $time = time();
169
  $url = $this->api_endpoint.$uri;
170
  $headers = array(
@@ -207,9 +217,9 @@ class Mailgun
207
  /**
208
  * Get account associated lists.
209
  *
210
- * @return array
211
  *
212
- * @since 0.1
213
  */
214
  public function get_lists()
215
  {
@@ -227,9 +237,9 @@ class Mailgun
227
  /**
228
  * Handle add list ajax post.
229
  *
230
- * @return string json
231
  *
232
- * @since 0.1
233
  */
234
  public function add_list()
235
  {
@@ -262,11 +272,11 @@ class Mailgun
262
  /**
263
  * Frontend List Form.
264
  *
265
- * @param string $list_address Mailgun address list id
266
- * @param array $args widget arguments
267
- * @param string $instance widget instance params
268
  *
269
- * @since 0.1
270
  */
271
  public function list_form($list_address, $args = array(), $instance = array())
272
  {
@@ -388,13 +398,15 @@ class Mailgun
388
 
389
  }
390
 
391
- /**
392
- * Initialize List Form.
393
- *
394
- * @param array $atts Form attributes
395
- *
396
- * @since 0.1
397
- */
 
 
398
  public function build_list_form($atts)
399
  {
400
  if (isset($atts['id']) && $atts['id'] != '') {
@@ -431,7 +443,7 @@ class Mailgun
431
  /**
432
  * Initialize List Widget.
433
  *
434
- * @since 0.1
435
  */
436
  public function load_list_widget()
437
  {
4
  * Plugin Name: Mailgun
5
  * Plugin URI: http://wordpress.org/extend/plugins/mailgun/
6
  * Description: Mailgun integration for WordPress
7
+ * Version: 1.5.12
8
  * Author: Mailgun
9
  * Author URI: http://www.mailgun.com/
10
  * License: GPLv2 or later
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
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
  {
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
  {
131
 
132
  /**
133
  * Deactivate this plugin and die.
134
+ * Deactivate the plugin when files critical to it's operation cannot be loaded
135
  *
136
+ * @param $file Files critical to plugin functionality
137
+ *
138
+ * @return void
139
+ *
140
+ * @since 0.1
141
  */
142
  public function deactivate_and_die($file)
143
  {
153
  /**
154
  * Make a Mailgun api call.
155
  *
156
+ * @param string $uri The endpoint for the Mailgun API
157
+ * @param array $params Array of parameters passed to the API
158
+ * @param string $method The form request type
159
  *
160
+ * @return array
161
  *
162
+ * @since 0.1
163
  */
164
  public function api_call($uri, $params = array(), $method = 'POST')
165
  {
166
  $options = get_option('mailgun');
167
+ $getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $options['region'];
168
+ $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $options['apiKey'];
169
  $domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options['domain'];
170
 
171
+ $region = mg_detect_region($getRegion);
172
+ if (!$region) {
173
+ mg_api_last_error(__("Region has not been selected", "mailgun"));
174
+ } else {
175
+ $this->api_endpoint = $region;
176
+ }
177
+
178
  $time = time();
179
  $url = $this->api_endpoint.$uri;
180
  $headers = array(
217
  /**
218
  * Get account associated lists.
219
  *
220
+ * @return array
221
  *
222
+ * @since 0.1
223
  */
224
  public function get_lists()
225
  {
237
  /**
238
  * Handle add list ajax post.
239
  *
240
+ * @return string json
241
  *
242
+ * @since 0.1
243
  */
244
  public function add_list()
245
  {
272
  /**
273
  * Frontend List Form.
274
  *
275
+ * @param string $list_address Mailgun address list id
276
+ * @param array $args widget arguments
277
+ * @param array $instance widget instance params
278
  *
279
+ * @since 0.1
280
  */
281
  public function list_form($list_address, $args = array(), $instance = array())
282
  {
398
 
399
  }
400
 
401
+ /**
402
+ * Initialize List Form.
403
+ *
404
+ * @param array $atts Form attributes
405
+ *
406
+ * @return string
407
+ *
408
+ * @since 0.1
409
+ */
410
  public function build_list_form($atts)
411
  {
412
  if (isset($atts['id']) && $atts['id'] != '') {
443
  /**
444
  * Initialize List Widget.
445
  *
446
+ * @since 0.1
447
  */
448
  public function load_list_widget()
449
  {
readme.txt CHANGED
@@ -4,8 +4,8 @@ Mailgun for WordPress
4
  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.6
8
- Stable tag: 1.5.11
9
  License: GPLv2 or later
10
 
11
 
@@ -18,7 +18,7 @@ Easily send email from your WordPress site through Mailgun using the HTTP API or
18
 
19
  One particularly useful feature of this plugin is that it provides you with a way to send email when the server you are on does not support SMTP or where outbound SMTP is restricted since the plug-in uses the Mailgun HTTP API for sending email by default. All you need to use the plugin is a [Mailgun account](http://www.mailgun.com/). Mailgun has a free account that lets you send up to 200 emails per day, which is great for testing. Paid subscriptions are available for increased limits.
20
 
21
- The latest version of this plugin adds support for Mailgun list subscription. Using the shortcode, you can place a form on an article or page to allow the visitor to subscribe to one or more lists. Using the widget, you can provide subscription functionality in sidebars or anywhere widgets are supported e.g. footers.
22
 
23
  The current version of this plugin only handles sending emails, tracking and tagging and list subscription.
24
 
@@ -53,6 +53,7 @@ define( 'MG_DEBUG_SMTP', true );
53
  Yes, using the following constants that can be placed in wp-config.php:
54
 
55
  `
 
56
  MAILGUN_USEAPI Type: boolean
57
  MAILGUN_APIKEY Type: string
58
  MAILGUN_DOMAIN Type: string
@@ -70,7 +71,7 @@ MAILGUN_FROM_ADDRESS Type: string
70
  Mutates messages to use recipient variables syntax - see
71
  https://documentation.mailgun.com/user_manual.html#batch-sending for more info.
72
 
73
- Should accept a list of `To` addressses.
74
 
75
  Should *only* return `true` or `false`.
76
 
@@ -95,7 +96,7 @@ MAILGUN_FROM_ADDRESS Type: string
95
  Mutates messages to use recipient variables syntax - see
96
  https://documentation.mailgun.com/user_manual.html#batch-sending for more info.
97
 
98
- Should accept a list of `To` addressses.
99
 
100
  Should *only* return `true` or `false`.
101
 
@@ -127,6 +128,11 @@ MAILGUN_FROM_ADDRESS Type: string
127
 
128
  == Changelog ==
129
 
 
 
 
 
 
130
  = 1.5.11 (2018-05-30): =
131
  - Fix an issue with authentication failing for newer API keys
132
  - Test plugin up to Wordpress 4.9.6
4
  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.7
8
+ Stable tag: 1.5.12
9
  License: GPLv2 or later
10
 
11
 
18
 
19
  One particularly useful feature of this plugin is that it provides you with a way to send email when the server you are on does not support SMTP or where outbound SMTP is restricted since the plug-in uses the Mailgun HTTP API for sending email by default. All you need to use the plugin is a [Mailgun account](http://www.mailgun.com/). Mailgun has a free account that lets you send up to 200 emails per day, which is great for testing. Paid subscriptions are available for increased limits.
20
 
21
+ The latest version of this plugin now supports regions. Select either U.S./North America or Europe to choose the API endpoint from which you will send email.
22
 
23
  The current version of this plugin only handles sending emails, tracking and tagging and list subscription.
24
 
53
  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
71
  Mutates messages to use recipient variables syntax - see
72
  https://documentation.mailgun.com/user_manual.html#batch-sending for more info.
73
 
74
+ Should accept a list of `To` addresses.
75
 
76
  Should *only* return `true` or `false`.
77
 
96
  Mutates messages to use recipient variables syntax - see
97
  https://documentation.mailgun.com/user_manual.html#batch-sending for more info.
98
 
99
+ Should accept a list of `To` addresses.
100
 
101
  Should *only* return `true` or `false`.
102
 
128
 
129
  == Changelog ==
130
 
131
+ = 1.5.12 (2018-08-02)
132
+ - Add EU endpoint for Mailgun HTTP API
133
+ - Fix broken logo image on Lists page
134
+ - Test plugin up to Wordpress 4.9.7
135
+
136
  = 1.5.11 (2018-05-30): =
137
  - Fix an issue with authentication failing for newer API keys
138
  - Test plugin up to Wordpress 4.9.6