我正在尝试从包含以下代码行的插件类WallpaperManager.getDrawable() -> //Retrieve the current system wallpaper.
中删除操作:
WC_GFPA_Entry
这是类代码:
add_action( 'gform_entry_detail_content_before', array( $this, 'entry_detail_screen_notice' ), 10, 2 );
到目前为止我在class WC_GFPA_Entry {
private static $instance;
public static function register() {
if ( self::$instance == null ) {
if ( apply_filters( 'woocommerce_gravityforms_create_entries', true ) ) {
self::$instance = new WC_GFPA_Entry();
}
}
}
private $_resuming_orders = array();
private function __construct() {
add_filter( 'gform_entry_detail_meta_boxes', array( $this, 'add_custom_entry_metabox' ), 10, 3 );
add_action( 'gform_entry_detail_content_before', array( $this, 'entry_detail_screen_notice' ), 10, 2 );
}
public function add_custom_entry_metabox( $meta_boxes, $entry, $form ) {
// some code
}
public function entry_detail_screen_notice( $form, $lead ) {
// some code .....
}
}
尝试过的内容:
functions.php
和
remove_action( 'gform_entry_detail_content_before', array( WC_GFPA_Entry::register(), 'entry_detail_screen_notice' ), 10, 2 );
我也试过改变优先级等,但没有真正起作用。任何帮助将不胜感激。
答案 0 :(得分:0)
不幸的是,没有简单的方法可以做到这一点。但是, 可以通过使用这样的实用程序来实现:
https://github.com/herewithme/wp-filters-extras/blob/master/wp-filters-extras.php
所以在你的例子中会是:
remove_filters_for_anonymous_class('gform_entry_detail_content_before', 'WC_GFPA_Entry', 'entry_detail_screen_notice', 10)
上面的Lib代码:
function remove_filters_with_method_name( $hook_name = '', $method_name = '', $priority = 0 ) {
global $wp_filter;
// Take only filters on right hook name and priority
if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
return false;
}
// Loop on filters registered
foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) {
// Test if filter is an array ! (always for class/method)
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) {
// Test if object is a class and method is equal to param !
if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && $filter_array['function'][1] == $method_name ) {
// Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/)
if ( is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) ) {
unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] );
} else {
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
}
}
}
}
return false;
}
/**
* Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name :)
*/
function remove_filters_for_anonymous_class( $hook_name = '', $class_name = '', $method_name = '', $priority = 0 ) {
global $wp_filter;
// Take only filters on right hook name and priority
if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
return false;
}
// Loop on filters registered
foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) {
// Test if filter is an array ! (always for class/method)
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) {
// Test if object is a class, class and method is equal to param !
if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) == $class_name && $filter_array['function'][1] == $method_name ) {
// Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/)
if ( is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) ) {
unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] );
} else {
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
}
}
}
}
return false;
}