php - 删除插件的过滤器

标签 php wordpress filter

我有一个评论插件可以覆盖特定帖子类型中的评论表单。 现在我试图将评论和评论分开。

我的第一步是删除修改当前评论模板的过滤器,并在第二个评论表单中使用该过滤器。

插件使用此代码(简化)

final class DM_Reviews {

    public function hooks() {
        do_action_ref_array( 'dm_reviews_before_setup_actions', array( &$this ) );

        add_filter( 'comment_form_defaults', array( $this, 'reviews_form'       ) );        

        do_action_ref_array( 'dm_reviews_after_setup_actions', array( &$this ) );
    }

    public function review_form( $args ) {    

            $form = 'plugin code to modify form';   

        return wp_parse_args( $form, $args );
    }

}

在我的子主题的 function.php 文件中,我尝试使用它但它没有用。

global $DM_Reviews;
remove_filter( 'comment_form_defaults', array($DM_Reviews, 'reviews_form'),1 );

WP Codex

如果有人能指导我解决问题的正确方向,那将对我有很大帮助。

最佳答案

我认为你可以实现这个目标,根据这个插件实例化类的方式使用以下解决方案之一:

if( class_exists('DM_Reviews' ) ){
  //This should work in whatever case, not tested
  remove_filter('comment_form_defaults', array( 'DM_Reviews', 'reviews_form'));
  //or Instantiating a new instance, not tested
  remove_filter('comment_form_defaults', array( new DM_Reviews(), 'reviews_form'));
  //or Targeting the specific instance, not tested
  remove_filter('comment_form_defaults', array( DM_Reviews::get_instance(), 'reviews_form'));
}

希望对您有所帮助,如果您遇到困难,请告诉我。

关于php - 删除插件的过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36911718/

相关文章:

php - 使用 PHP 解析包含 javascript 的 HTML

php - 锂框架 MySQL 原始查询

wordpress - 向 wp_nav_menu 函数添加类(深度 2)

javascript - 在 WooCommerce 结账时运行关于账单国家更改的 javascript 代码

java - Intellij Live Templates Editor 中有过滤选项吗?

php - 如何从 PHP myadim 数据库检索图像并在 android ListView 中显示?

php - 移除模块并连接一个新模块

css - 如何使图像位于另一层之后

ios - 按属性的第一个字母过滤

jquery - 如何获取表的所有 tr 元素并使用 jquery 过滤它们?