admin管理员组文章数量:1327687
I have a filter that's being applied, but I can't find a corresponding call to add_filter()
. Is there any other way it could be added?
Specifically: I'm trying to maintain/make some changes to a Wordpress plugin (privately developed, and the original developer is not available to contact), and for my current change, I've traced the execution path I'm looking at to the call:
$output = apply_filters('<plugin_name>-output-block', $output, $my_args);
However I cannot for the life of me find where the filter is being defined. I've grepped through the plugin's entire codebase for "<plugin_name>-output-block
" and nothing. I've also grepped for every instance of "add_filter
" in case it's being called with the filter name in a variable... and still nothing. As far as I can determine, the filter is never being added.
(I am aware of the functionality where you can use apply_filters()
to simply define a new hook on the fly, but I don't think that's what's happening here (or at least is not the only thing); if I comment out that line, the output definitely breaks... so there's existing functionality behind there that's being called.)
So: is there another way that the filter could be being added? A mechanism other than add_filter()
? Could it be added under a different name and then renamed somewhere? What am I missing?
I have a filter that's being applied, but I can't find a corresponding call to add_filter()
. Is there any other way it could be added?
Specifically: I'm trying to maintain/make some changes to a Wordpress plugin (privately developed, and the original developer is not available to contact), and for my current change, I've traced the execution path I'm looking at to the call:
$output = apply_filters('<plugin_name>-output-block', $output, $my_args);
However I cannot for the life of me find where the filter is being defined. I've grepped through the plugin's entire codebase for "<plugin_name>-output-block
" and nothing. I've also grepped for every instance of "add_filter
" in case it's being called with the filter name in a variable... and still nothing. As far as I can determine, the filter is never being added.
(I am aware of the functionality where you can use apply_filters()
to simply define a new hook on the fly, but I don't think that's what's happening here (or at least is not the only thing); if I comment out that line, the output definitely breaks... so there's existing functionality behind there that's being called.)
So: is there another way that the filter could be being added? A mechanism other than add_filter()
? Could it be added under a different name and then renamed somewhere? What am I missing?
1 Answer
Reset to default 0I've grepped through the plugin's entire codebase for "
<plugin_name>-output-block
" and nothing.
(Revised answer) Actually, you could just deactivate all other plugins and/or switch to a default (and unmodified) theme like the Twenty Twenty theme to see whether the issue is caused by another plugin or the active theme. But even so, I hope the following helps.
is there another way that the filter could be being added? A mechanism other than
add_filter()
?
Basically, that's the only proper way of registering a callback for a certain filter hook.
However, the callback can also be registered by calling add_action()
instead of add_filter()
(add_action()
is just a wrapper for add_filter()
), so try searching for that in the active theme and your plugin if necessary. For example, using regular expression (RegEx), try searching for add_(filter|action).+output\-block
in the theme/plugin files (PHP files).
And although unlikely, you can also try searching in the theme for $wp_filter
(which points to $GLOBALS['wp_filter']
) in case it's accessed directly to register the filter callback...
Quick & Easy (but tricky) way without manually searching in the theme/plugin files: Use Query Monitor (QM) with do_action()
(Well, you'd still need to search, but it would be much easier.)
I'm in no way affiliated with QM, neither the plugin nor its author(s), but QM can help you find the code which hooks to the <plugin_name>-output-block
hook.
In your plugin, temporarily use
do_action()
and notapply_filters()
:$output = do_action('<plugin_name>-output-block', $output, $my_args); // use this //$output = apply_filters('<plugin_name>-output-block', $output, $my_args); // not this
But since you said, "if I comment out that line, the output definitely breaks", then you may have to uncomment the second line above. But then, doing so means that all the hook callbacks will be called at least twice, so try first with the second line commented out.
Then just click on the "Hooks & Actions" item in the QM admin toolbar menu and select the "block" hook from the drop-down menu in the left side:
本文标签: What different ways can a plugin add a filter to a Wordpress site
版权声明:本文标题:What different ways can a plugin add a filter to a Wordpress site? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742214505a2434319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'<plugin_name>-output-block'
' ? – mozboz Commented Jul 28, 2020 at 10:16