简体   繁体   English

自定义插件中的替代功能

[英]Override function in custom plugin

I'm using a plugin with this action: 我正在通过此操作使用插件:

add_filter( 'pre_comment_approved', array( $this, 'pre_save_review' ), 10, 2 );

I've written a plugin to do some tweaking to my site here and there. 我已经编写了一个插件来对我的网站进行一些调整。 Mostly REST API customizations. 主要是REST API定制。

I'd like to override, subvert, ignore, remove, that filter. 我想覆盖,颠覆,忽略,删除该过滤器。 Right now I've got it "working" by just return ing on the first line of the pre_save_review function. 现在,只需在pre_save_review函数的第一行上return就可以使它“工作”。

I tried: 我试过了:

remove_action( 'pre_comment_approved', 'pre_save_review');

... but I wonder if there's some namespacing issue. ...但是我想知道是否存在一些命名空间问题。 I don't know a lot about PHP so I don't know how to refer to classes in other files/plugins, which I imagine is the issue. 我对PHP不太了解,所以我不知道如何引用其他文件/插件中的类,我想这就是问题所在。

Thanks! 谢谢!

You can remove all filters with a wordpress function "remove_all_filters" 您可以使用wordpress函数“ remove_all_filters”删除所有过滤器

remove_all_filters('pre_comment_approved');

This also has a second parameter to pass the priority number, since this one is added with priority 10 it would be this: 它还具有第二个参数来传递优先级号,因为该优先级号被添加为10,因此它是:

remove_all_filters('pre_comment_approved', 10);

Reference remove_all_filters 参考remove_all_filters

You'll want to use the remove_filter function for this. 您将为此使用remove_filter函数。

See the Example in the documentation here: https://codex.wordpress.org/Function_Reference/remove_filter 请参阅此处的文档中的示例: https : //codex.wordpress.org/Function_Reference/remove_filter

If a filter has been added from within a class, for example by a plugin, removing it will require accessing the class variable. 如果从类内部(例如通过插件)添加了过滤器,则删除过滤器将需要访问类变量。

global $my_class;
remove_filter( 'the_content', array($my_class, 'class_filter_function') );

So maybe give the following a try; 因此,请尝试以下方法;

global $this;
remove_filter( 'pre_comment_approved', array( $this, 'pre_save_review' ) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM