Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove filter of a plugin

I have a review plugin that overrides the comment form in a specific posttype. Now I'm trying to seperate the reviews and comments.

My first step is to remove the filter that modifies the current comment template and use that filter inside a second comment form.

The plugin uses this code (simplified)

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 );
    }

}

In my child theme's function.php file, I tried to use this but it didn't worked.

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

WP Codex

If someone can put me in the right direction on how to solve it, it would help me a lot.

like image 755
kiarashi Avatar asked Oct 30 '22 04:10

kiarashi


1 Answers

I think you can achieve this goal, using one of the following solutions depending on the way this plugin instantiates the class:

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'));
}

Hope it helps, let me know if you get stuck.

like image 188
iEmanuele Avatar answered Nov 08 '22 14:11

iEmanuele