Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
remove_filter() - 从过滤器钩子中移除回调函数 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / remove_filter()

remove_filter( string $hook_name, callable|string|array $callback, int $priority = 10 )

从过滤器钩子中移除回调函数


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "49998edb6dfae1db465e16830f15ce0c" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "e3bd376c8a325cae20208df4f7e3936e" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

filter 过滤

removemore...


描述

这可以用来移除附加到特定过滤器挂钩的默认函数,并可能用替代函数替换它们。

要删除钩子,添加挂钩时$callback和$priority参数必须匹配。这适用于过滤器和动作。移除失败时不会发出警告。


参数

$hook_name

(string)(必填) 将要移除的函数所钩住的过滤器钩子。

$callback

(callable|string|array)(必填) 应用过滤器时要从运行中删除的回调。可以无条件调用此函数以推测性地删除可能存在或不存在的回调。

$priority

(int)(可选) 添加原始过滤器回调时使用的确切优先级。

默认值: 10


返回

(bool) 函数在被删除之前是否存在。



源码

查看源码 官方文档


更新日志

版本描述
1.2.0开始引入

使用示例

  • 示例1

    实例

    remove_filter( 'the_content', 'wpautop' );
    
    foreach ( array( 'the_content', 'the_title', 'comment_text' ) as $hook )
        remove_filter( $hook, 'capital_P_dangit' );
    

    如果过滤器是从类中添加的,例如通过插件添加的,则删除它将需要访问类变量。

    global $my_class;
    remove_filter( 'the_content', array($my_class, 'class_filter_function') );
    

    还值得注意的是,您可能需要把移除过滤器的工作优先安排在过滤器添加后发生的钩子上。在添加过滤器之前,无法成功删除它。