[英]Override function in custom plugin
我正在通过此操作使用插件:
add_filter( 'pre_comment_approved', array( $this, 'pre_save_review' ), 10, 2 );
我已经编写了一个插件来对我的网站进行一些调整。 主要是REST API定制。
我想覆盖,颠覆,忽略,删除该过滤器。 现在,只需在pre_save_review
函数的第一行上return
就可以使它“工作”。
我试过了:
remove_action( 'pre_comment_approved', 'pre_save_review');
...但是我想知道是否存在一些命名空间问题。 我对PHP不太了解,所以我不知道如何引用其他文件/插件中的类,我想这就是问题所在。
谢谢!
您可以使用wordpress函数“ remove_all_filters”删除所有过滤器
remove_all_filters('pre_comment_approved');
它还具有第二个参数来传递优先级号,因为该优先级号被添加为10,因此它是:
remove_all_filters('pre_comment_approved', 10);
您将为此使用remove_filter
函数。
请参阅此处的文档中的示例: https : //codex.wordpress.org/Function_Reference/remove_filter
如果从类内部(例如通过插件)添加了过滤器,则删除过滤器将需要访问类变量。
global $my_class;
remove_filter( 'the_content', array($my_class, 'class_filter_function') );
因此,请尝试以下方法;
global $this;
remove_filter( 'pre_comment_approved', array( $this, 'pre_save_review' ) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.