I want to check if any action/filter exists in the WordPress theme.
I have tried has_action
and has_filter
. But the problem with these functions is that if the hook/filter exists and no callbacks are added to the hook or all callbacks are removed from the hook, these will return false.
There is not an built-in WordPress function that will check for this. But you would be able to check if a filter exists using the following code:
The problem with this is that it will only check if the filter exists at the point at which the above code runs. So if the above code runs in a plugin, and a filter is added in a theme template file (which happens later in execution order, it won’t show up yet.