There are reports that remove_filter
does not work under some circumstances, and that we should provide alternatives. However, the article does not really make it clear under which circumstances this happens.
I am looking for code examples that will break remove_filter
, with WordPress and PHP version, and eventually other relevant info, provided. I think the following snippet should be a useable template:
<?php
include('wp-load.php');
function filtertest_function($value)
{
return 'Filtered';
}
var_dump(apply_filters('filtertest', 'Original value'));
add_filter('filtertest', 'filtertest_function');
var_dump(apply_filters('filtertest', 'Original value'));
remove_filter('filtertest', 'filtertest_function');
var_dump(apply_filters('filtertest', 'Original value'));
This will return the expected:
string(14) "Original value"
string(8) "Filtered"
string(14) "Original value"
I believe the error comes up in some cases where the filter is part of a class, or multiple filters are used. I understand _wp_filter_build_unique_id
is involved. Please point out where in that code the source of the error is.
remove_filter()
making me think that people may be using it when a more proper coding approach could/should be used (so maybe that's why I've not run into the problem?) I'd be curious to know when it is really needed besides to actually remove a filter added by core or another plugin that you need to have not run.remove_filter()
?). Next to the articel in trac ticket and comments code already shows problematic areas. But keep in mind that this is a development discussion and Mike posed the right counter-question: What are you after? I just suggest in the article to not rely onremove_filter()
, to be on the safe side.