If a plugin modified one of wp's filters by "add_filter", and I want to discard the modification and modify the wp's filter by my own codes. Should I remove the plugin's filter before I add my own filter?
1 Answer
Yes, you need to remove it first and then add your one. You can do it by calling remove_filter function like this:
remove_filter( 'wp_core_filter_hook', 'wp_core_filter_hook_handler', 10 );
Pay attention at third parameter passed to function: it is priority, it should be the same as defined when the function was originally hooked, otherwise the filter hook won't be removed.
If you want to remove all hook handlers, you can call remove_all_filters function:
remove_all_filter( 'wp_core_filter_hook' );
// or with priority
remove_all_filter( 'wp_core_filter_hook', 10 );
This function takes two parameters: filter name and priority (optional). If you pass priority then all handlers with specified priority will be removed.
And finally if you want to check if any filter has been registered for a hook, use function has_filter. It takes two parameters: filter name and function name (optional).