From fcd1152d68e86e990d22c56a22fb5d34450a1668 Mon Sep 17 00:00:00 2001 From: James <10816357+JWardee@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:28:12 +0100 Subject: [PATCH] V2.1.9 (#197) * Fixed bug that prevented plugins from chaining actions --- WpMailCatcher.php | 2 +- build/grunt/package-lock.json | 2 +- build/grunt/package.json | 2 +- entrypoint.sh | 2 +- languages/WpMailCatcher.pot | 4 +- readme.txt | 6 +- src/Loggers/LogHelper.php | 2 +- testing/tests/TestLogFunctions.php | 95 ++++++++++++++++++++++++++++++ 8 files changed, 107 insertions(+), 8 deletions(-) diff --git a/WpMailCatcher.php b/WpMailCatcher.php index c1e4cf4..e4d8e41 100644 --- a/WpMailCatcher.php +++ b/WpMailCatcher.php @@ -6,7 +6,7 @@ Domain Path: /languages 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. Author: James Ward -Version: 2.1.8 +Version: 2.1.9 Author URI: https://jamesward.io Donate link: https://paypal.me/jamesmward */ diff --git a/build/grunt/package-lock.json b/build/grunt/package-lock.json index 086ecd0..f4159d6 100644 --- a/build/grunt/package-lock.json +++ b/build/grunt/package-lock.json @@ -1,6 +1,6 @@ { "name": "WpMailCatcher", - "version": "2.1.8", + "version": "2.1.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/build/grunt/package.json b/build/grunt/package.json index e42514b..7346b5d 100644 --- a/build/grunt/package.json +++ b/build/grunt/package.json @@ -1,6 +1,6 @@ { "name": "WpMailCatcher", - "version": "2.1.8", + "version": "2.1.9", "lang_po_directory": "../../languages", "build_directory": "./..", "dist_directory": "../../assets", diff --git a/entrypoint.sh b/entrypoint.sh index 8ffa3a2..0d0dc5b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,7 +4,7 @@ export DB_DATABASE=wordpress export DB_USERNAME=wp_mail_catcher export DB_PASSWORD=password export PHP_VERSION=8.0 -export WP_VERSION=6.5.3 +export WP_VERSION=6.5.4 CMD=$1 diff --git a/languages/WpMailCatcher.pot b/languages/WpMailCatcher.pot index 1eb3479..2cff8f0 100644 --- a/languages/WpMailCatcher.pot +++ b/languages/WpMailCatcher.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: WpMailCatcher 2.1.8\n" +"Project-Id-Version: WpMailCatcher 2.1.9\n" "Report-Msgid-Bugs-To: wordpress@jamesward.io\n" -"POT-Creation-Date: 2024-05-29 19:52+0000\n" +"POT-Creation-Date: 2024-06-08 14:39+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/readme.txt b/readme.txt index e153d6d..5840802 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: mail logging, email log, email logger, logging, email logging Requires at least: 4.7 Tested up to: 6.4 Requires PHP: 7.4 -Stable tag: 2.1.8 +Stable tag: 2.1.9 License: GNU General Public License v3.0 License URI: https://raw.githubusercontent.com/JWardee/wp-mail-catcher/master/LICENSE Donate link: https://paypal.me/jamesmward @@ -107,6 +107,10 @@ Great! Please leave a note in our (GitHub tracker) == Changelog == += 2.1.9 = + +- Fix: When stopped a log from being saved via `wp_mail_catcher_before_success_log_save`, it now returns the unaltered mail + = 2.1.8 = - New: Added new hook `wp_mail_catcher_before_success_log_save` diff --git a/src/Loggers/LogHelper.php b/src/Loggers/LogHelper.php index 15f645f..bbdd0ce 100644 --- a/src/Loggers/LogHelper.php +++ b/src/Loggers/LogHelper.php @@ -32,7 +32,7 @@ public function saveMail(array $args, $transformFunc): array ); if ($userFilteredArgs === false) { - return []; + return $args; } $wpdb->insert($wpdb->prefix . GeneralHelper::$tableName, array_merge($transformedArgs, $userFilteredArgs)); diff --git a/testing/tests/TestLogFunctions.php b/testing/tests/TestLogFunctions.php index e242122..834f132 100644 --- a/testing/tests/TestLogFunctions.php +++ b/testing/tests/TestLogFunctions.php @@ -600,4 +600,99 @@ public function testCanStopErroredLogFromSavingViaFilter() remove_filter($filterName, $func); } + + private function getFilterChainFunction(&$wasChainedCalled, $to, $subject, $message) + { + return function ($args) use (&$wasChainedCalled, $to, $subject, $message) { + $wasChainedCalled = true; + $this->assertEquals($to, $args['to']); + $this->assertEquals($subject, $args['subject']); + $this->assertEquals($message, $args['message']); + return $args; + }; + } + + /** + * Other plugins hook into the `wp_mail` filter AFTER mail catcher, as such + * they will rely on the values we return from our function hooked into `wp_mail`. + * This test ensures that we correctly return the value so other plugins can make + * use of it + */ + public function testCanChainWpMailFiltersWhenLog() + { + $to = 'test@test.com'; + $subject = 'Subject'; + $message = 'Hello'; + $wasChainedCalled = false; + $successFilterName = GeneralHelper::$actionNameSpace . '_before_success_log_save'; + + $func = function ($log) { + return $log; + }; + + $chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message); + + add_filter($successFilterName, $func); + // Ensure our filter runs AFTER mail catcher + add_filter('wp_mail', $chainedFunc, 9999999); + + wp_mail($to, $subject, $message); + + $this->assertTrue($wasChainedCalled); + + remove_filter($successFilterName, $func); + remove_filter('wp_mail', $chainedFunc); + } + + public function testCanChainWpMailFiltersWhenLogIsStopped() + { + $to = 'test@test.com'; + $subject = 'Subject'; + $message = 'Hello'; + $wasChainedCalled = false; + $successFilterName = GeneralHelper::$actionNameSpace . '_before_success_log_save'; + + $func = function ($log) { + return false; + }; + + $chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message); + + add_filter($successFilterName, $func); + // Ensure our filter runs AFTER mail catcher + add_filter('wp_mail', $chainedFunc, 9999999); + + wp_mail($to, $subject, $message); + + $this->assertTrue($wasChainedCalled); + + remove_filter($successFilterName, $func); + remove_filter('wp_mail', $chainedFunc); + } + + public function testCanChainWpMailFiltersWhenLogIsErrored() + { + $to = 'testtest.com'; + $subject = 'Subject'; + $message = 'Hello'; + $wasChainedCalled = false; + $erroredFilterName = GeneralHelper::$actionNameSpace . '_before_error_log_save'; + + $func = function ($log) { + return false; + }; + + $chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message); + + add_filter($erroredFilterName, $func); + // Ensure our filter runs AFTER mail catcher + add_filter('wp_mail', $chainedFunc, 9999999); + + wp_mail($to, $subject, $message); + + $this->assertTrue($wasChainedCalled); + + remove_filter($erroredFilterName, $func); + remove_filter('wp_mail', $chainedFunc); + } }