By mistertaylor


2019-04-12 13:38:28 8 Comments

I can disable a filter as follows:

add_filter( 'send_password_change_email', '__return_false' );

This may be a trivial question, but I can't find an answer for it... can I re-enable the filter with the following?

add_filter( 'send_password_change_email', '__return_true' );

If not, how can I re-enable a filter?

1 comments

@nmr 2019-04-12 16:04:50

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' );
}

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] the_excerpt filter with an empty excerpt

  • 2017-04-22 23:56:19
  • JSP
  • 774 View
  • 1 Score
  • 1 Answer
  • Tags:   filters excerpt

1 Answered Questions

[SOLVED] Add a filter to an action

  • 2016-06-10 21:38:01
  • JacobTheDev
  • 75 View
  • 0 Score
  • 1 Answer
  • Tags:   filters actions

2 Answered Questions

[SOLVED] How to add a custom filter in functions.php

  • 2014-09-28 14:01:10
  • Joanna Mikalai
  • 5412 View
  • 1 Score
  • 2 Answer
  • Tags:   filters

2 Answered Questions

[SOLVED] How to check a filter are applied

  • 2013-12-10 10:50:22
  • ironsand
  • 3238 View
  • 1 Score
  • 2 Answer
  • Tags:   filters

1 Answered Questions

[SOLVED] xmlrpc_enabled filter not called

  • 2013-01-08 22:45:57
  • Omar Abid
  • 1212 View
  • 5 Score
  • 1 Answer
  • Tags:   filters xml-rpc

1 Answered Questions

[SOLVED] Combining action and filter?

1 Answered Questions

[SOLVED] How to filter 'post_gallery' after all other filters/plugins etc

  • 2012-02-02 13:09:29
  • Mere Development
  • 4016 View
  • 2 Score
  • 1 Answer
  • Tags:   filters gallery

2 Answered Questions

[SOLVED] How to add filter with 2 args?

  • 2012-01-19 22:08:17
  • Jenny
  • 9274 View
  • 9 Score
  • 2 Answer
  • Tags:   filters

1 Answered Questions

[SOLVED] Looking for a filter to modify the months

1 Answered Questions

[SOLVED] How to add a filter to the get_body_class function?

  • 2011-12-12 14:50:14
  • robertwbradford
  • 720 View
  • 0 Score
  • 1 Answer
  • Tags:   filters hooks

Sponsored Content