Last active
August 29, 2015 14:14
-
-
Save daronspence/73e06e037f699ca771dd to your computer and use it in GitHub Desktop.
Remove actions/filters from anonymous class instance
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
// All of your classes in /acf/forms/ are called anonymously | |
// so it's near impossible to filter them out without this jargon. :( | |
// example of won't work, but should | |
remove_filter('in_widget_form', array('acf_form_widget', 'edit_widget'), 10 ); | |
// See http://wordpress.stackexchange.com/questions/137688/remove-actions-filters-added-via-anonymous-functions | |
function acfw_remove_object_filter( $tag, $class, $method = NULL, $priority = NULL ) { | |
$filters = $GLOBALS['wp_filter'][ $tag ]; | |
if ( empty ( $filters ) ) { | |
return; | |
} | |
foreach ( $filters as $p => $filter ) : | |
if ( ! is_null($priority) && ( (int) $priority !== (int) $p ) ) continue; | |
$remove = FALSE; | |
foreach ( $filter as $identifier => $function ) { | |
$function = $function['function']; | |
if ( is_array( $function ) | |
&& ( is_a( $function[0], $class ) || ( is_array( $function ) | |
&& $function[0] === $class ) ) ) : | |
$remove = ( $method && ( $method === $function[1] ) ); | |
elseif ( $function instanceof Closure && $class === 'Closure' ) : | |
$remove = TRUE; | |
endif; | |
if ( $remove ) { | |
unset( $GLOBALS['wp_filter'][$tag][$p][$identifier] ); | |
} | |
} | |
endforeach; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm guessing this is todo with the widget customizer bug you emailed me about. I'll be reviewing and debugging the problem tomorrow, so hopefully I've got a solution for it shortly.