我有一个评论插件可以覆盖特定帖子类型中的评论表单。 现在我试图将评论和评论分开。
我的第一步是删除修改当前评论模板的过滤器,并在第二个评论表单中使用该过滤器。
插件使用此代码(简化)
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 );
如果有人能指导我解决问题的正确方向,那将对我有很大帮助。
最佳答案
我认为你可以实现这个目标,根据这个插件实例化类的方式使用以下解决方案之一:
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/