Skip to content

Instantly share code, notes, and snippets.

@daronspence
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daronspence/73e06e037f699ca771dd to your computer and use it in GitHub Desktop.
Save daronspence/73e06e037f699ca771dd to your computer and use it in GitHub Desktop.
Remove actions/filters from anonymous class instance
// 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;
}
@elliotcondon
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment