Skip to content

Commit b03ef13

Browse files
De 1558 wp mailgun ability to disable fallback (#209)
* Widget form html updates in mailgun.php Updates to markup to ease editing of CSS. -Wrapped "name" and "email" in <label> tag -Added placeholder text -Wrapped submit and lists in <div> with "mailgun-list-widget-lists" class -Added basic email pattern check to JS as form would submit with no "@" sign and return success message. But server message in console reports that email field invalid so nothing happens * Fallback option added to have ability to turn on/off it. * Fallback option added to have ability to turn on/off it. Information about Tracking settings Widget style fixes --------- Co-authored-by: dassels <[email protected]>
1 parent 1d60f7d commit b03ef13

File tree

6 files changed

+78
-11
lines changed

6 files changed

+78
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Changelog
22
=========
33

4+
2.1.9 (2025-06-24)
5+
- Added fallback option. Merge PR for widget
6+
47
2.1.8 (2025-05-11)
58
- Just keep update WP version. And tested compatibility with it
69

includes/options-page.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
$trackOpens = ( defined('MAILGUN_TRACK_OPENS') ? MAILGUN_TRACK_OPENS : null );
6161

6262
$suppressClicks = $this->get_option('suppress_clicks') ?: 'no';
63+
$emailFallback = $this->get_option('email_fallback') ?: 'no';
64+
65+
$settings = [];
66+
try {
67+
$settings = $mailgun->getTrackingSettings();
68+
} catch (Throwable $e) {
69+
}
6370

6471
?>
6572
<div class="wrap">
@@ -116,6 +123,24 @@
116123
<?php settings_fields('mailgun'); ?>
117124

118125
<table class="form-table">
126+
<?php if ($settings) : ?>
127+
<tr>
128+
<th><?php _e('Domain tracking settings from account', 'mailgun'); ?></th>
129+
<td>
130+
<ul>
131+
<li>
132+
<b>Click tracking</b> &mdash; <?php echo $settings['tracking']['open']['active'] == 1 ? 'Yes' : 'No'?>
133+
</li>
134+
<li>
135+
<b>Open tracking</b> &mdash; <?php echo $settings['tracking']['click']['active'] == 1 ? 'Yes' : 'No'?>
136+
</li>
137+
<li>
138+
<b>Unsubscribes</b> &mdash; <?php echo $settings['tracking']['unsubscribe']['active'] == 1 ? 'Yes' : 'No'?>
139+
</li>
140+
</ul>
141+
</td>
142+
</tr>
143+
<?php endif; ?>
119144
<tr valign="top">
120145
<th scope="row">
121146
<?php _e('Select Your Region', 'mailgun'); ?>
@@ -431,6 +456,18 @@ class="regular-text"
431456
</p>
432457
</td>
433458
</tr>
459+
<tr valign="top">
460+
<th scope="row">
461+
<?php _e('Email fallback', 'mailgun'); ?> <br>
462+
</th>
463+
<td>
464+
<select
465+
name="mailgun[email_fallback]">
466+
<option value="yes"<?php selected('yes', $emailFallback); ?>><?php _e('Yes', 'mailgun'); ?></option>
467+
<option value="no"<?php selected('no', $emailFallback); ?>><?php _e('No', 'mailgun'); ?></option>
468+
</select>
469+
</td>
470+
</tr>
434471
</table>
435472
<h3><?php _e('Lists', 'mailgun'); ?></h3>
436473
<table class="form-table">

includes/wp-mail-api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
495495
}
496496

