Skip to content

Commit fcd1152

Browse files
authored
V2.1.9 (#197)
* Fixed bug that prevented plugins from chaining actions
1 parent 56f6404 commit fcd1152

File tree

8 files changed

+107
-8
lines changed

8 files changed

+107
-8
lines changed

WpMailCatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Domain Path: /languages
77
Description: Logging your mail will stop you from ever losing your emails again! This fast, lightweight plugin (under 140kb in size!) is also useful for debugging or backing up your messages.
88
Author: James Ward
9-
Version: 2.1.8
9+
Version: 2.1.9
1010
Author URI: https://jamesward.io
1111
Donate link: https://paypal.me/jamesmward
1212
*/

build/grunt/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/grunt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WpMailCatcher",
3-
"version": "2.1.8",
3+
"version": "2.1.9",
44
"lang_po_directory": "../../languages",
55
"build_directory": "./..",
66
"dist_directory": "../../assets",

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export DB_DATABASE=wordpress
44
export DB_USERNAME=wp_mail_catcher
55
export DB_PASSWORD=password
66
export PHP_VERSION=8.0
7-
export WP_VERSION=6.5.3
7+
export WP_VERSION=6.5.4
88

99
CMD=$1
1010

languages/WpMailCatcher.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#, fuzzy
77
msgid ""
88
msgstr ""
9-
"Project-Id-Version: WpMailCatcher 2.1.8\n"
9+
"Project-Id-Version: WpMailCatcher 2.1.9\n"
1010
"Report-Msgid-Bugs-To: wordpress@jamesward.io\n"
11-
"POT-Creation-Date: 2024-05-29 19:52+0000\n"
11+
"POT-Creation-Date: 2024-06-08 14:39+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: mail logging, email log, email logger, logging, email logging
44
Requires at least: 4.7
55
Tested up to: 6.4
66
Requires PHP: 7.4
7-
Stable tag: 2.1.8
7+
Stable tag: 2.1.9
88
License: GNU General Public License v3.0
99
License URI: https://raw.githubusercontent.com/JWardee/wp-mail-catcher/master/LICENSE
1010
Donate link: https://paypal.me/jamesmward
@@ -107,6 +107,10 @@ Great! Please leave a note in our (GitHub tracker)
107107

108108
== Changelog ==
109109

110+
= 2.1.9 =
111+
112+
- Fix: When stopped a log from being saved via `wp_mail_catcher_before_success_log_save`, it now returns the unaltered mail
113+
110114
= 2.1.8 =
111115

112116
- New: Added new hook `wp_mail_catcher_before_success_log_save`

src/Loggers/LogHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function saveMail(array $args, $transformFunc): array
3232
);
3333

3434
if ($userFilteredArgs === false) {
35-
return [];
35+
return $args;
3636
}
3737

3838
$wpdb->insert($wpdb->prefix . GeneralHelper::$tableName, array_merge($transformedArgs, $userFilteredArgs));

testing/tests/TestLogFunctions.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,99 @@ public function testCanStopErroredLogFromSavingViaFilter()
600600

601601
remove_filter($filterName, $func);
602602
}
603+
604+
private function getFilterChainFunction(&$wasChainedCalled, $to, $subject, $message)
605+
{
606+
return function ($args) use (&$wasChainedCalled, $to, $subject, $message) {
607+
$wasChainedCalled = true;
608+
$this->assertEquals($to, $args['to']);
609+
$this->assertEquals($subject, $args['subject']);
610+
$this->assertEquals($message, $args['message']);
611+
return $args;
612+
};
613+
}
614+
615+
/**
616+
* Other plugins hook into the `wp_mail` filter AFTER mail catcher, as such
617+
* they will rely on the values we return from our function hooked into `wp_mail`.
618+
* This test ensures that we correctly return the value so other plugins can make
619+
* use of it
620+
*/
621+
public function testCanChainWpMailFiltersWhenLog()
622+
{
623+
$to = 'test@test.com';
624+
$subject = 'Subject';
625+
$message = '<strong>Hello</strong>';
626+
$wasChainedCalled = false;
627+
$successFilterName = GeneralHelper::$actionNameSpace . '_before_success_log_save';
628+
629+
$func = function ($log) {
630+
return $log;
631+
};
632+
633+
$chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message);
634+
635+
add_filter($successFilterName, $func);
636+
// Ensure our filter runs AFTER mail catcher
637+
add_filter('wp_mail', $chainedFunc, 9999999);
638+
639+
wp_mail($to, $subject, $message);
640+
641+
$this->assertTrue($wasChainedCalled);
642+
643+
remove_filter($successFilterName, $func);
644+
remove_filter('wp_mail', $chainedFunc);
645+
}
646+
647+
public function testCanChainWpMailFiltersWhenLogIsStopped()
648+
{
649+
$to = 'test@test.com';
650+
$subject = 'Subject';
651+
$message = '<strong>Hello</strong>';
652+
$wasChainedCalled = false;
653+
$successFilterName = GeneralHelper::$actionNameSpace . '_before_success_log_save';
654+
655+
$func = function ($log) {
656+
return false;
657+
};
658+
659+
$chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message);
660+
661+
add_filter($successFilterName, $func);
662+
// Ensure our filter runs AFTER mail catcher
663+
add_filter('wp_mail', $chainedFunc, 9999999);
664+
665+
wp_mail($to, $subject, $message);
666+
667+
$this->assertTrue($wasChainedCalled);
668+
669+
remove_filter($successFilterName, $func);
670+
remove_filter('wp_mail', $chainedFunc);
671+
}
672+
673+
public function testCanChainWpMailFiltersWhenLogIsErrored()
674+
{
675+
$to = 'testtest.com';
676+
$subject = 'Subject';
677+
$message = '<strong>Hello</strong>';
678+
$wasChainedCalled = false;
679+
$erroredFilterName = GeneralHelper::$actionNameSpace . '_before_error_log_save';
680+
681+
$func = function ($log) {
682+
return false;
683+
};
684+
685+
$chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message);
686+
687+
add_filter($erroredFilterName, $func);
688+
// Ensure our filter runs AFTER mail catcher
689+
add_filter('wp_mail', $chainedFunc, 9999999);
690+
691+
wp_mail($to, $subject, $message);
692+
693+
$this->assertTrue($wasChainedCalled);
694+
695+
remove_filter($erroredFilterName, $func);
696+
remove_filter('wp_mail', $chainedFunc);
697+
}
603698
}

0 commit comments

Comments
 (0)