How to re-enable a filter after disabling with __return_false

When you add functions to the same handle without specifying the priority, they are executed in the order of addition. Every time you try to send an email, all the hooked functions will be called in the order in which they were added.

To turn on email sending while a function runs, you can:

  • remove __return_false from filter at the beginning of the function and add again at the end,
  • add __return_true to filter (will be executed as second and override previous result) at the beginning of the function and remove it at the end.

Example:

function my_function() 
{
    add_filter( 'send_password_change_email', '__return_true' );
    //
    // sending an email about password change enabled
    //
    remove_filter( 'send_password_change_email', '__return_true' );
}