0
votes

Have you got an idea how to remove actions or filters in Wordpress (from a plugin in my case) when those are defined like so:

add_action('action_tag', function(){...}); or add_filter('filter_tag', function(){...});

They are defined inside the function add_action or add_filter so I have no clue witch 'function_name' I should use to remove it.

remove_action($tag, what am I supposed to put in here?, $priority);

2

2 Answers

0
votes

You are talking about anonymous functions. To remove anonymous functions from filters or actions, you have to use the same function body and priority you used when they were added like so:

// Add it.
add_filter( 'tag', function ( $param ) {
    return $param;
}, 10, 1 );

// Remove it.
remove_filter( 'tag', function ( $param ) {
    return $param;
}, 10 );
0
votes

try this.. This will delete all hooks that are anonymous functions

global $wp_filter;
foreach ( $wp_filter as $filter_name => $filter_properties ):
        foreach ( $filter_properties->callbacks as $priority ):
            foreach( $priority as $function ):
                if( is_object( $function["function"] ) == true ):
                    unset( $wp_filter[ $filter_name ] );
                endif;
            endforeach;
        endforeach;
endforeach;