admin管理员组文章数量:1024080
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?
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?
Share Improve this question edited Apr 12, 2019 at 13:49 mistertaylor asked Apr 12, 2019 at 13:38 mistertaylormistertaylor 6411 gold badge6 silver badges20 bronze badges 3 |1 Answer
Reset to default 3When 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' );
}
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?
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?
Share Improve this question edited Apr 12, 2019 at 13:49 mistertaylor asked Apr 12, 2019 at 13:38 mistertaylormistertaylor 6411 gold badge6 silver badges20 bronze badges 3- Just comment out or remove this line. – nmr Commented Apr 12, 2019 at 13:55
- For this specific instance, I want to disable sending the standard WP password changed email while a function runs and then re-enable it. – mistertaylor Commented Apr 12, 2019 at 14:42
-
put
remove_filter( 'send_password_change_email', '__return_false' );
at the end of the function? – majick Commented Apr 12, 2019 at 15:32
1 Answer
Reset to default 3When 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' );
}
本文标签: How to reenable a filter after disabling with returnfalse
版权声明:本文标题:How to re-enable a filter after disabling with __return_false 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745595701a2158154.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
remove_filter( 'send_password_change_email', '__return_false' );
at the end of the function? – majick Commented Apr 12, 2019 at 15:32