497497
// Email Fallback
498-
499-
if ($isFallbackNeeded) {
498+
$isFallbackEnabled = get_option('email_fallback') ?: 'no';
499+
if ($isFallbackNeeded && $isFallbackEnabled === 'yes') {
500500
global $phpmailer;
501501

502502
// (Re)create it, if it's gone missing.

mailgun.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Mailgun
44
* Plugin URI: http://wordpress.org/extend/plugins/mailgun/
55
* Description: Mailgun integration for WordPress
6-
* Version: 2.1.8
6+
* Version: 2.1.9
77
* Requires PHP: 7.4
88
* Requires at least: 4.4
99
* Author: Mailgun
@@ -294,6 +294,21 @@ public function get_lists(): array {
294294
return $results;
295295
}
296296

297+
/**
298+
* @return array
299+
* @throws JsonException
300+
*/
301+
public function getTrackingSettings(): array
302+
{
303+
$domain = ( defined( 'MAILGUN_DOMAIN' ) && MAILGUN_DOMAIN ) ? MAILGUN_DOMAIN : $this->get_option( 'domain' );
304+
if (!$domain) {
305+
return [];
306+
}
307+
$settings = $this->api_call(sprintf("domains/%s/tracking", $domain), [], 'GET' );
308+
309+
return json_decode( $settings, true, 512, JSON_THROW_ON_ERROR );
310+
}
311+
297312
/**
298313
* Handle add list ajax post.
299314
*
@@ -384,17 +399,18 @@ public function list_form( string $list_address, array $args = array() ): void {
384399
<?php endif; ?>
385400
<?php if ( isset( $args['collect_name'] ) && (int) $args['collect_name'] === 1 ) : ?>
386401
<p class="mailgun-list-widget-name">
387-
<strong>Name:</strong>
388-
<input type="text" name="name"/>
402+
<label><strong>Name:</strong></label>
403+
<input type="text" name="name" placeholder="Name"/>
389404
</p>
390405
<?php endif; ?>
391406
<p class="mailgun-list-widget-email">
392-
<strong>Email:</strong>
393-
<input type="text" name="email"/>
407+
<label><strong>Email:</strong></label>
408+
<input type="text" name="email" placeholder="Email"/>
394409
</p>
395410
</div>
396411

397-
<?php if ( count( $list_addresses ) > '1' ) : ?>
412+
<div class="mailgun-list-widget-lists">
413+
<?php if ( count( $list_addresses ) > '1' ) : ?>
398414
<ul class="mailgun-lists" style="list-style: none;">
399415
<?php
400416
foreach ( $all_list_addresses as $la ) :
@@ -414,7 +430,7 @@ public function list_form( string $list_address, array $args = array() ): void {
414430

415431
<input class="mailgun-list-submit-button" data-form-id="<?php echo esc_attr( $form_class_id ); ?>" type="button"
416432
value="Subscribe"/>
417-
<input type="hidden" name="mailgun-submission" value="1"/>
433+
<input type="hidden" name="mailgun-submission" value="1"/></div>
418434

419435
</form>
420436
<div class="widget-list-panel result-panel" style="display:none;">
@@ -444,6 +460,14 @@ public function list_form( string $list_address, array $args = array() ): void {
444460
return
445461
}
446462

463+
// Email validation regex pattern
464+
var emailPattern = /.+@.+\..{2,}/;
465+
466+
if (!emailPattern.test(jQuery('.' + form_id + ' .mailgun-list-widget-email input').val())) {
467+
alert('Please enter a valid email address.')
468+
return
469+
}
470+
447471
jQuery.ajax({
448472
url: '<?php echo admin_url( 'admin-ajax.php?action=add_list' ); ?>',
449473
action: 'add_list',

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Mailgun for WordPress
44
Contributors: mailgun, sivel, lookahead.io, m35dev, alanfuller
55
Tags: mailgun, smtp, http, api, mail, email
66
Tested up to: 6.8.1
7-
Stable tag: 2.1.8
7+
Stable tag: 2.1.9
88
Requires PHP: 7.4
99
License: GPLv2 or later
1010

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Mailgun for WordPress
44
Contributors: mailgun, sivel, lookahead.io, m35dev, alanfuller
55
Tags: mailgun, smtp, http, api, mail, email
66
Tested up to: 6.8.1
7-
Stable tag: 2.1.8
7+
Stable tag: 2.1.9
88
Requires PHP: 7.4
99
License: GPLv2 or later
1010

@@ -129,6 +129,9 @@ MAILGUN_TRACK_OPENS Type: string Choices: 'yes' or 'no'
129129

130130
== Changelog ==
131131

132+
= 2.1.9 (2025-06-24): =
133+
- Added fallback option. Merge PR for widget
134+
132135
= 2.1.8 (2025-05-11): =
133136
- Just keep update WP version. And tested compatibility with it
134137

0 commit comments

Comments
 (0)