Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.1.9 #197

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WpMailCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion build/grunt/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/grunt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WpMailCatcher",
"version": "2.1.8",
"version": "2.1.9",
"lang_po_directory": "../../languages",
"build_directory": "./..",
"dist_directory": "../../assets",
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions languages/WpMailCatcher.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]\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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/Loggers/LogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
95 changes: 95 additions & 0 deletions testing/tests/TestLogFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';
$subject = 'Subject';
$message = '<strong>Hello</strong>';
$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 = '[email protected]';
$subject = 'Subject';
$message = '<strong>Hello</strong>';
$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 = '<strong>Hello</strong>';
$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);
}
}
Loading