remove actions defined with function(){...} wordpress

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);


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 );

试试这个..这将删除所有匿名函数的钩子

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;
链接地址: http://www.djcxy.com/p/57354.html

上一篇: 使用手臂编译ICU

下一篇: 删除使用function(){...} wordpress定义的操作