【问题标题】:Wordpress remove plugin filter from themeWordpress 从主题中删除插件过滤器
【发布时间】:2020-01-04 14:57:49
【问题描述】:

我需要从插件 woocommerce-wholesale-pro 中删除过滤器。过滤器添加到文件 woocommerce-wholesale-pricing-pro.php 中,如下所示:

class IGN_Wholesale_Pro_Suite {
    function init() {
        add_filter( 'loop_shop_post_in', array( $this, 'product_filter' ) );

        ...
    }

    function product_filter( $meta_query = array() ) {
        ...
    }
}

到目前为止,我已经尝试在我的主题中将其添加到 functions.php 中:

function removeIGNfilter()
{
    remove_filter( 'loop_shop_post_in', array('IGN_Wholesale_Pro_Suite', 'product_filter') );
}
add_action('init','removeIGNfilter', 15);
add_action('plugins_loaded','removeIGNfilter', 15);

我也尝试过添加:

remove_filter( 'loop_shop_post_in', array('IGN_Wholesale_Pro_Suite', 'product_filter') );

之后:

add_filter( 'loop_shop_post_in', array( $this, 'product_filter' ) );

在 init() 函数的插件文件中,但它不起作用。但是当我把它改成这样时:

remove_filter( 'loop_shop_post_in', array($this, 'product_filter') );

有效。

有什么方法可以从我的主题中删除这个过滤器?

【问题讨论】:

  • 在remove_filter,而不是$this,你必须把使用的实例放在“add_filter”中

标签: php wordpress hook


【解决方案1】:

您可以使用以下方法

// below code is only testing not used to functions.php


class IGN_Wholesale_Pro_Suite {
function init() {
    add_filter( 'loop_shop_post_in', array( $this, 'product_filter' ) );
}
function product_filter( $meta_query = array() ) {
}
}

//only user for below code
$plugin_class_name = new IGN_Wholesale_Pro_Suite();
remove_action('loop_shop_post_in', array($plugin_class_name, 'product_filter'));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 2015-03-11
    • 1970-01-01
    相关资源
    最近更新 更多