Version Description
Download this release
Release Info
Developer | omykhailenko |
Plugin | Mailgun for WordPress |
Version | 1.8.3 |
Comparing to | |
See all releases |
Code changes from version v1.8.6 to 1.8.3
- CHANGELOG.md +0 -5
- includes/admin.php +14 -1
- includes/lists-page.php +1 -1
- includes/mg-filter.php +52 -59
- includes/options-page.php +9 -9
- includes/widget.php +6 -7
- includes/wp-mail-api.php +2 -5
- includes/wp-mail-smtp.php +14 -14
- mailgun.php +25 -43
- readme.md +2 -5
- readme.txt +2 -5
CHANGELOG.md
CHANGED
@@ -1,10 +1,5 @@
|
|
1 |
Changelog
|
2 |
=========
|
3 |
-
1.8.5 (2022-09-21)
|
4 |
-
- Make code changes to have more optimized way to use Mailgun object in the code
|
5 |
-
|
6 |
-
1.8.3 (2022-08-30)
|
7 |
-
- Plugin refactoring. Widget fixes for working with Legacy Widget Block. PHP8.0 support check
|
8 |
|
9 |
1.7.9 (2021-05-24)
|
10 |
- API Key description
|
1 |
Changelog
|
2 |
=========
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
1.7.9 (2021-05-24)
|
5 |
- API Key description
|
includes/admin.php
CHANGED
@@ -38,6 +38,7 @@ class MailgunAdmin extends Mailgun
|
|
38 |
*
|
39 |
* @return void
|
40 |
*
|
|
|
41 |
*/
|
42 |
public function __construct()
|
43 |
{
|
@@ -64,6 +65,7 @@ class MailgunAdmin extends Mailgun
|
|
64 |
*
|
65 |
* @return void
|
66 |
*
|
|
|
67 |
*/
|
68 |
public function init()
|
69 |
{
|
@@ -101,6 +103,7 @@ class MailgunAdmin extends Mailgun
|
|
101 |
*
|
102 |
* @return void
|
103 |
*
|
|
|
104 |
*/
|
105 |
public function admin_menu()
|
106 |
{
|
@@ -120,6 +123,7 @@ class MailgunAdmin extends Mailgun
|
|
120 |
*
|
121 |
* @return void
|
122 |
*
|
|
|
123 |
*/
|
124 |
public function admin_js()
|
125 |
{
|
@@ -129,6 +133,7 @@ class MailgunAdmin extends Mailgun
|
|
129 |
/**
|
130 |
* Output JS to footer for enhanced admin page functionality.
|
131 |
*
|
|
|
132 |
*/
|
133 |
public function admin_footer_js()
|
134 |
{
|
@@ -196,6 +201,7 @@ class MailgunAdmin extends Mailgun
|
|
196 |
*
|
197 |
* @return void
|
198 |
*
|
|
|
199 |
*/
|
200 |
public function options_page()
|
201 |
{
|
@@ -210,6 +216,7 @@ class MailgunAdmin extends Mailgun
|
|
210 |
*
|
211 |
* @return void
|
212 |
*
|
|
|
213 |
*/
|
214 |
public function lists_page()
|
215 |
{
|
@@ -226,6 +233,7 @@ class MailgunAdmin extends Mailgun
|
|
226 |
*
|
227 |
* @return void
|
228 |
*
|
|
|
229 |
*/
|
230 |
public function admin_init()
|
231 |
{
|
@@ -243,6 +251,7 @@ class MailgunAdmin extends Mailgun
|
|
243 |
*
|
244 |
* @return void
|
245 |
*
|
|
|
246 |
*/
|
247 |
public function register_settings()
|
248 |
{
|
@@ -256,6 +265,7 @@ class MailgunAdmin extends Mailgun
|
|
256 |
*
|
257 |
* @return array
|
258 |
*
|
|
|
259 |
*/
|
260 |
public function validation(array $options)
|
261 |
{
|
@@ -306,6 +316,7 @@ class MailgunAdmin extends Mailgun
|
|
306 |
*
|
307 |
* @return void
|
308 |
*
|
|
|
309 |
*/
|
310 |
public function admin_notices()
|
311 |
{
|
@@ -365,6 +376,7 @@ class MailgunAdmin extends Mailgun
|
|
365 |
*
|
366 |
* @return array
|
367 |
*
|
|
|
368 |
*/
|
369 |
public function filter_plugin_actions($links)
|
370 |
{
|
@@ -380,6 +392,7 @@ class MailgunAdmin extends Mailgun
|
|
380 |
* @return string
|
381 |
*
|
382 |
* @throws JsonException
|
|
|
383 |
*/
|
384 |
public function ajax_send_test()
|
385 |
{
|
@@ -465,7 +478,7 @@ class MailgunAdmin extends Mailgun
|
|
465 |
}
|
466 |
|
467 |
// Error message will always be returned in case of failure, if not - connection wasn't successful
|
468 |
-
$error_msg = $error_msg
|
469 |
die(
|
470 |
json_encode(array(
|
471 |
'message' => __('Failure', 'mailgun'),
|
38 |
*
|
39 |
* @return void
|
40 |
*
|
41 |
+
* @since 0.1
|
42 |
*/
|
43 |
public function __construct()
|
44 |
{
|
65 |
*
|
66 |
* @return void
|
67 |
*
|
68 |
+
* @since 0.1
|
69 |
*/
|
70 |
public function init()
|
71 |
{
|
103 |
*
|
104 |
* @return void
|
105 |
*
|
106 |
+
* @since 0.1
|
107 |
*/
|
108 |
public function admin_menu()
|
109 |
{
|
123 |
*
|
124 |
* @return void
|
125 |
*
|
126 |
+
* @since 0.1
|
127 |
*/
|
128 |
public function admin_js()
|
129 |
{
|
133 |
/**
|
134 |
* Output JS to footer for enhanced admin page functionality.
|
135 |
*
|
136 |
+
* @since 0.1
|
137 |
*/
|
138 |
public function admin_footer_js()
|
139 |
{
|
201 |
*
|
202 |
* @return void
|
203 |
*
|
204 |
+
* @since 0.1
|
205 |
*/
|
206 |
public function options_page()
|
207 |
{
|
216 |
*
|
217 |
* @return void
|
218 |
*
|
219 |
+
* @since 0.1
|
220 |
*/
|
221 |
public function lists_page()
|
222 |
{
|
233 |
*
|
234 |
* @return void
|
235 |
*
|
236 |
+
* @since 0.1
|
237 |
*/
|
238 |
public function admin_init()
|
239 |
{
|
251 |
*
|
252 |
* @return void
|
253 |
*
|
254 |
+
* @since 0.1
|
255 |
*/
|
256 |
public function register_settings()
|
257 |
{
|
265 |
*
|
266 |
* @return array
|
267 |
*
|
268 |
+
* @since 0.1
|
269 |
*/
|
270 |
public function validation(array $options)
|
271 |
{
|
316 |
*
|
317 |
* @return void
|
318 |
*
|
319 |
+
* @since 0.1
|
320 |
*/
|
321 |
public function admin_notices()
|
322 |
{
|
376 |
*
|
377 |
* @return array
|
378 |
*
|
379 |
+
* @since 0.1
|
380 |
*/
|
381 |
public function filter_plugin_actions($links)
|
382 |
{
|
392 |
* @return string
|
393 |
*
|
394 |
* @throws JsonException
|
395 |
+
* @since 0.1
|
396 |
*/
|
397 |
public function ajax_send_test()
|
398 |
{
|
478 |
}
|
479 |
|
480 |
// Error message will always be returned in case of failure, if not - connection wasn't successful
|
481 |
+
$error_msg = $error_msg ? $error_msg : "Can't connect to Mailgun";
|
482 |
die(
|
483 |
json_encode(array(
|
484 |
'message' => __('Failure', 'mailgun'),
|
includes/lists-page.php
CHANGED
@@ -19,7 +19,7 @@
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
-
$mailgun
|
23 |
|
24 |
// check mailgun domain & api key
|
25 |
$missing_error = '';
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
+
global $mailgun;
|
23 |
|
24 |
// check mailgun domain & api key
|
25 |
$missing_error = '';
|
includes/mg-filter.php
CHANGED
@@ -23,28 +23,26 @@
|
|
23 |
/**
|
24 |
* Tries several methods to get the MIME Content-Type of a file.
|
25 |
*
|
26 |
-
* @param
|
27 |
-
* @param
|
28 |
*
|
29 |
-
* @return
|
30 |
*
|
31 |
-
* @since
|
32 |
*/
|
33 |
-
function get_mime_content_type(
|
34 |
{
|
35 |
if (function_exists('mime_content_type')) {
|
36 |
return mime_content_type($filepath);
|
37 |
-
}
|
38 |
-
|
39 |
-
if (function_exists('finfo_file')) {
|
40 |
$fi = finfo_open(FILEINFO_MIME_TYPE);
|
41 |
$ret = finfo_file($fi, $filepath);
|
42 |
finfo_close($fi);
|
43 |
|
44 |
return $ret;
|
|
|
|
|
45 |
}
|
46 |
-
|
47 |
-
return $default_type;
|
48 |
}
|
49 |
|
50 |
/**
|
@@ -61,16 +59,16 @@ function get_mime_content_type(string $filepath, string $default_type = 'text/pl
|
|
61 |
* `$from_addr` before being returned. The filtered result is null-tested
|
62 |
* before being returned.
|
63 |
*
|
64 |
-
* @return
|
65 |
*
|
66 |
-
* @since
|
67 |
*/
|
68 |
function mg_detect_from_name($from_name_header = null)
|
69 |
{
|
70 |
// Get options to avoid strict mode problems
|
71 |
$mg_opts = get_option('mailgun');
|
72 |
-
$mg_override_from = $mg_opts['override-from']
|
73 |
-
$mg_from_name = $mg_opts['from-name']
|
74 |
|
75 |
$from_name = null;
|
76 |
|
@@ -81,7 +79,7 @@ function mg_detect_from_name($from_name_header = null)
|
|
81 |
} elseif (defined('MAILGUN_FROM_NAME') && MAILGUN_FROM_NAME) {
|
82 |
$from_name = MAILGUN_FROM_NAME;
|
83 |
} else {
|
84 |
-
if (empty($mg_from_name)) {
|
85 |
if (function_exists('get_current_site')) {
|
86 |
$from_name = get_current_site()->site_name;
|
87 |
} else {
|
@@ -98,7 +96,7 @@ function mg_detect_from_name($from_name_header = null)
|
|
98 |
'wp_mail_from_name',
|
99 |
$from_name
|
100 |
);
|
101 |
-
if (!empty($filter_from_name)) {
|
102 |
$from_name = $filter_from_name;
|
103 |
}
|
104 |
}
|
@@ -126,18 +124,18 @@ function mg_detect_from_name($from_name_header = null)
|
|
126 |
* might appear to be another option but some hosts may refuse to
|
127 |
* relay mail from an unknown domain.
|
128 |
*
|
129 |
-
* @link
|
130 |
*
|
131 |
-
* @return
|
132 |
*
|
133 |
-
* @since
|
134 |
*/
|
135 |
-
function mg_detect_from_address($from_addr_header = null)
|
136 |
{
|
137 |
// Get options to avoid strict mode problems
|
138 |
$mg_opts = get_option('mailgun');
|
139 |
-
$mg_override_from = $mg_opts['override-from']
|
140 |
-
$mg_from_addr = $mg_opts['from-address']
|
141 |
|
142 |
$from_addr = null;
|
143 |
|
@@ -148,7 +146,7 @@ function mg_detect_from_address($from_addr_header = null): string
|
|
148 |
} elseif (defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) {
|
149 |
$from_addr = MAILGUN_FROM_ADDRESS;
|
150 |
} else {
|
151 |
-
if (empty($mg_from_addr)) {
|
152 |
if (function_exists('get_current_site')) {
|
153 |
$sitedomain = get_current_site()->domain;
|
154 |
} else {
|
@@ -158,7 +156,7 @@ function mg_detect_from_address($from_addr_header = null): string
|
|
158 |
}
|
159 |
}
|
160 |
|
161 |
-
$from_addr = 'wordpress@'
|
162 |
} else {
|
163 |
$from_addr = $mg_from_addr;
|
164 |
}
|
@@ -195,18 +193,19 @@ function mg_detect_from_address($from_addr_header = null): string
|
|
195 |
* )
|
196 |
* )
|
197 |
*
|
198 |
-
* @param
|
199 |
*
|
200 |
-
* @return
|
201 |
*
|
202 |
-
* @since
|
203 |
*/
|
204 |
-
function mg_parse_headers($headers =
|
205 |
{
|
206 |
if (empty($headers)) {
|
207 |
-
return
|
208 |
}
|
209 |
|
|
|
210 |
if (!is_array($headers)) {
|
211 |
$tmp = explode("\n", str_replace("\r\n", "\n", $headers));
|
212 |
} else {
|
@@ -220,7 +219,7 @@ function mg_parse_headers($headers = []): array
|
|
220 |
$boundary = null;
|
221 |
$parts = null;
|
222 |
|
223 |
-
foreach ((array)$tmp as $header) {
|
224 |
// If this header does not contain a ':', is it a fold?
|
225 |
if (false === strpos($header, ':')) {
|
226 |
// Does this header have a boundary?
|
@@ -240,15 +239,15 @@ function mg_parse_headers($headers = []): array
|
|
240 |
$name = trim($name);
|
241 |
$value = trim($value);
|
242 |
|
243 |
-
if (!isset($new_headers[$name])) {
|
244 |
$new_headers[$name] = array();
|
245 |
}
|
246 |
|
247 |
-
$new_headers[$name]
|
248 |
-
'value'
|
249 |
-
'boundary'
|
250 |
-
'parts'
|
251 |
-
);
|
252 |
}
|
253 |
}
|
254 |
|
@@ -259,13 +258,13 @@ 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 |
{
|
270 |
if (is_null($headers) || !is_array($headers)) {
|
271 |
return '';
|
@@ -278,7 +277,7 @@ function mg_dump_headers($headers = null): string
|
|
278 |
|
279 |
foreach ($values as $content) {
|
280 |
// XXX - Is it actually okay to discard `parts` and `boundary`?
|
281 |
-
$header_values
|
282 |
}
|
283 |
|
284 |
$header_string .= sprintf("%s\r\n", implode(", ", $header_values));
|
@@ -291,21 +290,18 @@ function mg_dump_headers($headers = null): string
|
|
291 |
* Set the API endpoint based on the region selected.
|
292 |
* Value can be "0" if not selected, "us" or "eu"
|
293 |
*
|
294 |
-
* @param
|
295 |
*
|
296 |
-
* @return
|
297 |
*
|
298 |
-
* @since
|
299 |
*/
|
300 |
function mg_api_get_region($getRegion)
|
301 |
{
|
302 |
switch ($getRegion) {
|
303 |
-
case 'us':
|
304 |
-
|
305 |
-
|
306 |
-
return 'https://api.eu.mailgun.net/v3/';
|
307 |
-
default:
|
308 |
-
return false;
|
309 |
}
|
310 |
}
|
311 |
|
@@ -313,20 +309,17 @@ function mg_api_get_region($getRegion)
|
|
313 |
* Set the SMTP endpoint based on the region selected.
|
314 |
* Value can be "0" if not selected, "us" or "eu"
|
315 |
*
|
316 |
-
* @param
|
317 |
*
|
318 |
-
* @return
|
319 |
*
|
320 |
-
* @since
|
321 |
*/
|
322 |
function mg_smtp_get_region($getRegion)
|
323 |
{
|
324 |
switch ($getRegion) {
|
325 |
-
case 'us':
|
326 |
-
|
327 |
-
|
328 |
-
return 'smtp.eu.mailgun.org';
|
329 |
-
default:
|
330 |
-
return false;
|
331 |
}
|
332 |
}
|
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 |
{
|
35 |
if (function_exists('mime_content_type')) {
|
36 |
return mime_content_type($filepath);
|
37 |
+
} elseif (function_exists('finfo_file')) {
|
|
|
|
|
38 |
$fi = finfo_open(FILEINFO_MIME_TYPE);
|
39 |
$ret = finfo_file($fi, $filepath);
|
40 |
finfo_close($fi);
|
41 |
|
42 |
return $ret;
|
43 |
+
} else {
|
44 |
+
return $default_type;
|
45 |
}
|
|
|
|
|
46 |
}
|
47 |
|
48 |
/**
|
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 |
{
|
68 |
// Get options to avoid strict mode problems
|
69 |
$mg_opts = get_option('mailgun');
|
70 |
+
$mg_override_from = (isset($mg_opts['override-from'])) ? $mg_opts['override-from'] : null;
|
71 |
+
$mg_from_name = (isset($mg_opts['from-name'])) ? $mg_opts['from-name'] : null;
|
72 |
|
73 |
$from_name = null;
|
74 |
|
79 |
} elseif (defined('MAILGUN_FROM_NAME') && MAILGUN_FROM_NAME) {
|
80 |
$from_name = MAILGUN_FROM_NAME;
|
81 |
} else {
|
82 |
+
if (is_null($mg_from_name) || empty($mg_from_name)) {
|
83 |
if (function_exists('get_current_site')) {
|
84 |
$from_name = get_current_site()->site_name;
|
85 |
} else {
|
96 |
'wp_mail_from_name',
|
97 |
$from_name
|
98 |
);
|
99 |
+
if (!is_null($filter_from_name) && !empty($filter_from_name)) {
|
100 |
$from_name = $filter_from_name;
|
101 |
}
|
102 |
}
|
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 |
{
|
135 |
// Get options to avoid strict mode problems
|
136 |
$mg_opts = get_option('mailgun');
|
137 |
+
$mg_override_from = (isset($mg_opts['override-from'])) ? $mg_opts['override-from'] : null;
|
138 |
+
$mg_from_addr = (isset($mg_opts['from-address'])) ? $mg_opts['from-address'] : null;
|
139 |
|
140 |
$from_addr = null;
|
141 |
|
146 |
} elseif (defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) {
|
147 |
$from_addr = MAILGUN_FROM_ADDRESS;
|
148 |
} else {
|
149 |
+
if (is_null($mg_from_addr) || empty($mg_from_addr)) {
|
150 |
if (function_exists('get_current_site')) {
|
151 |
$sitedomain = get_current_site()->domain;
|
152 |
} else {
|
156 |
}
|
157 |
}
|
158 |
|
159 |
+
$from_addr = 'wordpress@'.$sitedomain;
|
160 |
} else {
|
161 |
$from_addr = $mg_from_addr;
|
162 |
}
|
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 |
{
|
204 |
if (empty($headers)) {
|
205 |
+
return array();
|
206 |
}
|
207 |
|
208 |
+
$tmp = array();
|
209 |
if (!is_array($headers)) {
|
210 |
$tmp = explode("\n", str_replace("\r\n", "\n", $headers));
|
211 |
} else {
|
219 |
$boundary = null;
|
220 |
$parts = null;
|
221 |
|
222 |
+
foreach ((array) $tmp as $header) {
|
223 |
// If this header does not contain a ':', is it a fold?
|
224 |
if (false === strpos($header, ':')) {
|
225 |
// Does this header have a boundary?
|
239 |
$name = trim($name);
|
240 |
$value = trim($value);
|
241 |
|
242 |
+
if ( !isset($new_headers[$name]) ) {
|
243 |
$new_headers[$name] = array();
|
244 |
}
|
245 |
|
246 |
+
array_push($new_headers[$name], array(
|
247 |
+
'value' => $value,
|
248 |
+
'boundary' => $boundary,
|
249 |
+
'parts' => $parts,
|
250 |
+
));
|
251 |
}
|
252 |
}
|
253 |
|
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 |
{
|
269 |
if (is_null($headers) || !is_array($headers)) {
|
270 |
return '';
|
277 |
|
278 |
foreach ($values as $content) {
|
279 |
// XXX - Is it actually okay to discard `parts` and `boundary`?
|
280 |
+
array_push($header_values, $content['value']);
|
281 |
}
|
282 |
|
283 |
$header_string .= sprintf("%s\r\n", implode(", ", $header_values));
|
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 |
|
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
@@ -19,31 +19,31 @@
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
-
$mailgun
|
23 |
|
24 |
$mailgun_domain_const = ((defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : null);
|
25 |
-
$mailgun_domain = $mailgun_domain_const
|
26 |
|
27 |
$mailgun_region_const = ((defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : null);
|
28 |
-
$mailgun_region = $mailgun_region_const
|
29 |
|
30 |
$mailgun_api_key_const = ((defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : null);
|
31 |
-
$mailgun_api_key = $mailgun_api_key_const
|
32 |
|
33 |
$mailgun_username_const = ((defined('MAILGUN_USERNAME') && MAILGUN_USERNAME) ? MAILGUN_USERNAME : null);
|
34 |
-
$mailgun_username = $mailgun_username_const
|
35 |
|
36 |
$mailgun_password_const = ((defined('MAILGUN_PASSWORD') && MAILGUN_PASSWORD) ? MAILGUN_PASSWORD : null);
|
37 |
-
$mailgun_password = $mailgun_password_const
|
38 |
|
39 |
$mailgun_sectype_const = ((defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : null);
|
40 |
-
$mailgun_sectype = $mailgun_sectype_const
|
41 |
|
42 |
$mailgun_from_name_const = ((defined('MAILGUN_FROM_NAME') && MAILGUN_FROM_NAME) ? MAILGUN_FROM_NAME : null);
|
43 |
-
$mailgun_from_name = $mailgun_from_name_const
|
44 |
|
45 |
$mailgun_from_address_const = ((defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) ? MAILGUN_FROM_ADDRESS : null);
|
46 |
-
$mailgun_from_address = $mailgun_from_address_const
|
47 |
|
48 |
$mailgun_secure_const = (defined('MAILGUN_SECURE') ? MAILGUN_SECURE : null);
|
49 |
$mailgun_secure = !is_null($mailgun_secure_const) ? ((string)(1 * $mailgun_secure_const)) : $this->get_option('secure');
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
+
global $mailgun;
|
23 |
|
24 |
$mailgun_domain_const = ((defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : null);
|
25 |
+
$mailgun_domain = $mailgun_domain_const ? $mailgun_domain_const : $this->get_option('domain');
|
26 |
|
27 |
$mailgun_region_const = ((defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : null);
|
28 |
+
$mailgun_region = $mailgun_region_const ? $mailgun_region_const : $this->get_option('region');
|
29 |
|
30 |
$mailgun_api_key_const = ((defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : null);
|
31 |
+
$mailgun_api_key = $mailgun_api_key_const ? $mailgun_api_key_const : $this->get_option('apiKey');
|
32 |
|
33 |
$mailgun_username_const = ((defined('MAILGUN_USERNAME') && MAILGUN_USERNAME) ? MAILGUN_USERNAME : null);
|
34 |
+
$mailgun_username = $mailgun_username_const ? $mailgun_username_const : $this->get_option('username');
|
35 |
|
36 |
$mailgun_password_const = ((defined('MAILGUN_PASSWORD') && MAILGUN_PASSWORD) ? MAILGUN_PASSWORD : null);
|
37 |
+
$mailgun_password = $mailgun_password_const ? $mailgun_password_const : $this->get_option('password');
|
38 |
|
39 |
$mailgun_sectype_const = ((defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : null);
|
40 |
+
$mailgun_sectype = $mailgun_sectype_const ? $mailgun_sectype_const : $this->get_option('sectype');
|
41 |
|
42 |
$mailgun_from_name_const = ((defined('MAILGUN_FROM_NAME') && MAILGUN_FROM_NAME) ? MAILGUN_FROM_NAME : null);
|
43 |
+
$mailgun_from_name = $mailgun_from_name_const ? $mailgun_from_name_const : $this->get_option('from-name');
|
44 |
|
45 |
$mailgun_from_address_const = ((defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) ? MAILGUN_FROM_ADDRESS : null);
|
46 |
+
$mailgun_from_address = $mailgun_from_address_const ? $mailgun_from_address_const : $this->get_option('from-address');
|
47 |
|
48 |
$mailgun_secure_const = (defined('MAILGUN_SECURE') ? MAILGUN_SECURE : null);
|
49 |
$mailgun_secure = !is_null($mailgun_secure_const) ? ((string)(1 * $mailgun_secure_const)) : $this->get_option('secure');
|
includes/widget.php
CHANGED
@@ -19,7 +19,7 @@
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
-
class list_widget extends
|
23 |
{
|
24 |
public function __construct()
|
25 |
{
|
@@ -37,11 +37,8 @@ class list_widget extends \WP_Widget
|
|
37 |
// This is where the action happens
|
38 |
public function widget($args, $instance)
|
39 |
{
|
40 |
-
$mailgun
|
41 |
|
42 |
-
if (!isset($instance['list_address']) || !$instance['list_address']) {
|
43 |
-
return;
|
44 |
-
}
|
45 |
// vars
|
46 |
$list_address = apply_filters('list_address', $instance['list_address']);
|
47 |
|
@@ -63,6 +60,8 @@ class list_widget extends \WP_Widget
|
|
63 |
// Widget Backend
|
64 |
public function form($instance)
|
65 |
{
|
|
|
|
|
66 |
if (isset($instance['list_address'])) {
|
67 |
$list_address = $instance['list_address'];
|
68 |
} else {
|
@@ -75,8 +74,8 @@ class list_widget extends \WP_Widget
|
|
75 |
$collect_name = '';
|
76 |
}
|
77 |
|
78 |
-
$list_title = $instance['list_title']
|
79 |
-
$list_description = $instance['list_description']
|
80 |
|
81 |
// Widget admin form
|
82 |
?>
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
+
class list_widget extends WP_Widget
|
23 |
{
|
24 |
public function __construct()
|
25 |
{
|
37 |
// This is where the action happens
|
38 |
public function widget($args, $instance)
|
39 |
{
|
40 |
+
global $mailgun;
|
41 |
|
|
|
|
|
|
|
42 |
// vars
|
43 |
$list_address = apply_filters('list_address', $instance['list_address']);
|
44 |
|
60 |
// Widget Backend
|
61 |
public function form($instance)
|
62 |
{
|
63 |
+
global $mailgun;
|
64 |
+
|
65 |
if (isset($instance['list_address'])) {
|
66 |
$list_address = $instance['list_address'];
|
67 |
} else {
|
74 |
$collect_name = '';
|
75 |
}
|
76 |
|
77 |
+
$list_title = isset($instance['list_title']) ? $instance['list_title'] : null;
|
78 |
+
$list_description = isset($instance['list_description']) ? $instance['list_description'] : null;
|
79 |
|
80 |
// Widget admin form
|
81 |
?>
|
includes/wp-mail-api.php
CHANGED
@@ -108,16 +108,13 @@ function mg_mutate_to_rcpt_vars_cb($to_addrs)
|
|
108 |
*
|
109 |
* @global PHPMailer\PHPMailer\PHPMailer $phpmailer
|
110 |
*
|
|
|
111 |
*/
|
112 |
if (!function_exists('wp_mail')) {
|
113 |
function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
|
114 |
{
|
115 |
// Compact the input, apply the filters, and extract them back out
|
116 |
-
|
117 |
-
if (!is_array($extractData)) {
|
118 |
-
$extractData = (array)$extractData;
|
119 |
-
}
|
120 |
-
extract($extractData, EXTR_OVERWRITE);
|
121 |
|
122 |
$mailgun = get_option('mailgun');
|
123 |
$region = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $mailgun['region'];
|
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'];
|
includes/wp-mail-smtp.php
CHANGED
@@ -20,8 +20,8 @@
|
|
20 |
*/
|
21 |
|
22 |
// Include MG filter functions
|
23 |
-
if (!include
|
24 |
-
|
25 |
}
|
26 |
|
27 |
/**
|
@@ -40,12 +40,12 @@ function mg_smtp_last_error($error = null)
|
|
40 |
|
41 |
if (null === $error) {
|
42 |
return $last_error;
|
43 |
-
}
|
44 |
-
|
45 |
-
|
46 |
-
$last_error = $error;
|
47 |
|
48 |
-
|
|
|
49 |
}
|
50 |
|
51 |
/**
|
@@ -54,11 +54,11 @@ function mg_smtp_last_error($error = null)
|
|
54 |
* @param string $str Log message
|
55 |
* @param string $level Logging level
|
56 |
*
|
57 |
-
* @return
|
58 |
*
|
59 |
* @since 1.5.7
|
60 |
*/
|
61 |
-
function mg_smtp_debug_output(
|
62 |
{
|
63 |
if (defined('MG_DEBUG_SMTP') && MG_DEBUG_SMTP) {
|
64 |
error_log("PHPMailer [$level] $str");
|
@@ -69,9 +69,9 @@ function mg_smtp_debug_output(string $str, $level)
|
|
69 |
* Capture and store the failure message from PHPmailer so the user will
|
70 |
* actually know what is wrong.
|
71 |
*
|
72 |
-
* @param WP_Error $error Error raised by
|
73 |
*
|
74 |
-
* @return
|
75 |
*
|
76 |
* @since 1.5.7
|
77 |
*/
|
@@ -86,7 +86,7 @@ function wp_mail_failed($error)
|
|
86 |
|
87 |
/**
|
88 |
* Provides a `wp_mail` compatible filter for SMTP sends through the
|
89 |
-
*
|
90 |
*
|
91 |
* @param array $args Compacted array of arguments.
|
92 |
*
|
@@ -97,7 +97,7 @@ function wp_mail_failed($error)
|
|
97 |
function mg_smtp_mail_filter(array $args)
|
98 |
{
|
99 |
// Extract the arguments from array to ($to, $subject, $message, $headers, $attachments)
|
100 |
-
extract($args
|
101 |
|
102 |
// $headers and $attachments are optional - make sure they exist
|
103 |
$headers = (!isset($headers)) ? '' : $headers;
|
@@ -109,7 +109,7 @@ function mg_smtp_mail_filter(array $args)
|
|
109 |
// Filter the `From:` header
|
110 |
$from_header = (isset($mg_headers['From'])) ? $mg_headers['From'][0] : null;
|
111 |
|
112 |
-
list($from_name, $from_addr) =
|
113 |
if (!is_null($from_header)) {
|
114 |
$content = $from_header['value'];
|
115 |
$boundary = $from_header['boundary'];
|
20 |
*/
|
21 |
|
22 |
// Include MG filter functions
|
23 |
+
if (!include dirname(__FILE__).'/mg-filter.php') {
|
24 |
+
Mailgun::deactivate_and_die(dirname(__FILE__).'/mg-filter.php');
|
25 |
}
|
26 |
|
27 |
/**
|
40 |
|
41 |
if (null === $error) {
|
42 |
return $last_error;
|
43 |
+
} else {
|
44 |
+
$tmp = $last_error;
|
45 |
+
$last_error = $error;
|
|
|
46 |
|
47 |
+
return $tmp;
|
48 |
+
}
|
49 |
}
|
50 |
|
51 |
/**
|
54 |
* @param string $str Log message
|
55 |
* @param string $level Logging level
|
56 |
*
|
57 |
+
* @return none
|
58 |
*
|
59 |
* @since 1.5.7
|
60 |
*/
|
61 |
+
function mg_smtp_debug_output($str, $level)
|
62 |
{
|
63 |
if (defined('MG_DEBUG_SMTP') && MG_DEBUG_SMTP) {
|
64 |
error_log("PHPMailer [$level] $str");
|
69 |
* Capture and store the failure message from PHPmailer so the user will
|
70 |
* actually know what is wrong.
|
71 |
*
|
72 |
+
* @param WP_Error $error Error raised by Wordpress/PHPmailer
|
73 |
*
|
74 |
+
* @return none
|
75 |
*
|
76 |
* @since 1.5.7
|
77 |
*/
|
86 |
|
87 |
/**
|
88 |
* Provides a `wp_mail` compatible filter for SMTP sends through the
|
89 |
+
* Wordpress PHPmailer transport.
|
90 |
*
|
91 |
* @param array $args Compacted array of arguments.
|
92 |
*
|
97 |
function mg_smtp_mail_filter(array $args)
|
98 |
{
|
99 |
// Extract the arguments from array to ($to, $subject, $message, $headers, $attachments)
|
100 |
+
extract($args);
|
101 |
|
102 |
// $headers and $attachments are optional - make sure they exist
|
103 |
$headers = (!isset($headers)) ? '' : $headers;
|
109 |
// Filter the `From:` header
|
110 |
$from_header = (isset($mg_headers['From'])) ? $mg_headers['From'][0] : null;
|
111 |
|
112 |
+
list($from_name, $from_addr) = array(null, null);
|
113 |
if (!is_null($from_header)) {
|
114 |
$content = $from_header['value'];
|
115 |
$boundary = $from_header['boundary'];
|
mailgun.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Plugin Name: Mailgun
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/mailgun/
|
5 |
* Description: Mailgun integration for WordPress
|
6 |
-
* Version: 1.8.
|
7 |
-
* Tested up to: 6.1
|
8 |
* Author: Mailgun
|
9 |
* Author URI: http://www.mailgun.com/
|
10 |
* License: GPLv2 or later
|
@@ -36,15 +36,10 @@
|
|
36 |
* either API or SMTP.
|
37 |
*
|
38 |
* Registers handlers for later actions and sets up config variables with
|
39 |
-
*
|
40 |
*/
|
41 |
class Mailgun
|
42 |
{
|
43 |
-
/**
|
44 |
-
* @var Mailgun $instance
|
45 |
-
*/
|
46 |
-
private static $instance;
|
47 |
-
|
48 |
/**
|
49 |
* @var false|mixed|null
|
50 |
*/
|
@@ -68,6 +63,7 @@ class Mailgun
|
|
68 |
/**
|
69 |
* Setup shared functionality for Admin and Front End.
|
70 |
*
|
|
|
71 |
*/
|
72 |
public function __construct()
|
73 |
{
|
@@ -99,18 +95,6 @@ class Mailgun
|
|
99 |
}
|
100 |
}
|
101 |
|
102 |
-
/**
|
103 |
-
* @return static
|
104 |
-
*/
|
105 |
-
public static function getInstance()
|
106 |
-
{
|
107 |
-
if (!isset(self::$instance)) {
|
108 |
-
self::$instance = new self();
|
109 |
-
}
|
110 |
-
|
111 |
-
return self::$instance;
|
112 |
-
}
|
113 |
-
|
114 |
/**
|
115 |
* Get specific option from the options table.
|
116 |
*
|
@@ -120,6 +104,7 @@ class Mailgun
|
|
120 |
*
|
121 |
* @return mixed
|
122 |
*
|
|
|
123 |
*/
|
124 |
public function get_option(string $option, ?array $options = null, bool $default = false)
|
125 |
{
|
@@ -142,6 +127,7 @@ class Mailgun
|
|
142 |
*
|
143 |
* @return void
|
144 |
*
|
|
|
145 |
*/
|
146 |
public function phpmailer_init(&$phpmailer)
|
147 |
{
|
@@ -188,6 +174,8 @@ class Mailgun
|
|
188 |
* @param $file Files critical to plugin functionality
|
189 |
*
|
190 |
* @return void
|
|
|
|
|
191 |
*/
|
192 |
public function deactivate_and_die($file)
|
193 |
{
|
@@ -210,6 +198,7 @@ class Mailgun
|
|
210 |
*
|
211 |
* @return string
|
212 |
*
|
|
|
213 |
*/
|
214 |
public function api_call($uri, $params = [], $method = 'POST'): string
|
215 |
{
|
@@ -219,7 +208,7 @@ class Mailgun
|
|
219 |
$domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options[ 'domain' ];
|
220 |
|
221 |
$region = mg_api_get_region($getRegion);
|
222 |
-
$this->api_endpoint = ($region)
|
223 |
|
224 |
$time = time();
|
225 |
$url = $this->api_endpoint . $uri;
|
@@ -277,6 +266,7 @@ class Mailgun
|
|
277 |
* @return array
|
278 |
*
|
279 |
* @throws JsonException
|
|
|
280 |
*/
|
281 |
public function get_lists(): array
|
282 |
{
|
@@ -295,21 +285,21 @@ class Mailgun
|
|
295 |
/**
|
296 |
* Handle add list ajax post.
|
297 |
*
|
298 |
-
* @return
|
299 |
*
|
300 |
* @throws JsonException
|
|
|
301 |
*/
|
302 |
public function add_list()
|
303 |
{
|
304 |
$name = $_POST['name'] ?? null;
|
305 |
$email = $_POST['email'] ?? null;
|
306 |
|
307 |
-
$list_addresses = $_POST['addresses'];
|
308 |
|
309 |
if (!empty($list_addresses)) {
|
310 |
-
$result = [];
|
311 |
foreach ($list_addresses as $address => $val) {
|
312 |
-
$
|
313 |
"lists/{$address}/members",
|
314 |
[
|
315 |
'address' => $email,
|
@@ -317,19 +307,7 @@ class Mailgun
|
|
317 |
]
|
318 |
);
|
319 |
}
|
320 |
-
|
321 |
-
if ($result) {
|
322 |
-
$message = 'Something went wrong';
|
323 |
-
$response = json_decode($result[0], true);
|
324 |
-
if (is_array($response) && isset($response['message'])) {
|
325 |
-
$message = $response['message'];
|
326 |
-
}
|
327 |
-
|
328 |
-
}
|
329 |
-
echo json_encode([
|
330 |
-
'status' => 200,
|
331 |
-
'message' => $message
|
332 |
-
], JSON_THROW_ON_ERROR);
|
333 |
} else {
|
334 |
echo json_encode([
|
335 |
'status' => 500,
|
@@ -347,12 +325,12 @@ class Mailgun
|
|
347 |
* @param array $instance widget instance params
|
348 |
*
|
349 |
* @throws JsonException
|
|
|
350 |
*/
|
351 |
public function list_form(string $list_address, array $args = [], array $instance = [])
|
352 |
{
|
353 |
-
$
|
354 |
-
$
|
355 |
-
$form_class_id = "list-form-{$widgetId}";
|
356 |
|
357 |
// List addresses from the plugin config
|
358 |
$list_addresses = array_map('trim', explode(',', $list_address));
|
@@ -377,7 +355,7 @@ class Mailgun
|
|
377 |
</p>
|
378 |
</div>
|
379 |
<?php endif; ?>
|
380 |
-
<?php if (isset($args[ 'collect_name' ]) && (
|
381 |
<p class="mailgun-list-widget-name">
|
382 |
<strong>Name:</strong>
|
383 |
<input type="text" name="name"/>
|
@@ -446,6 +424,7 @@ class Mailgun
|
|
446 |
dataType: 'json',
|
447 |
data: jQuery('.' + form_id + '').serialize(),
|
448 |
success: function (data) {
|
|
|
449 |
data_msg = data.message
|
450 |
already_exists = false
|
451 |
if (data_msg !== undefined) {
|
@@ -478,6 +457,7 @@ class Mailgun
|
|
478 |
* @return string
|
479 |
*
|
480 |
* @throws JsonException
|
|
|
481 |
*/
|
482 |
public function build_list_form(array $atts): string
|
483 |
{
|
@@ -508,6 +488,8 @@ class Mailgun
|
|
508 |
|
509 |
/**
|
510 |
* Initialize List Widget.
|
|
|
|
|
511 |
*/
|
512 |
public function load_list_widget()
|
513 |
{
|
@@ -524,7 +506,7 @@ class Mailgun
|
|
524 |
}
|
525 |
}
|
526 |
|
527 |
-
$mailgun = Mailgun
|
528 |
|
529 |
if (@include __DIR__ . '/includes/widget.php') {
|
530 |
add_action('widgets_init', [&$mailgun, 'load_list_widget']);
|
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.8.2
|
|
|
8 |
* Author: Mailgun
|
9 |
* Author URI: http://www.mailgun.com/
|
10 |
* License: GPLv2 or later
|
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 |
* @var false|mixed|null
|
45 |
*/
|
63 |
/**
|
64 |
* Setup shared functionality for Admin and Front End.
|
65 |
*
|
66 |
+
* @since 0.1
|
67 |
*/
|
68 |
public function __construct()
|
69 |
{
|
95 |
}
|
96 |
}
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
/**
|
99 |
* Get specific option from the options table.
|
100 |
*
|
104 |
*
|
105 |
* @return mixed
|
106 |
*
|
107 |
+
* @since 0.1
|
108 |
*/
|
109 |
public function get_option(string $option, ?array $options = null, bool $default = false)
|
110 |
{
|
127 |
*
|
128 |
* @return void
|
129 |
*
|
130 |
+
* @since 0.1
|
131 |
*/
|
132 |
public function phpmailer_init(&$phpmailer)
|
133 |
{
|
174 |
* @param $file Files critical to plugin functionality
|
175 |
*
|
176 |
* @return void
|
177 |
+
*
|
178 |
+
* @since 0.1
|
179 |
*/
|
180 |
public function deactivate_and_die($file)
|
181 |
{
|
198 |
*
|
199 |
* @return string
|
200 |
*
|
201 |
+
* @since 0.1
|
202 |
*/
|
203 |
public function api_call($uri, $params = [], $method = 'POST'): string
|
204 |
{
|
208 |
$domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $options[ 'domain' ];
|
209 |
|
210 |
$region = mg_api_get_region($getRegion);
|
211 |
+
$this->api_endpoint = ($region) ? $region : 'https://api.mailgun.net/v3/';
|
212 |
|
213 |
$time = time();
|
214 |
$url = $this->api_endpoint . $uri;
|
266 |
* @return array
|
267 |
*
|
268 |
* @throws JsonException
|
269 |
+
* @since 0.1
|
270 |
*/
|
271 |
public function get_lists(): array
|
272 |
{
|
285 |
/**
|
286 |
* Handle add list ajax post.
|
287 |
*
|
288 |
+
* @return string json
|
289 |
*
|
290 |
* @throws JsonException
|
291 |
+
* @since 0.1
|
292 |
*/
|
293 |
public function add_list()
|
294 |
{
|
295 |
$name = $_POST['name'] ?? null;
|
296 |
$email = $_POST['email'] ?? null;
|
297 |
|
298 |
+
$list_addresses = $_POST[ 'addresses' ];
|
299 |
|
300 |
if (!empty($list_addresses)) {
|
|
|
301 |
foreach ($list_addresses as $address => $val) {
|
302 |
+
$this->api_call(
|
303 |
"lists/{$address}/members",
|
304 |
[
|
305 |
'address' => $email,
|
307 |
]
|
308 |
);
|
309 |
}
|
310 |
+
echo json_encode(['status' => 200, 'message' => 'Thank you!'], JSON_THROW_ON_ERROR);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
} else {
|
312 |
echo json_encode([
|
313 |
'status' => 500,
|
325 |
* @param array $instance widget instance params
|
326 |
*
|
327 |
* @throws JsonException
|
328 |
+
* @since 0.1
|
329 |
*/
|
330 |
public function list_form(string $list_address, array $args = [], array $instance = [])
|
331 |
{
|
332 |
+
$widget_class_id = "mailgun-list-widget-{$args['widget_id']}";
|
333 |
+
$form_class_id = "list-form-{$args['widget_id']}";
|
|
|
334 |
|
335 |
// List addresses from the plugin config
|
336 |
$list_addresses = array_map('trim', explode(',', $list_address));
|
355 |
</p>
|
356 |
</div>
|
357 |
<?php endif; ?>
|
358 |
+
<?php if (isset($args[ 'collect_name' ]) && intval($args[ 'collect_name' ]) === 1): ?>
|
359 |
<p class="mailgun-list-widget-name">
|
360 |
<strong>Name:</strong>
|
361 |
<input type="text" name="name"/>
|
424 |
dataType: 'json',
|
425 |
data: jQuery('.' + form_id + '').serialize(),
|
426 |
success: function (data) {
|
427 |
+
|
428 |
data_msg = data.message
|
429 |
already_exists = false
|
430 |
if (data_msg !== undefined) {
|
457 |
* @return string
|
458 |
*
|
459 |
* @throws JsonException
|
460 |
+
* @since 0.1
|
461 |
*/
|
462 |
public function build_list_form(array $atts): string
|
463 |
{
|
488 |
|
489 |
/**
|
490 |
* Initialize List Widget.
|
491 |
+
*
|
492 |
+
* @since 0.1
|
493 |
*/
|
494 |
public function load_list_widget()
|
495 |
{
|
506 |
}
|
507 |
}
|
508 |
|
509 |
+
$mailgun = new Mailgun();
|
510 |
|
511 |
if (@include __DIR__ . '/includes/widget.php') {
|
512 |
add_action('widgets_init', [&$mailgun, 'load_list_widget']);
|
readme.md
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: 6.1
|
8 |
-
Stable tag: 1.8.
|
9 |
License: GPLv2 or later
|
10 |
|
11 |
|
@@ -131,9 +131,6 @@ MAILGUN_FROM_ADDRESS Type: string
|
|
131 |
|
132 |
|
133 |
== Changelog ==
|
134 |
-
= 1.8.3 (2022-08-30): =
|
135 |
-
- Plugin refactoring. Widget fixes for working with Legacy Widget Block. PHP8.0 support check
|
136 |
-
|
137 |
= 1.8.2 (2022-08-24): =
|
138 |
- Plugin refactoring. Small fixes
|
139 |
|
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: 6.0.1
|
8 |
+
Stable tag: 1.8.2
|
9 |
License: GPLv2 or later
|
10 |
|
11 |
|
131 |
|
132 |
|
133 |
== Changelog ==
|
|
|
|
|
|
|
134 |
= 1.8.2 (2022-08-24): =
|
135 |
- Plugin refactoring. Small fixes
|
136 |
|
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: 6.1
|
8 |
-
Stable tag: 1.8.
|
9 |
License: GPLv2 or later
|
10 |
|
11 |
|
@@ -128,9 +128,6 @@ MAILGUN_FROM_ADDRESS Type: string
|
|
128 |
|
129 |
|
130 |
== Changelog ==
|
131 |
-
= 1.8.3 (2022-08-30): =
|
132 |
-
- Plugin refactoring. Widget fixes for working with Legacy Widget Block. PHP8.0 support check
|
133 |
-
|
134 |
= 1.8.2 (2022-08-24): =
|
135 |
- Plugin refactoring. Small fixes
|
136 |
|
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: 6.0.1
|
8 |
+
Stable tag: 1.8.2
|
9 |
License: GPLv2 or later
|
10 |
|
11 |
|
128 |
|
129 |
|
130 |
== Changelog ==
|
|
|
|
|
|
|
131 |
= 1.8.2 (2022-08-24): =
|
132 |
- Plugin refactoring. Small fixes
|
133 |
|