awesomemotive / wp-mail-logging

:envelope: Logs each email sent by WordPress.
49 stars 24 forks source link

Add a new filter before saving the mail log #178

Closed donmhico closed 1 year ago

donmhico commented 1 year ago

Description

This PR adds a new filter named, wp_mail_logging_before_log_email which passed the $mailArray (an array containing the mail data) before it's saved.

This will give the developers the ability to manipulate the mail data before it's saved. One such use case is to remove sensitive data as described in #124.

Testing procedure

  1. Add this snippet in your functions.php or anywhere where it will run.
add_filter( 'wp_mail_logging_before_log_email', 'wp_mail_logging_before_log_email' );
function wp_mail_logging_before_log_email( $mail ) {

    $mail['to'] = 'john.doe@test.com';
    $mail['message'] = 'This is a test';
    $mail['subject'] = 'Lorem';

    return $mail;
}
  1. Trigger an email send in your WordPress that WP Mail Logging will capture/
  2. Check the Email Logs. You should notice that the email saved contains the data that we manipulated instead of the original data.