This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wpex_remove_class_filter( $hook_name = '', $class_name ='', $method_name = '', $priority = 0 ) { | |
global $wp_filter; | |
// Make sure class exists | |
if ( ! class_exists( $class_name ) ) { | |
return false; | |
} | |
// 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) | |
// @todo consider using has_action instead | |
// @link https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/ | |
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 | |
) { | |
if ( isset( $wp_filter[$hook_name] ) ) { | |
// WP 4.7 | |
if ( is_object( $wp_filter[$hook_name] ) ) { | |
unset( $wp_filter[$hook_name]->callbacks[$priority][$unique_id] ); | |
} | |
// WP 4.6 | |
else { | |
unset( $wp_filter[$hook_name][$priority][$unique_id] ); | |
} | |
} | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment