5
votes

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.

3

3 Answers

3
votes

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.

1
votes

for me remove_filter didn't work from function.php i wanted to remove a specific behavior of a plugin so what i did :

add_action( 'init', 'remove_filters' );

function remove_filters(){
    global $wp_filter;
    unset( $wp_filter["_filter_name"]);
}
-2
votes

Try this :

$instance = DM_Reviews::this();
remove_filter('comment_form_defaults', array( $instance, 'reviews_form'));