自定义插件中的替代功能

时间:2019-08-08 20:03:32

标签: php wordpress

我正在使用具有此操作的插件:

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

我已经编写了一个插件来对我的网站进行一些调整。主要是REST API自定义。

我想覆盖,颠覆,忽略,删除该过滤器。现在,只需在return函数的第一行上pre_save_review就可以使它“工作”。

我尝试过:

remove_action( 'pre_comment_approved', 'pre_save_review');

...但是我不知道是否存在命名空间问题。我对PHP不太了解,所以我不知道该如何引用其他文件/插件中的类。

谢谢!

2 个答案:

答案 0 :(得分:2)

您可以使用wordpress函数“ remove_all_filters”删除所有过滤器

remove_all_filters('pre_comment_approved');

这还有第二个参数传递优先级数字,因为此优先级被添加为10,所以它是:

remove_all_filters('pre_comment_approved', 10);

引用remove_all_filters

答案 1 :(得分:0)

您将为此使用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' ) );