Version Description
(2020-10-07): = - Test plugin with PHP 7.4. - Test plugin up to WordPress 5.5.1.
Download this release
Release Info
Developer | Mailgun |
Plugin | Mailgun for WordPress |
Version | 1.7.2 |
Comparing to | |
See all releases |
Code changes from version 1.5.10 to 1.7.2
- .gitignore +2 -0
- CHANGELOG.md +49 -0
- includes/admin.php +483 -431
- includes/lists-page.php +10 -10
- includes/mg-filter.php +53 -17
- includes/options-page.php +446 -197
- includes/wp-mail-api.php +59 -13
- languages/mailgun-template.po +0 -4
- mailgun.php +479 -450
- readme.txt +62 -7
.gitignore
CHANGED
@@ -1 +1,3 @@
|
|
1 |
svn/
|
|
|
|
1 |
svn/
|
2 |
+
.idea/
|
3 |
+
docker-compose.yaml
|
CHANGELOG.md
CHANGED
@@ -1,6 +1,55 @@
|
|
1 |
Changelog
|
2 |
=========
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
1.5.10 (2017-11-22):
|
5 |
- Fix back to settings link on lists page (https://github.com/mailgun/wordpress-plugin/pull/65)
|
6 |
- Fix a bug causing `text/html` emails to send as both `text/plain` *and* `text/html` parts
|
1 |
Changelog
|
2 |
=========
|
3 |
|
4 |
+
1.7.1 (2019-02-07)
|
5 |
+
- Reinstall settings page for multisites.
|
6 |
+
|
7 |
+
1.7 (2019-01-21)
|
8 |
+
- Remove settings page for multisites.
|
9 |
+
- Simplify admin notifications.
|
10 |
+
- Test plugin with PHP 7.2.
|
11 |
+
- Test plugin up to WordPress 5.0.3.
|
12 |
+
|
13 |
+
1.6.1 (2018-10-08)
|
14 |
+
- Restore Settings page form for all install types.
|
15 |
+
|
16 |
+
1.6 (2018-9-21)
|
17 |
+
- Refactor admin notifications
|
18 |
+
- Enable Settings page for all WordPress install types
|
19 |
+
- Enable Test Configuration for all WordPress install types
|
20 |
+
- Test plugin up to WordPress 4.9.8.
|
21 |
+
|
22 |
+
1.5.14 (2018-09-11)
|
23 |
+
- Force SSL-secured SMTP connections to use port 465 (SMTPS) to connect, 587 for plain and TLS
|
24 |
+
- Support region endpoint switching for SMTP
|
25 |
+
|
26 |
+
1.5.13.1 (2018-08-15)
|
27 |
+
- Fix line breaks in Test Configuration email
|
28 |
+
|
29 |
+
1.5.13 (2018-08-14)
|
30 |
+
- Default to US region if no region is configured in settings
|
31 |
+
- Add admin notification about region configuration
|
32 |
+
- Log an error message when an email is sent with no explicit region configured
|
33 |
+
|
34 |
+
1.5.12.3 (2018-08-09)
|
35 |
+
- Fix Region select menu default when wp-config.php variable is set
|
36 |
+
- Fix front end email input validation
|
37 |
+
|
38 |
+
1.5.12.2 (2018-08-09)
|
39 |
+
- Fix plugin not saving after update
|
40 |
+
|
41 |
+
1.5.12.1 (2018-08-06)
|
42 |
+
- Fix for backwards compatibility
|
43 |
+
|
44 |
+
1.5.12 (2018-08-02)
|
45 |
+
- Add EU endpoint for Mailgun HTTP API
|
46 |
+
- Fix broken logo image on Lists page
|
47 |
+
- Test plugin up to Wordpress 4.9.7
|
48 |
+
|
49 |
+
1.5.11 (2018-05-30):
|
50 |
+
- Fix an issue with authentication failing for newer API keys
|
51 |
+
- Test plugin up to Wordpress 4.9.6
|
52 |
+
|
53 |
1.5.10 (2017-11-22):
|
54 |
- Fix back to settings link on lists page (https://github.com/mailgun/wordpress-plugin/pull/65)
|
55 |
- Fix a bug causing `text/html` emails to send as both `text/plain` *and* `text/html` parts
|
includes/admin.php
CHANGED
@@ -1,441 +1,493 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
class MailgunAdmin extends Mailgun
|
23 |
-
{
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
136 |
} else {
|
137 |
-
|
138 |
-
|
139 |
}
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
mailgunApiOrNot()
|
145 |
-
jQuery('#mailgun-api').change(function() {
|
146 |
-
|
147 |
-
})
|
148 |
-
jQuery('#mailgun-test').click(function(e) {
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
}
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
})
|
168 |
-
.
|
169 |
-
|
170 |
-
'Mailgun ' + data.method + ' Test ' + data.message
|
171 |
-
+ '; status "' + data.error + '"'
|
172 |
-
);
|
173 |
})
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
})
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
});
|
182 |
-
/* ]]> */
|
183 |
-
</script>
|
184 |
-
<?php
|
185 |
-
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Output the options page.
|
190 |
-
*
|
191 |
-
* @return none
|
192 |
-
*
|
193 |
-
* @since 0.1
|
194 |
-
*/
|
195 |
-
public function options_page()
|
196 |
-
{
|
197 |
-
if (!@include 'options-page.php') {
|
198 |
-
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');
|
199 |
-
}
|
200 |
-
}
|
201 |
-
|
202 |
-
/**
|
203 |
-
* Output the lists page.
|
204 |
-
*
|
205 |
-
* @return none
|
206 |
-
*
|
207 |
-
* @since 0.1
|
208 |
-
*/
|
209 |
-
public function lists_page()
|
210 |
-
{
|
211 |
-
if (!@include 'lists-page.php') {
|
212 |
-
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');
|
213 |
-
}
|
214 |
-
}
|
215 |
-
|
216 |
-
// /options-general.php?page=mailgun-lists
|
217 |
-
|
218 |
-
/**
|
219 |
-
* Wrapper function hooked into admin_init to register settings
|
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');
|
233 |
-
|
234 |
-
add_action('admin_notices', array(&$this, 'admin_notices'));
|
235 |
-
}
|
236 |
-
|
237 |
-
/**
|
238 |
-
* Whitelist the mailgun options.
|
239 |
-
*
|
240 |
-
* @since 0.1
|
241 |
-
*
|
242 |
-
* @return none
|
243 |
-
*/
|
244 |
-
public function register_settings()
|
245 |
-
{
|
246 |
-
register_setting('mailgun', 'mailgun', array(&$this, 'validation'));
|
247 |
-
}
|
248 |
-
|
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 |
-
{
|
260 |
-
$apiKey = trim($options['apiKey']);
|
261 |
-
$username = trim($options['username']);
|
262 |
-
if (!empty($apiKey)) {
|
263 |
-
$pos = strpos($apiKey, 'key-');
|
264 |
-
if ($pos === false || $pos > 4) {
|
265 |
-
$apiKey = "key-{$apiKey}";
|
266 |
-
}
|
267 |
-
|
268 |
-
$pos = strpos($apiKey, 'api:');
|
269 |
-
if ($pos !== false && $pos == 0) {
|
270 |
-
$apiKey = substr($apiKey, 4);
|
271 |
-
}
|
272 |
-
$options['apiKey'] = $apiKey;
|
273 |
-
}
|
274 |
-
|
275 |
-
if (!empty($username)) {
|
276 |
-
$username = preg_replace('/@.+$/', '', $username);
|
277 |
-
$options['username'] = $username;
|
278 |
-
}
|
279 |
-
|
280 |
-
foreach ($options as $key => $value) {
|
281 |
-
$options[$key] = trim($value);
|
282 |
-
}
|
283 |
-
|
284 |
-
if (empty($options['override-from'])) {
|
285 |
-
$options['override-from'] = $this->defaults['override-from'];
|
286 |
-
}
|
287 |
-
|
288 |
-
if (empty($options['sectype'])) {
|
289 |
-
$options['sectype'] = $this->defaults['sectype'];
|
290 |
-
}
|
291 |
-
// alternatively:
|
292 |
-
// foreach ($defaults as $key => $value) {
|
293 |
-
// if (empty($options[$key])) {
|
294 |
-
// $options[$key] = $value;
|
295 |
-
// }
|
296 |
-
// }
|
297 |
-
|
298 |
-
$this->options = $options;
|
299 |
-
|
300 |
-
return $options;
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Function to output an admin notice when the plugin has not
|
305 |
-
* been configured yet.
|
306 |
-
*
|
307 |
-
* @return none
|
308 |
-
*
|
309 |
-
* @since 0.1
|
310 |
-
*/
|
311 |
-
public function admin_notices()
|
312 |
-
{
|
313 |
-
$screen = get_current_screen();
|
314 |
-
if (!current_user_can('manage_options') || $screen->id == $this->hook_suffix
|
315 |
-
) {
|
316 |
-
return;
|
317 |
-
}
|
318 |
-
|
319 |
-
if ((!$this->get_option('apiKey') && $this->get_option('useAPI') === '1')
|
320 |
-
|| (!$this->get_option('password') && $this->get_option('useAPI') === '0')
|
321 |
-
) {
|
322 |
-
?>
|
323 |
-
<div id='mailgun-warning' class='notice notice-warning fade'><p><strong><?php _e('Mailgun is almost ready. ', 'mailgun'); ?></strong><?php printf(__('You must <a href="%1$s">configure Mailgun</a> for it to work.', 'mailgun'), menu_page_url('mailgun', false)); ?></p></div>
|
324 |
<?php
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
<?php
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* Output the options page.
|
194 |
+
*
|
195 |
+
* @return void
|
196 |
+
*
|
197 |
+
* @since 0.1
|
198 |
+
*/
|
199 |
+
public function options_page()
|
200 |
+
{
|
201 |
+
if (!@include 'options-page.php'):
|
202 |
+
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>',
|
203 |
+
'mailgun'), dirname(__FILE__) . '/options-page.php');
|
204 |
+
endif;
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Output the lists page.
|
209 |
+
*
|
210 |
+
* @return void
|
211 |
+
*
|
212 |
+
* @since 0.1
|
213 |
+
*/
|
214 |
+
public function lists_page()
|
215 |
+
{
|
216 |
+
if (!@include 'lists-page.php'):
|
217 |
+
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>',
|
218 |
+
'mailgun'), dirname(__FILE__) . '/lists-page.php');
|
219 |
+
endif;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Wrapper function hooked into admin_init to register settings
|
224 |
+
* and potentially register an admin notice if the plugin hasn't
|
225 |
+
* been configured yet.
|
226 |
+
*
|
227 |
+
* @return void
|
228 |
+
*
|
229 |
+
* @since 0.1
|
230 |
+
*/
|
231 |
+
public function admin_init()
|
232 |
+
{
|
233 |
+
$this->register_settings();
|
234 |
+
$region = $this->get_option('region');
|
235 |
+
$apiKey = $this->get_option('apiKey');
|
236 |
+
$useAPI = $this->get_option('useAPI');
|
237 |
+
$password = $this->get_option('password');
|
238 |
+
|
239 |
+
add_action('admin_notices', array(&$this, 'admin_notices'));
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Whitelist the mailgun options.
|
244 |
+
*
|
245 |
+
* @return void
|
246 |
+
*
|
247 |
+
* @since 0.1
|
248 |
+
*/
|
249 |
+
public function register_settings()
|
250 |
+
{
|
251 |
+
register_setting('mailgun', 'mailgun', array(&$this, 'validation'));
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Data validation callback function for options.
|
256 |
+
*
|
257 |
+
* @param array $options An array of options posted from the options page
|
258 |
+
*
|
259 |
+
* @return array
|
260 |
+
*
|
261 |
+
* @since 0.1
|
262 |
+
*/
|
263 |
+
public function validation($options)
|
264 |
+
{
|
265 |
+
$apiKey = trim($options[ 'apiKey' ]);
|
266 |
+
$username = trim($options[ 'username' ]);
|
267 |
+
if (!empty($apiKey)):
|
268 |
+
$pos = strpos($apiKey, 'api:');
|
269 |
+
if ($pos !== false && $pos == 0):
|
270 |
+
$apiKey = substr($apiKey, 4);
|
271 |
+
endif;
|
272 |
+
|
273 |
+
if (1 === preg_match('(\w{32}-\w{8}-\w{8})', $apiKey)):
|
274 |
+
$options[ 'apiKey' ] = $apiKey;
|
275 |
+
else:
|
276 |
+
$pos = strpos($apiKey, 'key-');
|
277 |
+
if ($pos === false || $pos > 4):
|
278 |
+
$apiKey = "key-{$apiKey}";
|
279 |
+
endif;
|
280 |
+
|
281 |
+
$options[ 'apiKey' ] = $apiKey;
|
282 |
+
endif;
|
283 |
+
endif;
|
284 |
+
|
285 |
+
if (!empty($username)):
|
286 |
+
$username = preg_replace('/@.+$/', '', $username);
|
287 |
+
$options[ 'username' ] = $username;
|
288 |
+
endif;
|
289 |
+
|
290 |
+
foreach ($options as $key => $value) {
|
291 |
+
$options[ $key ] = trim($value);
|
292 |
+
}
|
293 |
+
|
294 |
+
if (empty($options[ 'override-from' ])):
|
295 |
+
$options[ 'override-from' ] = $this->defaults[ 'override-from' ];
|
296 |
+
endif;
|
297 |
+
|
298 |
+
if (empty($options[ 'sectype' ])):
|
299 |
+
$options[ 'sectype' ] = $this->defaults[ 'sectype' ];
|
300 |
+
endif;
|
301 |
+
|
302 |
+
$this->options = $options;
|
303 |
+
|
304 |
+
return $options;
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Function to output an admin notice
|
309 |
+
* when plugin settings or constants need to be configured
|
310 |
+
*
|
311 |
+
* @return void
|
312 |
+
*
|
313 |
+
* @since 0.1
|
314 |
+
*/
|
315 |
+
public function admin_notices()
|
316 |
+
{
|
317 |
+
$screen = get_current_screen();
|
318 |
+
if (!current_user_can('manage_options') || $screen->id == $this->hook_suffix):
|
319 |
+
return;
|
320 |
+
endif;
|
321 |
+
|
322 |
+
$smtpPasswordUndefined = ( !$this->get_option('password') && ( !defined('MAILGUN_PASSWORD') || !MAILGUN_PASSWORD ) );
|
323 |
+
$smtpActiveNotConfigured = ( $this->get_option('useAPI') === '0' && $smtpPasswordUndefined );
|
324 |
+
$apiRegionUndefined = ( !$this->get_option('region') && ( !defined('MAILGUN_REGION') || !MAILGUN_REGION ) );
|
325 |
+
$apiKeyUndefined = ( !$this->get_option('apiKey') && ( !defined('MAILGUN_APIKEY') || !MAILGUN_APIKEY ));
|
326 |
+
$apiActiveNotConfigured = ( $this->get_option('useAPI') === '1' && ( $apiRegionUndefined || $apiKeyUndefined ) );
|
327 |
+
|
328 |
+
if ($apiActiveNotConfigured || $smtpActiveNotConfigured):
|
329 |
+
?>
|
330 |
+
<div id='mailgun-warning' class='notice notice-warning is-dismissible'>
|
331 |
+
<p>
|
332 |
+
<?php
|
333 |
+
printf(
|
334 |
+
__('Mailgun now supports multiple regions! The U.S. region will be used by default, but you can choose the EU region. You can configure your Mailgun settings in your wp-config.php file or <a href="%1$s">here</a>',
|
335 |
+
'mailgun'),
|
336 |
+
menu_page_url('mailgun', false)
|
337 |
+
);
|
338 |
+
?>
|
339 |
+
</p>
|
340 |
+
</div>
|
341 |
<?php
|
342 |
+
endif;
|
343 |
+
|
344 |
+
if ($this->get_option('override-from') === '1' &&
|
345 |
+
(!$this->get_option('from-name') || !$this->get_option('from-address'))
|
346 |
+
):
|
347 |
+
?>
|
348 |
+
<div id='mailgun-warning' class='notice notice-warning is-dismissible'>
|
349 |
+
<p>
|
350 |
+
<strong>
|
351 |
+
<?php _e('Mailgun is almost ready. ', 'mailgun'); ?>
|
352 |
+
</strong>
|
353 |
+
<?php
|
354 |
+
printf(
|
355 |
+
__('"Override From" option requires that "From Name" and "From Address" be set to work properly! <a href="%1$s">Configure Mailgun now</a>.',
|
356 |
+
'mailgun'),
|
357 |
+
menu_page_url('mailgun', false)
|
358 |
+
);
|
359 |
+
?>
|
360 |
+
</p>
|
361 |
+
</div>
|
362 |
+
<?php
|
363 |
+
endif;
|
364 |
+
}
|
365 |
+
|
366 |
+
/**
|
367 |
+
* Add a settings link to the plugin actions.
|
368 |
+
*
|
369 |
+
* @param array $links Array of the plugin action links
|
370 |
+
*
|
371 |
+
* @return array
|
372 |
+
*
|
373 |
+
* @since 0.1
|
374 |
+
*/
|
375 |
+
public function filter_plugin_actions($links)
|
376 |
+
{
|
377 |
+
$settings_link = '<a href="' . menu_page_url('mailgun', false) . '">' . __('Settings', 'mailgun') . '</a>';
|
378 |
+
array_unshift($links, $settings_link);
|
379 |
+
|
380 |
+
return $links;
|
381 |
+
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* AJAX callback function to test mail sending functionality.
|
385 |
+
*
|
386 |
+
* @return string
|
387 |
+
*
|
388 |
+
* @since 0.1
|
389 |
+
*/
|
390 |
+
public function ajax_send_test()
|
391 |
+
{
|
392 |
+
nocache_headers();
|
393 |
+
header('Content-Type: application/json');
|
394 |
+
|
395 |
+
if (!current_user_can('manage_options') || !wp_verify_nonce($_GET[ '_wpnonce' ])):
|
396 |
+
die(
|
397 |
+
json_encode(
|
398 |
+
array(
|
399 |
+
'message' => __('Unauthorized', 'mailgun'),
|
400 |
+
'method' => null,
|
401 |
+
'error' => __('Unauthorized', 'mailgun'),
|
402 |
+
)
|
403 |
+
)
|
404 |
+
);
|
405 |
+
endif;
|
406 |
+
|
407 |
+
$getRegion = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $this->get_option('region');
|
408 |
+
$useAPI = (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI) ? MAILGUN_USEAPI : $this->get_option('useAPI');
|
409 |
+
$secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
|
410 |
+
$sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
|
411 |
+
|
412 |
+
if ((bool) !$getRegion):
|
413 |
+
mg_api_last_error(__("Region has not been selected", "mailgun"));
|
414 |
+
else:
|
415 |
+
if ($getRegion === 'us'):
|
416 |
+
$region = __("U.S./North America", "mailgun");
|
417 |
+
endif;
|
418 |
+
|
419 |
+
if ($getRegion === "eu"):
|
420 |
+
$region = __("Europe", "mailgun");
|
421 |
+
endif;
|
422 |
+
endif;
|
423 |
+
|
424 |
+
if ((bool) $useAPI):
|
425 |
+
$method = __('HTTP API', 'mailgun');
|
426 |
+
else:
|
427 |
+
$method = ((bool) $secure) ? __('Secure SMTP', 'mailgun') : __('Insecure SMTP', 'mailgun');
|
428 |
+
if ((bool) $secure):
|
429 |
+
$method = $method . sprintf(__(' via %s', 'mailgun'), $sectype);
|
430 |
+
endif;
|
431 |
+
endif;
|
432 |
+
|
433 |
+
$admin_email = get_option('admin_email');
|
434 |
+
$result = wp_mail(
|
435 |
+
$admin_email,
|
436 |
+
__('Mailgun WordPress Plugin Test', 'mailgun'),
|
437 |
+
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.",
|
438 |
+
'mailgun'), $region, $method),
|
439 |
+
array('Content-Type: text/plain')
|
440 |
+
);
|
441 |
+
|
442 |
+
if ((bool) $useAPI):
|
443 |
+
if (!function_exists('mg_api_last_error')):
|
444 |
+
if (!include dirname(__FILE__) . '/wp-mail-api.php'):
|
445 |
+
self::deactivate_and_die(dirname(__FILE__) . '/wp-mail-api.php');
|
446 |
+
endif;
|
447 |
+
endif;
|
448 |
+
|
449 |
+
$error_msg = mg_api_last_error();
|
450 |
+
else:
|
451 |
+
if (!function_exists('mg_smtp_last_error')):
|
452 |
+
if (!include dirname(__FILE__) . '/wp-mail-smtp.php'):
|
453 |
+
self::deactivate_and_die(dirname(__FILE__) . '/wp-mail-smtp.php');
|
454 |
+
endif;
|
455 |
+
endif;
|
456 |
+
|
457 |
+
$error_msg = mg_smtp_last_error();
|
458 |
+
endif;
|
459 |
+
|
460 |
+
// Admin Email is used as 'to' parameter, but in case of 'Test Configuration' this message is not clear for the user, so replaced with more appropriate one
|
461 |
+
if (false !== strpos($error_msg, "'to'") && false !== strpos($error_msg, 'is not a valid')):
|
462 |
+
$error_msg = sprintf(
|
463 |
+
"Administration Email Address (%s) is not valid and can't be used for test, you can change it at General Setting page",
|
464 |
+
$admin_email
|
465 |
+
);
|
466 |
+
endif;
|
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 |
+
// Error message will always be returned in case of failure, if not - connection wasn't successful
|
480 |
+
$error_msg = $error_msg ? $error_msg : "Can't connect to Mailgun";
|
481 |
+
|
482 |
+
die(
|
483 |
+
json_encode(
|
484 |
+
array(
|
485 |
+
'message' => __('Failure', 'mailgun'),
|
486 |
+
'method' => $method,
|
487 |
+
'error' => $error_msg,
|
488 |
+
)
|
489 |
+
)
|
490 |
+
);
|
491 |
+
endif;
|
492 |
+
}
|
493 |
+
}
|
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 |
-
|
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();
|
@@ -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://
|
48 |
</a>
|
49 |
</span>
|
50 |
|
@@ -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
|
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();
|
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 |
|
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/mg-filter.php
CHANGED
@@ -19,15 +19,16 @@
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
|
|
22 |
/**
|
23 |
* Tries several methods to get the MIME Content-Type of a file.
|
24 |
*
|
25 |
-
* @param
|
26 |
-
* @param
|
27 |
*
|
28 |
-
* @return
|
29 |
*
|
30 |
-
* @since
|
31 |
*/
|
32 |
function get_mime_content_type($filepath, $default_type = 'text/plain')
|
33 |
{
|
@@ -58,9 +59,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
|
62 |
*
|
63 |
-
* @since
|
64 |
*/
|
65 |
function mg_detect_from_name($from_name_header = null)
|
66 |
{
|
@@ -123,13 +124,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
|
127 |
-
*
|
128 |
-
* @param string $from_addr_header From address given by a header.
|
129 |
*
|
130 |
-
* @return
|
131 |
*
|
132 |
-
* @since
|
133 |
*/
|
134 |
function mg_detect_from_address($from_addr_header = null)
|
135 |
{
|
@@ -194,11 +193,11 @@ function mg_detect_from_address($from_addr_header = null)
|
|
194 |
* )
|
195 |
* )
|
196 |
*
|
197 |
-
* @param
|
198 |
*
|
199 |
-
* @return
|
200 |
*
|
201 |
-
* @since
|
202 |
*/
|
203 |
function mg_parse_headers($headers = array())
|
204 |
{
|
@@ -259,11 +258,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
|
263 |
*
|
264 |
-
* @return
|
265 |
*
|
266 |
-
* @since
|
267 |
*/
|
268 |
function mg_dump_headers($headers = null)
|
269 |
{
|
@@ -287,3 +286,40 @@ function mg_dump_headers($headers = null)
|
|
287 |
return $header_string;
|
288 |
}
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
+
|
23 |
/**
|
24 |
* Tries several methods to get the MIME Content-Type of a file.
|
25 |
*
|
26 |
+
* @param string $filepath
|
27 |
+
* @param string $default_type If all methods fail, fallback to $default_type
|
28 |
*
|
29 |
+
* @return string Content-Type
|
30 |
*
|
31 |
+
* @since 1.5.4
|
32 |
*/
|
33 |
function get_mime_content_type($filepath, $default_type = 'text/plain')
|
34 |
{
|
59 |
* `$from_addr` before being returned. The filtered result is null-tested
|
60 |
* before being returned.
|
61 |
*
|
62 |
+
* @return string
|
63 |
*
|
64 |
+
* @since 1.5.8
|
65 |
*/
|
66 |
function mg_detect_from_name($from_name_header = null)
|
67 |
{
|
124 |
* might appear to be another option but some hosts may refuse to
|
125 |
* relay mail from an unknown domain.
|
126 |
*
|
127 |
+
* @link http://trac.wordpress.org/ticket/5007.
|
|
|
|
|
128 |
*
|
129 |
+
* @return string
|
130 |
*
|
131 |
+
* @since 1.5.8
|
132 |
*/
|
133 |
function mg_detect_from_address($from_addr_header = null)
|
134 |
{
|
193 |
* )
|
194 |
* )
|
195 |
*
|
196 |
+
* @param string|array $headers
|
197 |
*
|
198 |
+
* @return array
|
199 |
*
|
200 |
+
* @since 1.5.8
|
201 |
*/
|
202 |
function mg_parse_headers($headers = array())
|
203 |
{
|
258 |
* Takes a header array in the format produced by mg_parse_headers and
|
259 |
* dumps them down in to a submittable header format.
|
260 |
*
|
261 |
+
* @param array $headers Headers to dump
|
262 |
*
|
263 |
+
* @return string String of \r\n separated headers
|
264 |
*
|
265 |
+
* @since 1.5.8
|
266 |
*/
|
267 |
function mg_dump_headers($headers = null)
|
268 |
{
|
286 |
return $header_string;
|
287 |
}
|
288 |
|
289 |
+
/**
|
290 |
+
* Set the API endpoint based on the region selected.
|
291 |
+
* Value can be "0" if not selected, "us" or "eu"
|
292 |
+
*
|
293 |
+
* @param string $getRegion Region value set either in config or Mailgun plugin settings.
|
294 |
+
*
|
295 |
+
* @return bool|string
|
296 |
+
*
|
297 |
+
* @since 1.5.12
|
298 |
+
*/
|
299 |
+
function mg_api_get_region($getRegion)
|
300 |
+
{
|
301 |
+
switch ($getRegion) {
|
302 |
+
case 'us': return 'https://api.mailgun.net/v3/';
|
303 |
+
case 'eu': return 'https://api.eu.mailgun.net/v3/';
|
304 |
+
default: return false;
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Set the SMTP endpoint based on the region selected.
|
310 |
+
* Value can be "0" if not selected, "us" or "eu"
|
311 |
+
*
|
312 |
+
* @param string $getRegion Region value set either in config or Mailgun plugin settings.
|
313 |
+
*
|
314 |
+
* @return bool|string
|
315 |
+
*
|
316 |
+
* @since 1.5.12
|
317 |
+
*/
|
318 |
+
function mg_smtp_get_region($getRegion)
|
319 |
+
{
|
320 |
+
switch ($getRegion) {
|
321 |
+
case 'us': return 'smtp.mailgun.org';
|
322 |
+
case 'eu': return 'smtp.eu.mailgun.org';
|
323 |
+
default: return false;
|
324 |
+
}
|
325 |
+
}
|
includes/options-page.php
CHANGED
@@ -1,201 +1,450 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
?>
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
$mailgun_domain_const = ((defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : null);
|
23 |
+
$mailgun_domain = $mailgun_domain_const ? $mailgun_domain_const : $this->get_option('domain');
|
24 |
+
|
25 |
+
$mailgun_region_const = ((defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : null);
|
26 |
+
$mailgun_region = $mailgun_region_const ? $mailgun_region_const : $this->get_option('region');
|
27 |
+
|
28 |
+
$mailgun_api_key_const = ((defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : null);
|
29 |
+
$mailgun_api_key = $mailgun_api_key_const ? $mailgun_api_key_const : $this->get_option('apiKey');
|
30 |
+
|
31 |
+
$mailgun_username_const = ((defined('MAILGUN_USERNAME') && MAILGUN_USERNAME) ? MAILGUN_USERNAME : null);
|
32 |
+
$mailgun_username = $mailgun_username_const ? $mailgun_username_const : $this->get_option('username');
|
33 |
+
|
34 |
+
$mailgun_password_const = ((defined('MAILGUN_PASSWORD') && MAILGUN_PASSWORD) ? MAILGUN_PASSWORD : null);
|
35 |
+
$mailgun_password = $mailgun_password_const ? $mailgun_password_const : $this->get_option('password');
|
36 |
+
|
37 |
+
$mailgun_sectype_const = ((defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : null);
|
38 |
+
$mailgun_sectype = $mailgun_sectype_const ? $mailgun_sectype_const : $this->get_option('sectype');
|
39 |
+
|
40 |
+
$mailgun_from_name_const = ((defined('MAILGUN_FROM_NAME') && MAILGUN_FROM_NAME) ? MAILGUN_FROM_NAME : null);
|
41 |
+
$mailgun_from_name = $mailgun_from_name_const ? $mailgun_from_name_const : $this->get_option('from-name');
|
42 |
+
|
43 |
+
$mailgun_from_address_const = ((defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) ? MAILGUN_FROM_ADDRESS : null);
|
44 |
+
$mailgun_from_address = $mailgun_from_address_const ? $mailgun_from_address_const : $this->get_option('from-address');
|
45 |
+
|
46 |
+
$mailgun_secure_const = (defined('MAILGUN_SECURE') ? MAILGUN_SECURE : null);
|
47 |
+
$mailgun_secure = !is_null($mailgun_secure_const) ? ((string)(1 * $mailgun_secure_const)) : $this->get_option('secure');
|
48 |
+
|
49 |
+
$mailgun_use_api_const = (defined('MAILGUN_USEAPI') ? MAILGUN_USEAPI : null);
|
50 |
+
$mailgun_use_api = !is_null($mailgun_use_api_const) ? ((string)(1 * $mailgun_use_api_const)) : $this->get_option('useAPI');
|
51 |
+
|
52 |
|
53 |
?>
|
54 |
+
<div class="wrap">
|
55 |
+
<div id="icon-options-general" class="icon32"><br/></div>
|
56 |
+
<span class="alignright">
|
57 |
+
<a target="_blank" href="http://www.mailgun.com/">
|
58 |
+
<img src="https://assets.mailgun.com/img/mailgun.svg" alt="Mailgun" style="width:10em;"/>
|
59 |
+
</a>
|
60 |
+
</span>
|
61 |
+
<h2><?php _e('Mailgun', 'mailgun'); ?></h2>
|
62 |
+
|
63 |
+
<p>
|
64 |
+
<?php
|
65 |
+
$url = 'https://www.mailgun.com';
|
66 |
+
$link = sprintf(
|
67 |
+
wp_kses(
|
68 |
+
__('A <a href="%1$s" target="%2$s">Mailgun</a> account is required to use this plugin and the Mailgun service.', 'mailgun'),
|
69 |
+
array('a' => array(
|
70 |
+
'href' => array(),
|
71 |
+
'target' => array()
|
72 |
+
)
|
73 |
+
)
|
74 |
+
), esc_url($url), '_blank'
|
75 |
+
);
|
76 |
+
echo $link;
|
77 |
+
?>
|
78 |
+
</p>
|
79 |
+
|
80 |
+
<p>
|
81 |
+
<?php
|
82 |
+
$url = 'https://signup.mailgun.com/new/signup';
|
83 |
+
$link = sprintf(
|
84 |
+
wp_kses(
|
85 |
+
__('If you need to register for an account, you can do so at <a href="%1$s" target="%2$s">Mailgun.com</a>.', 'mailgun'),
|
86 |
+
array('a' => array(
|
87 |
+
'href' => array(),
|
88 |
+
'target' => array()
|
89 |
+
)
|
90 |
+
)
|
91 |
+
), esc_url($url), '_blank'
|
92 |
+
);
|
93 |
+
echo $link;
|
94 |
+
?>
|
95 |
+
</p>
|
96 |
+
|
97 |
+
<h3><?php _e('Configuration', 'mailgun'); ?></h3>
|
98 |
+
<form id="mailgun-form" action="options.php" method="post">
|
99 |
+
<?php settings_fields('mailgun'); ?>
|
100 |
+
|
101 |
+
<table class="form-table">
|
102 |
+
<tr valign="top">
|
103 |
+
<th scope="row">
|
104 |
+
<?php _e('Select Your Region', 'mailgun'); ?>
|
105 |
+
</th>
|
106 |
+
<td>
|
107 |
+
<?php if ($mailgun_region_const): ?>
|
108 |
+
<input type="hidden" name="mailgun[region]" value="<?php echo $mailgun_region ?>">
|
109 |
+
<?php endif ?>
|
110 |
+
|
111 |
+
<select id="mailgun-region" name="mailgun[region]" <?php echo $mailgun_region_const ? 'disabled="disabled"' : '' ?>>
|
112 |
+
<option value="us"<?php selected('us', $mailgun_region); ?>><?php _e('U.S./North America', 'mailgun') ?></option>
|
113 |
+
<option value="eu"<?php selected('eu', $mailgun_region); ?>><?php _e('Europe', 'mailgun') ?></option>
|
114 |
+
</select>
|
115 |
+
<p class="description">
|
116 |
+
<?php
|
117 |
+
_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');
|
118 |
+
?>
|
119 |
+
</p>
|
120 |
+
</td>
|
121 |
+
</tr>
|
122 |
+
<tr valign="top">
|
123 |
+
<th scope="row">
|
124 |
+
<?php _e('Use HTTP API', 'mailgun'); ?>
|
125 |
+
</th>
|
126 |
+
<td>
|
127 |
+
<?php if (!is_null($mailgun_use_api_const)): ?>
|
128 |
+
<input type="hidden" name="mailgun[useAPI]" value="<?php echo $mailgun_use_api ?>">
|
129 |
+
<?php endif ?>
|
130 |
+
|
131 |
+
<select id="mailgun-api" name="mailgun[useAPI]" <?php echo !is_null($mailgun_use_api_const) ? 'disabled="disabled"' : '' ?>>
|
132 |
+
<option value="1"<?php selected('1', $mailgun_use_api); ?>><?php _e('Yes', 'mailgun'); ?></option>
|
133 |
+
<option value="0"<?php selected('0', $mailgun_use_api); ?>><?php _e('No', 'mailgun'); ?></option>
|
134 |
+
</select>
|
135 |
+
<p class="description">
|
136 |
+
<?php
|
137 |
+
_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');
|
138 |
+
?>
|
139 |
+
</p>
|
140 |
+
</td>
|
141 |
+
</tr>
|
142 |
+
<tr valign="top">
|
143 |
+
<th scope="row">
|
144 |
+
<?php _e('Mailgun Domain Name', 'mailgun'); ?>
|
145 |
+
</th>
|
146 |
+
<td>
|
147 |
+
<input type="text" class="regular-text"
|
148 |
+
name="mailgun[domain]"
|
149 |
+
value="<?php esc_attr_e($mailgun_domain); ?>"
|
150 |
+
placeholder="samples.mailgun.org"
|
151 |
+
<?php echo $mailgun_domain_const ? 'readonly="readonly"' : '' ?>
|
152 |
+
/>
|
153 |
+
<p class="description">
|
154 |
+
<?php _e('Your Mailgun Domain Name.', 'mailgun'); ?>
|
155 |
+
</p>
|
156 |
+
</td>
|
157 |
+
</tr>
|
158 |
+
<tr valign="top" class="mailgun-api">
|
159 |
+
<th scope="row">
|
160 |
+
<?php _e('API Key', 'mailgun'); ?>
|
161 |
+
</th>
|
162 |
+
<td>
|
163 |
+
<input type="text" class="regular-text" name="mailgun[apiKey]"
|
164 |
+
value="<?php esc_attr_e($mailgun_api_key); ?>"
|
165 |
+
placeholder="key-3ax6xnjp29jd6fds4gc373sgvjxteol0"
|
166 |
+
<?php echo $mailgun_api_key_const ? 'readonly="readonly"' : '' ?>
|
167 |
+
/>
|
168 |
+
<p class="description">
|
169 |
+
<?php
|
170 |
+
_e('Your Mailgun API key. Only valid for use with the API.', 'mailgun');
|
171 |
+
?>
|
172 |
+
</p>
|
173 |
+
</td>
|
174 |
+
</tr>
|
175 |
+
<tr valign="top" class="mailgun-smtp">
|
176 |
+
<th scope="row">
|
177 |
+
<?php _e('Username', 'mailgun'); ?>
|
178 |
+
</th>
|
179 |
+
<td>
|
180 |
+
<input type="text" class="regular-text"
|
181 |
+
name="mailgun[username]"
|
182 |
+
value="<?php esc_attr_e($mailgun_username); ?>"
|
183 |
+
placeholder="postmaster"
|
184 |
+
<?php echo $mailgun_username_const ? 'readonly="readonly"' : '' ?>
|
185 |
+
/>
|
186 |
+
<p class="description">
|
187 |
+
<?php
|
188 |
+
_e('Your Mailgun SMTP username. Only valid for use with SMTP.', 'mailgun');
|
189 |
+
?>
|
190 |
+
</p>
|
191 |
+
</td>
|
192 |
+
</tr>
|
193 |
+
<tr valign="top" class="mailgun-smtp">
|
194 |
+
<th scope="row">
|
195 |
+
<?php _e('Password', 'mailgun'); ?>
|
196 |
+
</th>
|
197 |
+
<td>
|
198 |
+
<input type="text" class="regular-text"
|
199 |
+
name="mailgun[password]"
|
200 |
+
value="<?php esc_attr_e($mailgun_password); ?>"
|
201 |
+
placeholder="my-password"
|
202 |
+
<?php echo $mailgun_password_const ? 'readonly="readonly"' : '' ?>
|
203 |
+
/>
|
204 |
+
<p class="description">
|
205 |
+
<?php
|
206 |
+
_e('Your Mailgun SMTP password that goes with the above username. Only valid for use with SMTP.', 'mailgun');
|
207 |
+
?>
|
208 |
+
</p>
|
209 |
+
</td>
|
210 |
+
</tr>
|
211 |
+
<tr valign="top" class="mailgun-smtp">
|
212 |
+
<th scope="row">
|
213 |
+
<?php _e('Use Secure SMTP', 'mailgun'); ?>
|
214 |
+
</th>
|
215 |
+
<td>
|
216 |
+
<?php if (!is_null($mailgun_secure_const)): ?>
|
217 |
+
<input type="hidden" name="mailgun[secure]" value="<?php echo $mailgun_secure ?>">
|
218 |
+
<?php endif ?>
|
219 |
+
|
220 |
+
<select name="mailgun[secure]" <?php echo !is_null($mailgun_secure_const) ? 'disabled="disabled"' : '' ?>>
|
221 |
+
<option value="1"<?php selected('1', $mailgun_secure); ?>><?php _e('Yes', 'mailgun'); ?></option>
|
222 |
+
<option value="0"<?php selected('0', $mailgun_secure); ?>><?php _e('No', 'mailgun'); ?></option>
|
223 |
+
</select>
|
224 |
+
<p class="description">
|
225 |
+
<?php
|
226 |
+
_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');
|
227 |
+
?>
|
228 |
+
</p>
|
229 |
+
</td>
|
230 |
+
</tr>
|
231 |
+
<tr valign="top" class="mailgun-smtp">
|
232 |
+
<th scope="row">
|
233 |
+
<?php _e('Security Type', 'mailgun'); ?>
|
234 |
+
</th>
|
235 |
+
<td>
|
236 |
+
<?php if ($mailgun_sectype_const): ?>
|
237 |
+
<input type="hidden" name="mailgun[sectype]" value="<?php echo $mailgun_sectype ?>">
|
238 |
+
<?php endif ?>
|
239 |
+
|
240 |
+
<select name="mailgun[sectype]" <?php echo $mailgun_sectype_const ? 'disabled="disabled"' : '' ?>>
|
241 |
+
<option value="ssl"<?php selected('ssl', $mailgun_sectype); ?>>SSL</option>
|
242 |
+
<option value="tls"<?php selected('tls', $mailgun_sectype); ?>>TLS</option>
|
243 |
+
</select>
|
244 |
+
<p class="description">
|
245 |
+
<?php
|
246 |
+
_e('Leave this at "TLS" unless mail sending fails. This option only matters for Secure SMTP. Default "TLS".', 'mailgun');
|
247 |
+
?>
|
248 |
+
</p>
|
249 |
+
</td>
|
250 |
+
</tr>
|
251 |
+
<tr valign="top">
|
252 |
+
<th scope="row">
|
253 |
+
<?php _e('Click Tracking', 'mailgun'); ?>
|
254 |
+
</th>
|
255 |
+
<td>
|
256 |
+
<select name="mailgun[track-clicks]">
|
257 |
+
<option value="htmlonly"<?php selected('htmlonly', $this->get_option('track-clicks')); ?>><?php _e('HTML Only', 'mailgun'); ?></option>
|
258 |
+
<option value="yes"<?php selected('yes', $this->get_option('track-clicks')); ?>><?php _e('Yes', 'mailgun'); ?></option>
|
259 |
+
<option value="no"<?php selected('no', $this->get_option('track-clicks')); ?>><?php _e('No', 'mailgun'); ?></option>
|
260 |
+
</select>
|
261 |
+
<p class="description">
|
262 |
+
<?php
|
263 |
+
$url = 'http://documentation.mailgun.com/user_manual.html#tracking-clicks';
|
264 |
+
$link = sprintf(
|
265 |
+
wp_kses(
|
266 |
+
__('If enabled, Mailgun will track links. <a href="%1$s" target="%2$s">Open Tracking Documentation</a>.', 'mailgun'),
|
267 |
+
array('a' => array(
|
268 |
+
'href' => array(),
|
269 |
+
'target' => array()
|
270 |
+
)
|
271 |
+
)
|
272 |
+
), esc_url($url), '_blank'
|
273 |
+
);
|
274 |
+
echo $link;
|
275 |
+
?>
|
276 |
+
</p>
|
277 |
+
</td>
|
278 |
+
</tr>
|
279 |
+
<tr valign="top">
|
280 |
+
<th scope="row">
|
281 |
+
<?php _e('Open Tracking', 'mailgun'); ?>
|
282 |
+
</th>
|
283 |
+
<td>
|
284 |
+
<select name="mailgun[track-opens]">
|
285 |
+
<option value="1"<?php selected('1', $this->get_option('track-opens')); ?>><?php _e('Yes', 'mailgun'); ?></option>
|
286 |
+
<option value="0"<?php selected('0', $this->get_option('track-opens')); ?>><?php _e('No', 'mailgun'); ?></option>
|
287 |
+
</select>
|
288 |
+
<p class="description">
|
289 |
+
<?php
|
290 |
+
$url = 'http://documentation.mailgun.com/user_manual.html#tracking-opens';
|
291 |
+
$link = sprintf(
|
292 |
+
wp_kses(
|
293 |
+
__('If enabled, HTML messages will include an open tracking beacon. <a href="%1$s" target="%2$s">Open Tracking Documentation</a>.', 'mailgun'),
|
294 |
+
array('a' => array(
|
295 |
+
'href' => array(),
|
296 |
+
'target' => array()
|
297 |
+
)
|
298 |
+
)
|
299 |
+
), esc_url($url), '_blank'
|
300 |
+
);
|
301 |
+
echo $link;
|
302 |
+
?>
|
303 |
+
</p>
|
304 |
+
</td>
|
305 |
+
</tr>
|
306 |
+
<tr valign="top">
|
307 |
+
<th scope="row">
|
308 |
+
<?php _e('From Address', 'mailgun'); ?>
|
309 |
+
</th>
|
310 |
+
<td>
|
311 |
+
<input type="text"
|
312 |
+
class="regular-text"
|
313 |
+
name="mailgun[from-address]"
|
314 |
+
value="<?php esc_attr_e($mailgun_from_address); ?>"
|
315 |
+
placeholder="wordpress@mydomain.com"
|
316 |
+
<?php echo $mailgun_from_address_const ? 'readonly="readonly"' : '' ?>
|
317 |
+
/>
|
318 |
+
<p class="description">
|
319 |
+
<?php
|
320 |
+
_e('The <address@mydomain.com> part of the sender information (<code>"Excited User <user@samples.mailgun.org>"</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');
|
321 |
+
?>
|
322 |
+
</p>
|
323 |
+
</td>
|
324 |
+
</tr>
|
325 |
+
<tr valign="top">
|
326 |
+
<th scope="row">
|
327 |
+
<?php _e('From Name', 'mailgun'); ?>
|
328 |
+
</th>
|
329 |
+
<td>
|
330 |
+
<input type="text" class="regular-text"
|
331 |
+
name="mailgun[from-name]"
|
332 |
+
value="<?php esc_attr_e($mailgun_from_name); ?>"
|
333 |
+
placeholder="WordPress"
|
334 |
+
<?php echo $mailgun_from_name_const ? 'readonly="readonly"' : '' ?>
|
335 |
+
/>
|
336 |
+
<p class="description">
|
337 |
+
<?php
|
338 |
+
_e('The "User Name" part of the sender information (<code>"Excited User <user@samples.mailgun.org>"</code>).', 'mailgun');
|
339 |
+
?>
|
340 |
+
</p>
|
341 |
+
</td>
|
342 |
+
</tr>
|
343 |
+
<tr valign="top">
|
344 |
+
<th scope="row">
|
345 |
+
<?php _e('Override "From" Details', 'mailgun'); ?>
|
346 |
+
</th>
|
347 |
+
<td>
|
348 |
+
<select name="mailgun[override-from]">
|
349 |
+
<option value="1"<?php selected('1', $this->get_option('override-from', null, '0')); ?>><?php _e('Yes', 'mailgun'); ?></option>
|
350 |
+
<option value="0"<?php selected('0', $this->get_option('override-from', null, '0')); ?>><?php _e('No', 'mailgun'); ?></option>
|
351 |
+
</select>
|
352 |
+
<p class="description">
|
353 |
+
<?php
|
354 |
+
_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');
|
355 |
+
?>
|
356 |
+
</p>
|
357 |
+
</td>
|
358 |
+
</tr>
|
359 |
+
<tr valign="top">
|
360 |
+
<th scope="row">
|
361 |
+
<?php _e('Tag', 'mailgun'); ?>
|
362 |
+
</th>
|
363 |
+
<td>
|
364 |
+
<input type="text" class="regular-text"
|
365 |
+
name="mailgun[campaign-id]"
|
366 |
+
value="<?php esc_attr_e($this->get_option('campaign-id')); ?>"
|
367 |
+
placeholder="tag"
|
368 |
+
/>
|
369 |
+
<p class="description">
|
370 |
+
<?php
|
371 |
+
_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');
|
372 |
+
_e('Learn more about', 'mailgun');
|
373 |
+
|
374 |
+
$url1 = 'https://documentation.mailgun.com/user_manual.html#tracking-messages';
|
375 |
+
$url2 = 'https://documentation.mailgun.com/user_manual.html#tagging';
|
376 |
+
$link = sprintf(
|
377 |
+
wp_kses(
|
378 |
+
__('<a href="%1$s" target="%3$s">Tracking</a> and <a href="%2$s" target="%3$s">Tagging</a>', 'mailgun'),
|
379 |
+
array('a' => array(
|
380 |
+
'href' => array(),
|
381 |
+
'target' => array()
|
382 |
+
)
|
383 |
+
)
|
384 |
+
), esc_url($url1), esc_url($url2), '_blank'
|
385 |
+
);
|
386 |
+
echo $link;
|
387 |
+
?>
|
388 |
+
</p>
|
389 |
+
</td>
|
390 |
+
</tr>
|
391 |
+
</table>
|
392 |
+
<h3><?php _e('Lists', 'mailgun'); ?></h3>
|
393 |
+
<table class="form-table">
|
394 |
+
<tr valign="top">
|
395 |
+
<th scope="row">
|
396 |
+
<?php _e('Shortcode', 'mailgun'); ?>
|
397 |
+
</th>
|
398 |
+
<td>
|
399 |
+
<div>
|
400 |
+
<code>[mailgun id="<em>{mailgun list id}</em>" collect_name="true"]</code>
|
401 |
+
</div>
|
402 |
+
<div>
|
403 |
+
<p class="description">
|
404 |
+
<?php
|
405 |
+
_e('Use the shortcode above to associate a widget instance with a mailgun list', 'mailgun');
|
406 |
+
?>
|
407 |
+
</p>
|
408 |
+
</div>
|
409 |
+
</td>
|
410 |
+
</tr>
|
411 |
+
<tr valign="top">
|
412 |
+
<th scope="row">
|
413 |
+
<?php _e('Lists', 'mailgun'); ?>
|
414 |
+
</th>
|
415 |
+
<td>
|
416 |
+
<?php
|
417 |
+
$url = '?page=mailgun-lists';
|
418 |
+
|
419 |
+
$link = sprintf(
|
420 |
+
wp_kses(
|
421 |
+
__('<a href="%1$s" target="%2$s">View available lists</a>.', 'mailgun'),
|
422 |
+
array('a' => array(
|
423 |
+
'href' => array(),
|
424 |
+
)
|
425 |
+
)
|
426 |
+
), esc_url($url)
|
427 |
+
);
|
428 |
+
echo $link;
|
429 |
+
?>
|
430 |
+
</td>
|
431 |
+
</tr>
|
432 |
+
</table>
|
433 |
+
<p>
|
434 |
+
<?php
|
435 |
+
_e('Before attempting to test the configuration, please click "Save Changes".', 'mailgun');
|
436 |
+
?>
|
437 |
+
</p>
|
438 |
+
<p class="submit">
|
439 |
+
<input type="submit"
|
440 |
+
class="button-primary"
|
441 |
+
value="<?php _e('Save Changes', 'mailgun'); ?>"
|
442 |
+
/>
|
443 |
+
<input type="button"
|
444 |
+
id="mailgun-test"
|
445 |
+
class="button-secondary"
|
446 |
+
value="<?php _e('Test Configuration', 'mailgun'); ?>"
|
447 |
+
/>
|
448 |
+
</p>
|
449 |
+
</form>
|
450 |
+
</div>
|
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
|
32 |
*
|
33 |
-
* @return
|
34 |
*
|
35 |
-
* @since
|
36 |
*/
|
37 |
function mg_api_last_error($error = null)
|
38 |
{
|
@@ -98,22 +98,26 @@ 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
|
102 |
-
* @param
|
103 |
-
* @param
|
104 |
-
* @param
|
105 |
-
* @param
|
106 |
*
|
107 |
-
* @return
|
108 |
*
|
109 |
-
* @
|
|
|
|
|
110 |
*/
|
|
|
111 |
function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
112 |
{
|
113 |
// Compact the input, apply the filters, and extract them back out
|
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 |
|
@@ -121,6 +125,12 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
|
121 |
return false;
|
122 |
}
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if (!is_array($attachments)) {
|
125 |
$attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
|
126 |
}
|
@@ -289,6 +299,39 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
|
289 |
$body['html'] = $message;
|
290 |
}
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
// If we don't have a charset from the input headers
|
293 |
if (!isset($charset)) {
|
294 |
$charset = get_bloginfo('charset');
|
@@ -341,7 +384,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
|
341 |
// // }
|
342 |
// }
|
343 |
|
344 |
-
// Allow other plugins to apply
|
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 +400,9 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
|
357 |
),
|
358 |
);
|
359 |
|
360 |
-
$
|
|
|
|
|
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
|
@@ -375,7 +420,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
|
375 |
// Mailgun API should *always* return a `message` field, even when
|
376 |
// $response_code != 200, so a lack of `message` indicates something
|
377 |
// is broken.
|
378 |
-
if ((int) $response_code != 200
|
379 |
// Store response code and HTTP response message in last error.
|
380 |
$response_message = wp_remote_retrieve_response_message($response);
|
381 |
$errmsg = "$response_code - $response_message";
|
@@ -393,6 +438,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
|
393 |
|
394 |
return true;
|
395 |
}
|
|
|
396 |
|
397 |
function mg_build_payload_from_body($body, $boundary) {
|
398 |
$payload = '';
|
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 |
+
* @global PHPMailer\PHPMailer\PHPMailer $phpmailer
|
110 |
+
*
|
111 |
+
* @since 0.1
|
112 |
*/
|
113 |
+
if (!function_exists('wp_mail')) {
|
114 |
function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
115 |
{
|
116 |
// Compact the input, apply the filters, and extract them back out
|
117 |
extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
|
118 |
|
119 |
$mailgun = get_option('mailgun');
|
120 |
+
$region = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $mailgun['region'];
|
121 |
$apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $mailgun['apiKey'];
|
122 |
$domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $mailgun['domain'];
|
123 |
|
125 |
return false;
|
126 |
}
|
127 |
|
128 |
+
// If a region is not set via defines or through the options page, default to US region.
|
129 |
+
if (!((bool) $region)) {
|
130 |
+
error_log('[Mailgun] No region configuration was found! Defaulting to US region.');
|
131 |
+
$region = 'us';
|
132 |
+
}
|
133 |
+
|
134 |
if (!is_array($attachments)) {
|
135 |
$attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
|
136 |
}
|
299 |
$body['html'] = $message;
|
300 |
}
|
301 |
|
302 |
+
// Some plugins, such as WooCommerce (@see WC_Email::handle_multipart()), to handle multipart/alternative with html
|
303 |
+
// and plaintext messages hooks into phpmailer_init action to override AltBody property directly in $phpmailer,
|
304 |
+
// so we should allow them to do this, and then get overridden plain text body from $phpmailer.
|
305 |
+
// Partly, this logic is taken from original wp_mail function.
|
306 |
+
if (false !== stripos($content_type, 'multipart')) {
|
307 |
+
global $phpmailer;
|
308 |
+
|
309 |
+
// (Re)create it, if it's gone missing.
|
310 |
+
if (!($phpmailer instanceof PHPMailer\PHPMailer\PHPMailer)) {
|
311 |
+
require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
|
312 |
+
require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
|
313 |
+
require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
|
314 |
+
$phpmailer = new PHPMailer\PHPMailer\PHPMailer(true);
|
315 |
+
|
316 |
+
$phpmailer::$validator = static function ($email) {
|
317 |
+
return (bool)is_email($email);
|
318 |
+
};
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Fires after PHPMailer is initialized.
|
323 |
+
*
|
324 |
+
* @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
|
325 |
+
*/
|
326 |
+
do_action_ref_array('phpmailer_init', array(&$phpmailer));
|
327 |
+
|
328 |
+
$plainTextMessage = $phpmailer->AltBody;
|
329 |
+
|
330 |
+
if ($plainTextMessage) {
|
331 |
+
$body['text'] = $plainTextMessage;
|
332 |
+
}
|
333 |
+
}
|
334 |
+
|
335 |
// If we don't have a charset from the input headers
|
336 |
if (!isset($charset)) {
|
337 |
$charset = get_bloginfo('charset');
|
384 |
// // }
|
385 |
// }
|
386 |
|
387 |
+
// Allow other plugins to apply attachment changes before writing to the payload.
|
388 |
$attachments = apply_filters('mg_mutate_attachments', $attachments);
|
389 |
if ( ($attachment_payload = mg_build_attachments_payload($attachments, $boundary)) != null ) {
|
390 |
$payload .= $attachment_payload;
|
400 |
),
|
401 |
);
|
402 |
|
403 |
+
$endpoint = mg_api_get_region($region);
|
404 |
+
$endpoint = ($endpoint) ? $endpoint : 'https://api.mailgun.net/v3/';
|
405 |
+
$url = $endpoint."{$domain}/messages";
|
406 |
|
407 |
// TODO: Mailgun only supports 1000 recipients per request, since we are
|
408 |
// overriding this function, let's add looping here to handle that
|
420 |
// Mailgun API should *always* return a `message` field, even when
|
421 |
// $response_code != 200, so a lack of `message` indicates something
|
422 |
// is broken.
|
423 |
+
if ((int) $response_code != 200 || !isset($response_body->message)) {
|
424 |
// Store response code and HTTP response message in last error.
|
425 |
$response_message = wp_remote_retrieve_response_message($response);
|
426 |
$errmsg = "$response_code - $response_message";
|
438 |
|
439 |
return true;
|
440 |
}
|
441 |
+
}
|
442 |
|
443 |
function mg_build_payload_from_body($body, $boundary) {
|
444 |
$payload = '';
|
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,457 +1,486 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/**
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
/*
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
/**
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
class Mailgun
|
42 |
-
{
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
url: '<?php echo admin_url('admin-ajax.php?action=add_list'); ?>',
|
359 |
-
action:'add_list',
|
360 |
type: 'post',
|
361 |
dataType: 'json',
|
362 |
-
data: jQuery('.'+form_id+'').serialize(),
|
363 |
-
success: function(data) {
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
// error
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
}
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
if (
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
}
|
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.7.1
|
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
@@ -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:
|
8 |
-
Stable tag: 1.
|
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
|
22 |
|
23 |
The current version of this plugin only handles sending emails, tracking and tagging and list subscription.
|
24 |
|
@@ -53,12 +53,14 @@ define( 'MG_DEBUG_SMTP', true );
|
|
53 |
Yes, using the following constants that can be placed in wp-config.php:
|
54 |
|
55 |
`
|
56 |
-
|
|
|
|
|
57 |
MAILGUN_APIKEY Type: string
|
58 |
MAILGUN_DOMAIN Type: string
|
59 |
MAILGUN_USERNAME Type: string
|
60 |
MAILGUN_PASSWORD Type: string
|
61 |
-
MAILGUN_SECURE Type: boolean
|
62 |
MAILGUN_SECTYPE Type: string Choices: 'ssl' or 'tls'
|
63 |
MAILGUN_FROM_NAME Type: string
|
64 |
MAILGUN_FROM_ADDRESS Type: string
|
@@ -70,7 +72,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`
|
74 |
|
75 |
Should *only* return `true` or `false`.
|
76 |
|
@@ -95,7 +97,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`
|
99 |
|
100 |
Should *only* return `true` or `false`.
|
101 |
|
@@ -127,6 +129,59 @@ MAILGUN_FROM_ADDRESS Type: string
|
|
127 |
|
128 |
== Changelog ==
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
= 1.5.10 (2017-11-22): =
|
131 |
- Fix back to settings link on lists page (https://github.com/mailgun/wordpress-plugin/pull/65)
|
132 |
- Fix a bug causing `text/html` emails to send as both `text/plain` *and* `text/html` parts
|
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: 5.5.1
|
8 |
+
Stable tag: 1.7.2
|
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 |
+
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
|
62 |
MAILGUN_PASSWORD Type: string
|
63 |
+
MAILGUN_SECURE Type: boolean Choices: '0' or '1' (0 = false/no)
|
64 |
MAILGUN_SECTYPE Type: string Choices: 'ssl' or 'tls'
|
65 |
MAILGUN_FROM_NAME Type: string
|
66 |
MAILGUN_FROM_ADDRESS Type: string
|
72 |
Mutates messages to use recipient variables syntax - see
|
73 |
https://documentation.mailgun.com/user_manual.html#batch-sending for more info.
|
74 |
|
75 |
+
Should accept a list of `To` addresses.
|
76 |
|
77 |
Should *only* return `true` or `false`.
|
78 |
|
97 |
Mutates messages to use recipient variables syntax - see
|
98 |
https://documentation.mailgun.com/user_manual.html#batch-sending for more info.
|
99 |
|
100 |
+
Should accept a list of `To` addresses.
|
101 |
|
102 |
Should *only* return `true` or `false`.
|
103 |
|
129 |
|
130 |
== Changelog ==
|
131 |
|
132 |
+
= 1.7.2 (2020-10-07): =
|
133 |
+
- Test plugin with PHP 7.4.
|
134 |
+
- Test plugin up to WordPress 5.5.1.
|
135 |
+
|
136 |
+
= 1.7.1 (2019-02-07): =
|
137 |
+
- Reinstall settings page for multisites.
|
138 |
+
|
139 |
+
= 1.7 (2019-01-21): =
|
140 |
+
- Remove settings page for multisites.
|
141 |
+
- Simplify admin notifications.
|
142 |
+
- Test plugin with PHP 7.2.
|
143 |
+
- Test plugin up to WordPress 5.0.3.
|
144 |
+
|
145 |
+
= 1.6.1 (2018-10-08): =
|
146 |
+
- Restore Settings page form for all install types.
|
147 |
+
|
148 |
+
= 1.6 (2018-9-21): =
|
149 |
+
- Refactor admin notifications
|
150 |
+
- Enable Settings page for all WordPress install types
|
151 |
+
- Enable Test Configuration for all WordPress install types
|
152 |
+
- Test plugin up to WordPress 4.9.8.
|
153 |
+
|
154 |
+
= 1.5.14 (2018-09-11): =
|
155 |
+
- Force SSL-secured SMTP connections to use port 465 (SMTPS) to connect, 587 for plain and TLS
|
156 |
+
- Support region endpoint switching for SMTP
|
157 |
+
|
158 |
+
= 1.5.13.1 (2018-08-15): =
|
159 |
+
- Fix line breaks in Test Configuration email
|
160 |
+
|
161 |
+
= 1.5.13 (2018-08-14): =
|
162 |
+
- Default to US region if no region is configured in settings
|
163 |
+
- Add admin notification about region configuration
|
164 |
+
- Log an error message when an email is sent with no explicit region configured
|
165 |
+
|
166 |
+
= 1.5.12.3 (2018-08-09): =
|
167 |
+
- Fix Region select menu default when wp-config.php variable is set
|
168 |
+
- Fix front end email input validation
|
169 |
+
|
170 |
+
= 1.5.12.2 (2018-08-09): =
|
171 |
+
- Fix plugin not saving after update
|
172 |
+
|
173 |
+
= 1.5.12.1 (2018-08-06): =
|
174 |
+
- Fix for backwards compatibility
|
175 |
+
|
176 |
+
= 1.5.12 (2018-08-02): =
|
177 |
+
- Add EU endpoint for Mailgun HTTP API
|
178 |
+
- Fix broken logo image on Lists page
|
179 |
+
- Test plugin up to Wordpress 4.9.7
|
180 |
+
|
181 |
+
= 1.5.11 (2018-05-30): =
|
182 |
+
- Fix an issue with authentication failing for newer API keys
|
183 |
+
- Test plugin up to Wordpress 4.9.6
|
184 |
+
|
185 |
= 1.5.10 (2017-11-22): =
|
186 |
- Fix back to settings link on lists page (https://github.com/mailgun/wordpress-plugin/pull/65)
|
187 |
- Fix a bug causing `text/html` emails to send as both `text/plain` *and* `text/html` parts
|