0

I want to modularly disable emails sent out by WordPress so I can replace them with my own custom emails when necessary.

I tried googling for a list of filter hooks, but couldn't find anything as comprehensive as I would like. I found these two so far:

/**
 * Disable default WordPress emails.
 */
add_filter( 'send_password_change_email', '__return_false' );
add_filter( 'send_email_change_email', '__return_false' );

Is there a resource or a list of all filter hooks that WordPress uses to send emails?

Update

Another option, as mentioned in kirillrocks's answer is to completely disable the wp_mail() function. However, this is undesirable for my use case as it disables ALL emails. For my use case, I would like to disable all mails individually, so I can later 'overwrite' them with my own emails, but still use the wp_mail() function to send them.

2

Option 1: Remove the 'to' argument from wp_mail function in WordPress, it will keep your system running without sending any default WordPress emails.

add_filter('wp_mail','disabling_emails', 10,1);
function disabling_emails( $args ){
    unset ( $args['to'] );
    return $args;
}

The wp_mail is a wrapper for the phpmailer class and it will not send any emails if there is no recipient.

Option 2: Hook to the phpmailer class directly and ClearAllRecipients from there

function my_action( $phpmailer ) {
    $phpmailer->ClearAllRecipients();
}
add_action( 'phpmailer_init', 'my_action' );

Option 3: Keep using wp_mail for your own needs but disable for everything else.

add_filter('wp_mail','disabling_emails', 10,1);
function disabling_emails( $args ){
    if ( ! $_GET['allow_wp_mail'] ) {
        unset ( $args['to'] );
    }
    return $args;
}

and when you are calling wp_mail use it like this:

$_GET['allow_wp_mail'] = true;
wp_mail( $to, $subject, $message, $headers );
unset ( $_GET['allow_wp_mail'] ); // optional

https://react2wp.com/wordpress-disable-email-notifications-pragmatically-in-code-fix/

You are welcome!

  • Hi, thank you for your answer. I stumbled upon this option as well, but doesn't this remove the wp_mail functionality altogether? I want to replace the default mails with my own, but still use the wp_mail function. Perhaps I should have mentioned that in the question... Still appreciated though! – Swen Apr 29 '18 at 13:10
  • Updated with option #3 – kirillrocks Apr 29 '18 at 16:00
0

to change the content of the "change password" email and the "change email" email, you can use the filter "password_change_email" and "email_change_email".

An example for the "password_change_email" filter:

function my_change_email($pass_change_email, $user, $userdata )
{   
   $pass_change_email['message'] = "Hello this is my email content.";

   return $pass_change_email;
}


add_filter( 'password_change_email', 'my_change_email' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.