我为此尝试了很多解决方案,但我想不出来。以下是插件代码的简化版本:
class YITH_Vendors_Frontend_Premium extends YITH_Vendors_Frontend {
public function __construct() {
add_action( \'woocommerce_register_form\', array( $this, \'register_form\' ) );
}
因此,我想从我的子主题函数中删除此操作。php。
问题是该类不是通过变量实例化的。相反,它是这样实例化的:
class YITH_Vendors_Premium extends YITH_Vendors {
public function __construct() {
public function init() {
$this->frontend = new YITH_Vendors_Frontend_Premium();
}
}
}
然而,这个类永远不会通过变量实例化。相反,有一个函数可以对其进行实例化:
function YITH_Vendors() {
if ( defined( \'YITH_WPV_PREMIUM\' ) ) {
return YITH_Vendors_Premium::instance();
}
return YITH_Vendors::instance();
}
然后就这样叫它:
YITH_Vendors();
我尝试了所有这些,但没有机会:
remove_action( \'woocommerce_register_form\', array( "YITH_Vendors_Frontend", \'register_form\' ), 999 );
remove_action( \'woocommerce_register_form\', array( "YITH_Vendors_Frontend_Premium", \'register_form\' ), 999 );
remove_action( \'woocommerce_register_form\', array( "YITH_Vendors", \'register_form\' ), 999 );
remove_action( \'woocommerce_register_form\', array( "YITH_Vendors_Premium", \'register_form\' ), 999 );
请帮忙!谢谢
SO网友:WP-Silver
使用简单的remove\\u操作是行不通的,您需要一个自定义函数来替换为匿名对象。还要确保在设置“woocommerce\\u product\\u query”过滤器后触发。
尝试此功能:
function remove_anonymous_object_filter( $tag, $class, $method )
{
$filters = false;
if ( isset( $GLOBALS[\'wp_filter\'][$tag] ) )
$filters = $GLOBALS[\'wp_filter\'][$tag];
if ( $filters )
foreach ( $filters as $priority => $filter )
{
foreach ( $filter as $identifier => $function )
{
if ( ! is_array( $function ) )
continue;
if ( ! $function[\'function\'][0] instanceof $class )
continue;
if ( $method == $function[\'function\'][1] )
{
remove_filter($tag, array( $function[\'function\'][0], $method ), $priority);
}
}
}
}
对于您的特定筛选器,您应该尝试以下操作:
remove_anonymous_object_filter(\'woocommerce_product_query\', \'YITH_Vendors_Frontend_Premium\', \'hide_vendors_product\');
还应检查匿名对象筛选器是否存在,请使用以下功能:
function anonymous_object_filter_exists($tag, $class, $method)
{
if ( ! isset( $GLOBALS[\'wp_filter\'][$tag] ) )
return FALSE;
$filters = $GLOBALS[\'wp_filter\'][$tag];
if ( ! $filters )
return FALSE;
foreach ( $filters as $priority => $filter )
{
foreach ( $filter as $identifier => $function )
{
if ( ! is_array( $function ) )
continue;
if ( ! $function[\'function\'][0] instanceof $class )
continue;
if ( $method == $function[\'function\'][1] )
{
return TRUE;
}
}
}
return FALSE;
}
然后使用此选项:
if (anonymous_object_filter_exists(\'woocommerce_product_query\', \'YITH_Vendors_Frontend_Premium\', \'hide_vendors_product\'))
{ .. }