Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Last active August 21, 2020 01:27
Show Gist options
  • Save trvswgnr/4863186fc774b7fd6060d022cca5a01b to your computer and use it in GitHub Desktop.
Save trvswgnr/4863186fc774b7fd6060d022cca5a01b to your computer and use it in GitHub Desktop.
WordPress - Remove filter that was added using a class function
<?php
/**
* Remove filter that was added using a class function
*
* @param string $filter_name The filter hook to which the function to be removed is hooked.
* @param string $class_name The name of the class where the function resides.
* @param string $function_name The name of the function which should be removed.
*/
function remove_filter_with_class_function( $filter_name, $class_name, $function_name ) {
global $wp_filter;
foreach ( $wp_filter[ $filter_name ]->callbacks as $priority => $pri_data ) {
foreach ( $pri_data as $cb => $cb_data ) {
if ( is_array( $cb_data['function'] ) && get_class( $cb_data['function'][0] ) === $class_name && $cb_data['function'][1] === $function_name ) {
$object = $cb_data['function'][0];
$priority_to_remove = $priority;
$function = $cb_data['function'][1];
break;
}
}
if ( isset( $object ) ) {
break;
}
}
remove_filter( $filter_name, array( $object, $function ), $priority_to_remove );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment