Skip to content

Commit

Permalink
feat($general): filter anynymous fns from being processed by wp_list_…
Browse files Browse the repository at this point in the history
…filter()
  • Loading branch information
andreiglingeanu committed Aug 11, 2020
1 parent e0004c1 commit aa061ca
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion includes/remove-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ function remove_class_hook( $tag, $class_name = '', $method_name = '', $priority
global $wp_filter;
$is_hook_removed = false;
if ( ! empty( $wp_filter[ $tag ]->callbacks[ $priority ] ) ) {
$methods = wp_list_pluck( $wp_filter[ $tag ]->callbacks[ $priority ], 'function' );

$methods = array_filter(wp_list_pluck(
$wp_filter[ $tag ]->callbacks[ $priority ],
'function'
), function ($method) {
/**
* Allow only array & string notation for hooks, since we're
* looking to remove an exact method of a class anyway. And the
* method of the class is passed in as a string anyway.
*/
return is_string($method) || is_array($method);
});

$found_hooks = ! empty( $methods ) ? wp_list_filter( $methods, array( 1 => $method_name ) ) : array();

foreach( $found_hooks as $hook_key => $hook ) {
if ( ! empty( $hook[0] ) && is_object( $hook[0] ) && get_class( $hook[0] ) === $class_name ) {
$wp_filter[ $tag ]->remove_filter( $tag, $hook, $priority );
Expand Down

0 comments on commit aa061ca

Please sign in to comment.