Skip to content

Instantly share code, notes, and snippets.

@younes-dro
Created January 10, 2020 04:06
Show Gist options
  • Save younes-dro/d74559046395f37ac33098bbab3c1a56 to your computer and use it in GitHub Desktop.
Save younes-dro/d74559046395f37ac33098bbab3c1a56 to your computer and use it in GitHub Desktop.
2 In cases like this the Wordpress adds a hash (unique id) to the function name and stores it in the global $wp_filter variable. So if you use remove_filter function nothing will happen
function my_remove_filter($tag, $function_name, $priority = 10){
global $wp_filter;
if( isset($wp_filter[$tag]->callbacks[$priority]) and !empty($wp_filter[$tag]->callbacks[$priority]) ){
$wp_filter[$tag]->callbacks[$priority] = array_filter($wp_filter[$tag]->callbacks[$priority], function($v, $k) use ($function_name){
return ( stripos($k, $function_name) === false );
}, ARRAY_FILTER_USE_BOTH );
}
}
my_remove_filter('plugins_loaded', 'my_action');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment