awesomemotive / wp-mail-logging

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

Create a hook that allows filtering of which to emails to log #190

Closed donmhico closed 1 month ago

donmhico commented 1 year ago

Description

Create a new hook that allows filtering of which emails to log but still sends it. The existing hook wp_mail_logging_before_log_email does allow emails not to be logged, but it will also prevent the email to be sent.

Reference

See https://wordpress.org/support/topic/exclude-mails-by-address-of-recipment/.

nasanansi commented 7 months ago

https://wordpress.org/support/topic/exclude-certain-e-mails/

donmhico commented 1 month ago

To give an update, since v1.12.0, it's possible to exclude the email logs from being logged using the filter wp_mail_logging_before_log_email.

Here's an example snippet.

add_filter( 'wp_mail_logging_before_log_email', 'wp_mail_logging_filter' );

function wp_mail_logging_filter( $mail ) {

    if ( $mail['to'] === 'filter@gmail.com' ) {
        return false;
    }

    return $mail;
}

This filter only prevents the email to be logged, but will still send the email.