Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Last active August 29, 2015 14:27
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 lgedeon/7806513f47b6466fc2cb to your computer and use it in GitHub Desktop.
Save lgedeon/7806513f47b6466fc2cb to your computer and use it in GitHub Desktop.
Setup correctly, an action hook or filter defined in a class is as easy to remove as any other hook. But if not setup correctly and not your code, try this.
<?php
function remove_filter_in_class( $tag, $function_to_remove, $priority, $class ) {
if ( isset( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) {
foreach ( $GLOBALS['wp_filter'][ $tag ][ $priority ] as $key => $function ) {
if ( is_array( $function['function'] )
&& $function_to_remove === array_pop( $function['function'] )
&& $class === get_class( array_pop( $function['function'] ) )
) {
return remove_filter( $tag, $key, $priority );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment